media: mtk-vcodec: support for M8192 decoder
Yunfei Dong
maintainerv8 cover media: mtk-vcodec: support for M8192 decoder
This series adds support for mt8192 h264/vp8/vp9 decoder drivers. Firstly, refactor power/clock/interrupt interfaces for mt8192 is lat and core architecture.
Secondly, add new functions to get frame buffer size and resolution according to decoder capability from scp side. Then add callback function to get/put capture buffer in order to enable lat and core decoder in parallel, need to adjust GStreamer at the same time.
Then add to support MT21C compressed mode and fix v4l2-compliance fail.
Next, extract H264 request api driver to let mt8183 and mt8192 use the same code, and adds mt8192 frame based h264 driver for stateless decoder.
Lastly, add vp8 and vp9 stateless decoder drivers.
Patches 1 refactor power/clock/interrupt interface.
Patches 2~4 get frame buffer size and resolution according to decoder capability. Patches 5 set capture queue bytesused.
Patches 6 adjust GStreamer.
Patch 7~11 add to support MT21C compressed mode and fix v4l2-compliance fail. patch 12 record capture queue format type.
Patch 13~14 extract h264 driver and add mt8192 frame based driver for h264 decoder. Patch 15~16 add vp8 and vp9 stateless decoder drivers.
Patch 17 prevent kernel crash when rmmod mtk-vcodec-dec.ko
---
changes compared with v6:
- adjust GStreamer, separate src buffer done with v4l2_ctrl_request_complete for patch 6.
- remove v4l2_m2m_set_dst_buffered.
- add new patch to set each plane bytesused in buf prepare for patch 5.
- using upstream interface to update vp9 prob tables for patch 16.
- fix maintainer comments.
- test the driver with chrome VD and GStreamer(H264/VP9/VP8/AV1).
changes compared with v6:
- rebase to the latest media stage and fix conficts
- fix memcpy to memcpy_fromio or memcpy_toio
- fix h264 crash when test field bitstream
changes compared with v5:
- fix vp9 comments for patch 15
- fix vp8 comments for patch 14.
- fix comments for patch 12.
- fix build errors.
changes compared with v4:
- fix checkpatch.pl fail.
- fix kernel-doc fail.
- rebase to the latest media codec driver.
changes compared with v3:
- remove enum mtk_chip for patch 2.
- add vp8 stateless decoder drivers for patch 14.
- add vp9 stateless decoder drivers for patch 15.
changes compared with v2:
- add new patch 11 to record capture queue format type.
- separate patch 4 according to tzung-bi's suggestion.
- re-write commit message for patch 5 according to tzung-bi's suggestion. changes compared with v1:
- rewrite commit message for patch 12.
- rewrite cover-letter message.
---
Yunfei Dong (17):
media: mediatek: vcodec: Add vdec enable/disable hardware helpers
media: mediatek: vcodec: Using firmware type to separate different
firmware architecture
media: mediatek: vcodec: get capture queue buffer size from scp
media: mediatek: vcodec: Read max resolution from dec_capability
media: mediatek: vcodec: set each plane bytesused in buf prepare
media: mediatek: vcodec: Refactor get and put capture buffer flow
media: mediatek: vcodec: Refactor supported vdec formats and
framesizes
media: mediatek: vcodec: Getting supported decoder format types
media: mediatek: vcodec: Add format to support MT21C
media: mediatek: vcodec: disable vp8 4K capability
media: mediatek: vcodec: Fix v4l2-compliance fail
media: mediatek: vcodec: record capture queue format type
media: mediatek: vcodec: Extract H264 common code
media: mediatek: vcodec: support stateless H.264 decoding for mt8192
media: mediatek: vcodec: support stateless VP8 decoding
media: mediatek: vcodec: support stateless VP9 decoding
media: mediatek: vcodec: prevent kernel crash when rmmod
mtk-vcodec-dec.ko
.../media/platform/mediatek/vcodec/Makefile | 4 + .../platform/mediatek/vcodec/mtk_vcodec_dec.c | 62 +- .../mediatek/vcodec/mtk_vcodec_dec_drv.c | 8 +- .../mediatek/vcodec/mtk_vcodec_dec_pm.c | 166 +- .../mediatek/vcodec/mtk_vcodec_dec_pm.h | 6 +- .../mediatek/vcodec/mtk_vcodec_dec_stateful.c | 19 +- .../vcodec/mtk_vcodec_dec_stateless.c | 257 +- .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 41 +- .../mediatek/vcodec/mtk_vcodec_enc_drv.c | 5 - .../platform/mediatek/vcodec/mtk_vcodec_fw.c | 6 + .../platform/mediatek/vcodec/mtk_vcodec_fw.h | 1 + .../vcodec/vdec/vdec_h264_req_common.c | 310 +++ .../vcodec/vdec/vdec_h264_req_common.h | 272 +++ .../mediatek/vcodec/vdec/vdec_h264_req_if.c | 438 +--- .../vcodec/vdec/vdec_h264_req_multi_if.c | 619 +++++ .../mediatek/vcodec/vdec/vdec_vp8_req_if.c | 437 ++++ .../vcodec/vdec/vdec_vp9_req_lat_if.c | 2072 +++++++++++++++++ .../platform/mediatek/vcodec/vdec_drv_if.c | 37 +- .../platform/mediatek/vcodec/vdec_drv_if.h | 3 + .../platform/mediatek/vcodec/vdec_ipi_msg.h | 36 + .../platform/mediatek/vcodec/vdec_msg_queue.c | 2 + .../platform/mediatek/vcodec/vdec_msg_queue.h | 2 + .../platform/mediatek/vcodec/vdec_vpu_if.c | 53 +- .../platform/mediatek/vcodec/vdec_vpu_if.h | 15 + .../platform/mediatek/vcodec/venc_vpu_if.c | 2 +- include/linux/remoteproc/mtk_scp.h | 2 + 26 files changed, 4274 insertions(+), 601 deletions(-) create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.h create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
Signature · 1 line
2.18.0
Yunfei Dong
maintainerPATCH v8 1/17 media: mediatek: vcodec: Add vdec enable/disable hardware helpers
Lock, power and clock are highly coupled operations. Adds vdec enable/disable hardware helpers and uses them.
--- .../mediatek/vcodec/mtk_vcodec_dec_drv.c | 5 - .../mediatek/vcodec/mtk_vcodec_dec_pm.c | 166 +++++++++++------- .../mediatek/vcodec/mtk_vcodec_dec_pm.h | 6 +- .../platform/mediatek/vcodec/vdec_drv_if.c | 20 +-- .../platform/mediatek/vcodec/vdec_msg_queue.c | 2 + 5 files changed, 116 insertions(+), 83 deletions(-)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c +0 -5
@@ -193,9 +193,6 @@ static int fops_vcodec_open(struct file *file)mtk_vcodec_dec_set_default_params (ctx);if (v4l2_fh_is_singular (&ctx->fh)) { - ret =mtk_vcodec_dec_pw_on (dev,MTK_VDEC_LAT0 ); -if (ret <0 ) - goto err_load_fw;/* * Does nothing if firmware was already loaded. */
@@ -252,8 +249,6 @@ static int fops_vcodec_release(struct file *file)v4l2_m2m_ctx_release (ctx->m2m_ctx);mtk_vcodec_dec_release (ctx); -if (v4l2_fh_is_singular (&ctx->fh)) -mtk_vcodec_dec_pw_off (dev,MTK_VDEC_LAT0 );v4l2_fh_del (&ctx->fh);v4l2_fh_exit (&ctx->fh);v4l2_ctrl_handler_free (&ctx->ctrl_hdl);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.c +106 -60
210 lines not on this page · raw message
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.h +2 -4
@@ -11,9 +11,7 @@int mtk_vcodec_init_dec_clk (struct platform_device *pdev,struct mtk_vcodec_pm *pm); -int mtk_vcodec_dec_pw_on (struct mtk_vcodec_dev *vdec_dev,int hw_idx); -void mtk_vcodec_dec_pw_off (struct mtk_vcodec_dev *vdec_dev,int hw_idx); -void mtk_vcodec_dec_clock_on (struct mtk_vcodec_dev *vdec_dev,int hw_idx); -void mtk_vcodec_dec_clock_off (struct mtk_vcodec_dev *vdec_dev,int hw_idx); +void mtk_vcodec_dec_enable_hardware (struct mtk_vcodec_ctx *ctx,int hw_idx); +void mtk_vcodec_dec_disable_hardware (struct mtk_vcodec_ctx *ctx,int hw_idx);#endif /* _MTK_VCODEC_DEC_PM_H_ */
drivers/media/platform/mediatek/vcodec/vdec_drv_if.c +6 -14
@@ -38,11 +38,9 @@ int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)return -EINVAL ; } -mtk_vdec_lock (ctx); -mtk_vcodec_dec_clock_on (ctx->dev, ctx->hw_id); +mtk_vcodec_dec_enable_hardware (ctx, ctx->hw_id); ret = ctx->dec_if->init (ctx); -mtk_vcodec_dec_clock_off (ctx->dev, ctx->hw_id); -mtk_vdec_unlock (ctx); +mtk_vcodec_dec_disable_hardware (ctx, ctx->hw_id);return ret; }
@@ -70,15 +68,11 @@ int vdec_if_decode(struct mtk_vcodec_ctx *ctx, struct mtk_vcodec_mem *bs,if (!ctx->drv_handle)return -EIO ; -mtk_vdec_lock (ctx); - +mtk_vcodec_dec_enable_hardware (ctx, ctx->hw_id);mtk_vcodec_set_curr_ctx (ctx->dev, ctx, ctx->hw_id); -mtk_vcodec_dec_clock_on (ctx->dev, ctx->hw_id); ret = ctx->dec_if->decode (ctx->drv_handle, bs, fb, res_chg); -mtk_vcodec_dec_clock_off (ctx->dev, ctx->hw_id);mtk_vcodec_set_curr_ctx (ctx->dev,NULL , ctx->hw_id); - -mtk_vdec_unlock (ctx); +mtk_vcodec_dec_disable_hardware (ctx, ctx->hw_id);return ret; }
@@ -103,11 +97,9 @@ void vdec_if_deinit(struct mtk_vcodec_ctx *ctx)if (!ctx->drv_handle)return ; -mtk_vdec_lock (ctx); -mtk_vcodec_dec_clock_on (ctx->dev, ctx->hw_id); +mtk_vcodec_dec_enable_hardware (ctx, ctx->hw_id); ctx->dec_if->deinit (ctx->drv_handle); -mtk_vcodec_dec_clock_off (ctx->dev, ctx->hw_id); -mtk_vdec_unlock (ctx); +mtk_vcodec_dec_disable_hardware (ctx, ctx->hw_id); ctx->drv_handle =NULL ; }
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +2 -0
@@ -212,11 +212,13 @@ static void vdec_msg_queue_core_work(struct work_struct *work)return ; ctx = lat_buf->ctx; +mtk_vcodec_dec_enable_hardware (ctx,MTK_VDEC_CORE );mtk_vcodec_set_curr_ctx (dev, ctx,MTK_VDEC_CORE ); lat_buf->core_decode (lat_buf);mtk_vcodec_set_curr_ctx (dev,NULL ,MTK_VDEC_CORE ); +mtk_vcodec_dec_disable_hardware (ctx,MTK_VDEC_CORE );vdec_msg_queue_qbuf (&ctx->msg_queue.lat_ctx, lat_buf);if (!list_empty (&ctx->msg_queue.lat_ctx.ready_queue)) {
Signature · 1 line
2.18.0
Yunfei Dong
maintainerPATCH v8 2/17 media: mediatek: vcodec: Using firmware type to separate different firmware architecture
In reply to Yunfei DongMT8173 platform use vpu firmware, mt8183/mt8192 will use scp firmware instead, using chip name is not reasonable to separate different firmware architecture. Using firmware type is much better.
--- .../mediatek/vcodec/mtk_vcodec_dec_stateful.c | 1 - .../mediatek/vcodec/mtk_vcodec_dec_stateless.c | 2 -- .../media/platform/mediatek/vcodec/mtk_vcodec_drv.h | 13 ------------- .../platform/mediatek/vcodec/mtk_vcodec_enc_drv.c | 5 ----- .../media/platform/mediatek/vcodec/mtk_vcodec_fw.c | 6 ++++++ .../media/platform/mediatek/vcodec/mtk_vcodec_fw.h | 1 + .../media/platform/mediatek/vcodec/vdec_vpu_if.c | 4 ++-- .../media/platform/mediatek/vcodec/venc_vpu_if.c | 2 +- 8 files changed, 10 insertions(+), 24 deletions(-)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c +0 -1
@@ -613,7 +613,6 @@ static struct vb2_ops mtk_vdec_frame_vb2_ops = { };const struct mtk_vcodec_dec_pdata mtk_vdec_8173_pdata = { - .chip =MTK_MT8173 , .init_vdec_params = mtk_init_vdec_params, .ctrls_setup = mtk_vcodec_dec_ctrls_setup, .vdec_vb2_ops = &mtk_vdec_frame_vb2_ops,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c +0 -2
@@ -343,7 +343,6 @@ static struct vb2_ops mtk_vdec_request_vb2_ops = { };const struct mtk_vcodec_dec_pdata mtk_vdec_8183_pdata = { - .chip =MTK_MT8183 , .init_vdec_params = mtk_init_vdec_params, .ctrls_setup = mtk_vcodec_dec_ctrls_setup, .vdec_vb2_ops = &mtk_vdec_request_vb2_ops,
@@ -362,7 +361,6 @@ const struct mtk_vcodec_dec_pdata mtk_vdec_8183_pdata = {/* This platform data is used for one lat and one core architecture. */ const struct mtk_vcodec_dec_pdata mtk_lat_sig_core_pdata = { - .chip =MTK_MT8192 , .init_vdec_params = mtk_init_vdec_params, .ctrls_setup = mtk_vcodec_dec_ctrls_setup, .vdec_vb2_ops = &mtk_vdec_request_vb2_ops,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +0 -13
@@ -332,13 +332,6 @@ struct mtk_vcodec_ctx {struct vdec_msg_queue msg_queue; }; -enum mtk_chip { -MTK_MT8173 , -MTK_MT8183 , -MTK_MT8192 , -MTK_MT8195 , -}; -/* * enum mtk_vdec_hw_arch - Used to separate different hardware architecture */
@@ -364,7 +357,6 @@ enum mtk_vdec_hw_arch {* @vdec_framesizes: supported video decoder frame sizes * @num_framesizes: count of video decoder frame sizes * -* @chip: chip this decoder is compatible with * @hw_arch: hardware arch is used to separate pure_sin_core and lat_sin_core * * @is_subdev_supported: whether support parent-node architecture(subdev)
@@ -387,7 +379,6 @@ struct mtk_vcodec_dec_pdata {const struct mtk_codec_framesizes *vdec_framesizes;const int num_framesizes; -enum mtk_chip chip;enum mtk_vdec_hw_arch hw_arch;bool is_subdev_supported;
@@ -397,8 +388,6 @@ struct mtk_vcodec_dec_pdata {/** * struct mtk_vcodec_enc_pdata - compatible data for each IC * -* @chip: chip this encoder is compatible with -* * @uses_ext: whether the encoder uses the extended firmware messaging format * @min_bitrate: minimum supported encoding bitrate * @max_bitrate: maximum supported encoding bitrate
@@ -409,8 +398,6 @@ struct mtk_vcodec_dec_pdata {* @core_id: stand for h264 or vp8 encode index */ struct mtk_vcodec_enc_pdata { -enum mtk_chip chip; -bool uses_ext;unsigned long min_bitrate;unsigned long max_bitrate;
drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c +0 -5
@@ -376,7 +376,6 @@ static int mtk_vcodec_probe(struct platform_device *pdev) }static const struct mtk_vcodec_enc_pdata mt8173_avc_pdata = { - .chip =MTK_MT8173 , .capture_formats = mtk_video_formats_capture_h264, .num_capture_formats =ARRAY_SIZE (mtk_video_formats_capture_h264), .output_formats = mtk_video_formats_output,
@@ -387,7 +386,6 @@ static const struct mtk_vcodec_enc_pdata mt8173_avc_pdata = { };static const struct mtk_vcodec_enc_pdata mt8173_vp8_pdata = { - .chip =MTK_MT8173 , .capture_formats = mtk_video_formats_capture_vp8, .num_capture_formats =ARRAY_SIZE (mtk_video_formats_capture_vp8), .output_formats = mtk_video_formats_output,
@@ -398,7 +396,6 @@ static const struct mtk_vcodec_enc_pdata mt8173_vp8_pdata = { };static const struct mtk_vcodec_enc_pdata mt8183_pdata = { - .chip =MTK_MT8183 , .uses_ext = true, .capture_formats = mtk_video_formats_capture_h264, .num_capture_formats =ARRAY_SIZE (mtk_video_formats_capture_h264),
@@ -410,7 +407,6 @@ static const struct mtk_vcodec_enc_pdata mt8183_pdata = { };static const struct mtk_vcodec_enc_pdata mt8192_pdata = { - .chip =MTK_MT8192 , .uses_ext = true, .capture_formats = mtk_video_formats_capture_h264, .num_capture_formats =ARRAY_SIZE (mtk_video_formats_capture_h264),
@@ -422,7 +418,6 @@ static const struct mtk_vcodec_enc_pdata mt8192_pdata = { };static const struct mtk_vcodec_enc_pdata mt8195_pdata = { - .chip =MTK_MT8195 , .uses_ext = true, .capture_formats = mtk_video_formats_capture_h264, .num_capture_formats =ARRAY_SIZE (mtk_video_formats_capture_h264),
drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw.c +6 -0
@@ -65,3 +65,9 @@ int mtk_vcodec_fw_ipi_send(struct mtk_vcodec_fw *fw, int id, void *buf,return fw->ops->ipi_send (fw, id, buf, len, wait); }EXPORT_SYMBOL_GPL (mtk_vcodec_fw_ipi_send); + +int mtk_vcodec_fw_get_type (struct mtk_vcodec_fw *fw) +{ +return fw->type; +} +EXPORT_SYMBOL_GPL (mtk_vcodec_fw_get_type);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw.h +1 -0
@@ -39,5 +39,6 @@ int mtk_vcodec_fw_ipi_register(struct mtk_vcodec_fw *fw, int id, const char *name, void *priv);int mtk_vcodec_fw_ipi_send (struct mtk_vcodec_fw *fw,int id,void *buf,unsigned int len,unsigned int wait); +int mtk_vcodec_fw_get_type (struct mtk_vcodec_fw *fw);#endif /* _MTK_VCODEC_FW_H_ */
drivers/media/platform/mediatek/vcodec/vdec_vpu_if.c +2 -2
@@ -33,8 +33,8 @@ static void handle_init_ack_msg(const struct vdec_vpu_ipi_init_ack *msg)*/ vpu->inst_id =0xdeadbeef ; -/* Firmware version field does not exist on MT8173. */ -if (vpu->ctx->dev->vdec_pdata->chip ==MTK_MT8173 ) +/* VPU firmware does not contain a version field. */ +if (mtk_vcodec_fw_get_type (vpu->ctx->dev->fw_handler) ==VPU )return ;/* Check firmware version. */
drivers/media/platform/mediatek/vcodec/venc_vpu_if.c +1 -1
@@ -18,7 +18,7 @@ static void handle_enc_init_msg(struct venc_vpu_inst *vpu, const void *data) msg->vpu_inst_addr);/* Firmware version field value is unspecified on MT8173. */ -if (vpu->ctx->dev->venc_pdata->chip ==MTK_MT8173 ) +if (mtk_vcodec_fw_get_type (vpu->ctx->dev->fw_handler) ==VPU )return ;/* Check firmware version. */
Signature · 1 line
2.18.0
Yunfei Dong
maintainerPATCH v8 3/17 media: mediatek: vcodec: get capture queue buffer size from scp
In reply to Yunfei DongDifferent capture buffer format has different buffer size, need to get real buffer size according to buffer type from scp.
--- .../platform/mediatek/vcodec/vdec_ipi_msg.h | 36 ++++++++++++++ .../platform/mediatek/vcodec/vdec_vpu_if.c | 49 +++++++++++++++++++ .../platform/mediatek/vcodec/vdec_vpu_if.h | 13 +++++ 3 files changed, 98 insertions(+)
drivers/media/platform/mediatek/vcodec/vdec_ipi_msg.h +36 -0
@@ -20,6 +20,7 @@ enum vdec_ipi_msgid {AP_IPIMSG_DEC_RESET =0xA004 ,AP_IPIMSG_DEC_CORE =0xA005 ,AP_IPIMSG_DEC_CORE_END =0xA006 , +AP_IPIMSG_DEC_GET_PARAM =0xA007 ,VPU_IPIMSG_DEC_INIT_ACK =0xB000 , VPU_IPIMSG_DEC_START_ACK = 0xB001,
@@ -28,6 +29,7 @@ enum vdec_ipi_msgid {VPU_IPIMSG_DEC_RESET_ACK =0xB004 ,VPU_IPIMSG_DEC_CORE_ACK =0xB005 ,VPU_IPIMSG_DEC_CORE_END_ACK =0xB006 , + VPU_IPIMSG_DEC_GET_PARAM_ACK = 0xB007, };/**
@@ -114,4 +116,38 @@ struct vdec_vpu_ipi_init_ack { uint32_t inst_id; }; +/** +* struct vdec_ap_ipi_get_param - for AP_IPIMSG_DEC_GET_PARAM +* @msg_id : AP_IPIMSG_DEC_GET_PARAM +* @inst_id : instance ID. Used if the ABI version >= 2. +* @data : picture information +* @param_type : get param type +* @codec_type : Codec fourcc +*/ +struct vdec_ap_ipi_get_param { +u32 msg_id; +u32 inst_id; +u32 data[4 ]; +u32 param_type; +u32 codec_type; +}; + +/** +* struct vdec_vpu_ipi_get_param_ack - for VPU_IPIMSG_DEC_GET_PARAM_ACK +* @msg_id : VPU_IPIMSG_DEC_GET_PARAM_ACK +* @status : VPU execution result +* @ap_inst_addr : AP vcodec_vpu_inst instance address +* @data : picture information from SCP. +* @param_type : get param type +* @reserved : reserved param +*/ +struct vdec_vpu_ipi_get_param_ack { +u32 msg_id; +s32 status; +u64 ap_inst_addr; +u32 data[4 ]; +u32 param_type; +u32 reserved; +}; +#endif
drivers/media/platform/mediatek/vcodec/vdec_vpu_if.c +49 -0
73 lines not on this page · raw message
drivers/media/platform/mediatek/vcodec/vdec_vpu_if.h +13 -0
@@ -28,6 +28,7 @@ struct mtk_vcodec_ctx;* @wq : wait queue to wait VPU message ack * @handler : ipi handler for each decoder * @codec_type : use codec type to separate different codecs +* @fb_sz : frame buffer size of each plane */ struct vdec_vpu_inst {int id;
@@ -42,6 +43,7 @@ struct vdec_vpu_inst {wait_queue_head_t wq;mtk_vcodec_ipi_handler handler;unsigned int codec_type; +unsigned int fb_sz[2 ]; };/**
@@ -104,4 +106,15 @@ int vpu_dec_core(struct vdec_vpu_inst *vpu);*/ int vpu_dec_core_end (struct vdec_vpu_inst *vpu); +/** +* vpu_dec_get_param - get param from scp +* +* @vpu : instance for vdec_vpu_inst +* @data: meta data to pass bitstream info to VPU decoder +* @len : meta data length +* @param_type : get param type +*/ +int vpu_dec_get_param (struct vdec_vpu_inst *vpu,uint32_t *data, +unsigned int len,unsigned int param_type); +#endif
Signature · 1 line
2.18.0
Yunfei Dong
maintainerPATCH v8 4/17 media: mediatek: vcodec: Read max resolution from dec_capability
In reply to Yunfei DongSupported max resolution for different platforms are not the same: 2K or 4K, getting it according to dec_capability.
--- .../platform/mediatek/vcodec/mtk_vcodec_dec.c | 44 ++++++++++--------- .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 4 ++ 2 files changed, 28 insertions(+), 20 deletions(-)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c +24 -20
@@ -152,13 +152,15 @@ void mtk_vcodec_dec_set_default_params(struct mtk_vcodec_ctx *ctx) q_data->coded_height =DFT_CFG_HEIGHT ; q_data->fmt = ctx->dev->vdec_pdata->default_cap_fmt; q_data->field =V4L2_FIELD_NONE ; + ctx->max_width =MTK_VDEC_MAX_W ; + ctx->max_height =MTK_VDEC_MAX_H ;v4l_bound_align_image (&q_data->coded_width,MTK_VDEC_MIN_W , -MTK_VDEC_MAX_W ,4 , + ctx->max_width,4 , &q_data->coded_height,MTK_VDEC_MIN_H , -MTK_VDEC_MAX_H ,5 ,6 ); + ctx->max_height,5 ,6 ); q_data->sizeimage[0 ] = q_data->coded_width * q_data->coded_height; q_data->bytesperline[0 ] = q_data->coded_width;
@@ -217,7 +219,7 @@ static int vidioc_vdec_subscribe_evt(struct v4l2_fh *fh, } } -static int vidioc_try_fmt (struct v4l2_format *f, +static int vidioc_try_fmt (struct mtk_vcodec_ctx *ctx,struct v4l2_format *f,const struct mtk_video_fmt *fmt) {struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
@@ -225,9 +227,9 @@ static int vidioc_try_fmt(struct v4l2_format *f, pix_fmt_mp->field =V4L2_FIELD_NONE ; pix_fmt_mp->width = -clamp (pix_fmt_mp->width,MTK_VDEC_MIN_W ,MTK_VDEC_MAX_W ); +clamp (pix_fmt_mp->width,MTK_VDEC_MIN_W , ctx->max_width); pix_fmt_mp->height = -clamp (pix_fmt_mp->height,MTK_VDEC_MIN_H ,MTK_VDEC_MAX_H ); +clamp (pix_fmt_mp->height,MTK_VDEC_MIN_H , ctx->max_height);if (f->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) { pix_fmt_mp->num_planes =1 ;
@@ -245,16 +247,16 @@ static int vidioc_try_fmt(struct v4l2_format *f, tmp_h = pix_fmt_mp->height;v4l_bound_align_image (&pix_fmt_mp->width,MTK_VDEC_MIN_W , -MTK_VDEC_MAX_W ,6 , + ctx->max_width,6 , &pix_fmt_mp->height,MTK_VDEC_MIN_H , -MTK_VDEC_MAX_H ,6 ,9 ); + ctx->max_height,6 ,9 );if (pix_fmt_mp->width < tmp_w && - (pix_fmt_mp->width +64 ) <=MTK_VDEC_MAX_W ) + (pix_fmt_mp->width +64 ) <= ctx->max_width) pix_fmt_mp->width +=64 ;if (pix_fmt_mp->height < tmp_h && - (pix_fmt_mp->height +64 ) <=MTK_VDEC_MAX_H ) + (pix_fmt_mp->height +64 ) <= ctx->max_height) pix_fmt_mp->height +=64 ; mtk_v4l2_debug(0,
@@ -294,7 +296,7 @@ static int vidioc_try_fmt_vid_cap_mplane(struct file *file, void *priv, fmt =mtk_vdec_find_format (f, dec_pdata); } -return vidioc_try_fmt (f, fmt); +return vidioc_try_fmt (ctx, f, fmt); } static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
@@ -317,7 +319,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,return -EINVAL ; } -return vidioc_try_fmt (f, fmt); +return vidioc_try_fmt (ctx, f, fmt); } static int vidioc_vdec_g_selection(struct file *file, void *priv,
@@ -444,8 +446,14 @@ static int vidioc_vdec_s_fmt(struct file *file, void *priv,if (fmt ==NULL )return -EINVAL ; +if (!(ctx->dev->dec_capability &VCODEC_CAPABILITY_4K_DISABLED )) { +mtk_v4l2_debug (3 ,"4K is enabled" ); + ctx->max_width =VCODEC_DEC_4K_CODED_WIDTH ; + ctx->max_height =VCODEC_DEC_4K_CODED_HEIGHT ; + } + q_data->fmt = fmt; -vidioc_try_fmt (f, q_data->fmt); +vidioc_try_fmt (ctx, f, q_data->fmt);if (f->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ) { q_data->sizeimage[0 ] = pix_mp->plane_fmt[0 ].sizeimage; q_data->coded_width = pix_mp->width;
@@ -529,14 +537,9 @@ static int vidioc_enum_framesizes(struct file *file, void *priv, fsize->type =V4L2_FRMSIZE_TYPE_STEPWISE ; fsize->stepwise = dec_pdata->vdec_framesizes[i].stepwise; -if (!(ctx->dev->dec_capability & -VCODEC_CAPABILITY_4K_DISABLED )) { -mtk_v4l2_debug (3 ,"4K is enabled" ); - fsize->stepwise.max_width = -VCODEC_DEC_4K_CODED_WIDTH ; - fsize->stepwise.max_height = -VCODEC_DEC_4K_CODED_HEIGHT ; - } + + fsize->stepwise.max_width = ctx->max_width; + fsize->stepwise.max_height = ctx->max_height; mtk_v4l2_debug(1, "%x, %d %d %d %d %d %d", ctx->dev->dec_capability, fsize->stepwise.min_width,
@@ -545,6 +548,7 @@ static int vidioc_enum_framesizes(struct file *file, void *priv, fsize->stepwise.min_height, fsize->stepwise.max_height, fsize->stepwise.step_height); +return 0 ; }
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4 -0
@@ -284,6 +284,8 @@ struct vdec_pic_info {* mtk_video_dec_buf. * @hw_id: hardware index used to identify different hardware. * +* @max_width: hardware supported max width +* @max_height: hardware supported max height * @msg_queue: msg queue used to store lat buffer information. */ struct mtk_vcodec_ctx {
@@ -329,6 +331,8 @@ struct mtk_vcodec_ctx {struct mutex lock;int hw_id; +unsigned int max_width; +unsigned int max_height;struct vdec_msg_queue msg_queue; };
Signature · 1 line
2.18.0
Yunfei Dong
maintainerPATCH v8 5/17 media: mediatek: vcodec: set each plane bytesused in buf prepare
In reply to Yunfei Dongcall vb2_set_plane_payload to set each plane bytesused in buf prepare, need not to set independently for stateless and statefull architectures.
--- .../platform/mediatek/vcodec/mtk_vcodec_dec.c | 2 ++ .../mediatek/vcodec/mtk_vcodec_dec_stateful.c | 5 ----- .../vcodec/mtk_vcodec_dec_stateless.c | 19 ------------------- 3 files changed, 2 insertions(+), 24 deletions(-)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c +2 -0
@@ -741,6 +741,8 @@ int vb2ops_vdec_buf_prepare(struct vb2_buffer *vb) i,vb2_plane_size (vb, i), q_data->sizeimage[i]); } +if (!V4L2_TYPE_IS_OUTPUT (vb->type)) +vb2_set_plane_payload (vb, i, q_data->sizeimage[i]); }return 0 ;
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c +0 -5
@@ -90,11 +90,6 @@ static struct vb2_buffer *get_display_buffer(struct mtk_vcodec_ctx *ctx) vb = &dstbuf->m2m_buf.vb;mutex_lock (&ctx->lock);if (dstbuf->used) { -vb2_set_plane_payload (&vb->vb2_buf,0 , ctx->picinfo.fb_sz[0 ]); -if (ctx->q_data[MTK_Q_DATA_DST ].fmt->num_planes ==2 ) -vb2_set_plane_payload (&vb->vb2_buf,1 , - ctx->picinfo.fb_sz[1 ]); -mtk_v4l2_debug (2 ,"[%d]status=%x queue id=%d to done_list %d" , ctx->id, disp_frame_buffer->status, vb->vb2_buf.index, dstbuf->queued_in_vb2);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c +0 -19
@@ -108,23 +108,6 @@ static const struct mtk_codec_framesizes mtk_vdec_framesizes[] = {#define NUM_SUPPORTED_FRAMESIZE ARRAY_SIZE(mtk_vdec_framesizes) -static void mtk_vdec_stateless_set_dst_payload (struct mtk_vcodec_ctx *ctx, -struct vdec_fb *fb) -{ -struct mtk_video_dec_buf *vdec_frame_buf = - container_of(fb, struct mtk_video_dec_buf, frame_buffer); -struct vb2_v4l2_buffer *vb = &vdec_frame_buf->m2m_buf.vb; -unsigned int cap_y_size = ctx->q_data[MTK_Q_DATA_DST ].sizeimage[0 ]; - -vb2_set_plane_payload (&vb->vb2_buf,0 , cap_y_size); -if (ctx->q_data[MTK_Q_DATA_DST ].fmt->num_planes ==2 ) { -unsigned int cap_c_size = - ctx->q_data[MTK_Q_DATA_DST ].sizeimage[1 ]; - -vb2_set_plane_payload (&vb->vb2_buf,1 , cap_c_size); - } -} -static struct vdec_fb *vdec_get_cap_buffer (struct mtk_vcodec_ctx *ctx,struct vb2_v4l2_buffer *vb2_v4l2) {
@@ -220,8 +203,6 @@ static void mtk_vdec_worker(struct work_struct *work) } } -mtk_vdec_stateless_set_dst_payload (ctx, dst_buf); -v4l2_m2m_buf_done_and_job_finish (dev->m2m_dev_dec, ctx->m2m_ctx, ret ?VB2_BUF_STATE_ERROR :VB2_BUF_STATE_DONE );
Signature · 1 line
2.18.0
Yunfei Dong
maintainerPATCH v8 6/17 media: mediatek: vcodec: Refactor get and put capture buffer flow
In reply to Yunfei DongFor lat and core decode in parallel, need to get capture buffer when core start to decode and put capture buffer to display list when core decode done.
---
changed compare with v7:
In order to adjust GStreamer, need to separate src buffer done with v4l2_ctrl_request_complete.
--- .../vcodec/mtk_vcodec_dec_stateless.c | 88 +++++++++++++------ .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 6 +- .../mediatek/vcodec/vdec/vdec_h264_req_if.c | 11 ++- .../platform/mediatek/vcodec/vdec_msg_queue.h | 2 + 4 files changed, 80 insertions(+), 27 deletions(-)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c +63 -25
@@ -108,20 +108,50 @@ static const struct mtk_codec_framesizes mtk_vdec_framesizes[] = {#define NUM_SUPPORTED_FRAMESIZE ARRAY_SIZE(mtk_vdec_framesizes) -static struct vdec_fb *vdec_get_cap_buffer (struct mtk_vcodec_ctx *ctx, -struct vb2_v4l2_buffer *vb2_v4l2) +static void mtk_vdec_stateless_cap_to_disp (struct mtk_vcodec_ctx *ctx,int error, +struct media_request *src_buf_req) { -struct mtk_video_dec_buf *framebuf = - container_of(vb2_v4l2, struct mtk_video_dec_buf, m2m_buf.vb); -struct vdec_fb *pfb = &framebuf->frame_buffer; -struct vb2_buffer *dst_buf = &vb2_v4l2->vb2_buf; +struct vb2_v4l2_buffer *vb2_dst; +enum vb2_buffer_state state; - pfb->base_y.va =NULL ; +if (error) + state =VB2_BUF_STATE_ERROR ; +else + state =VB2_BUF_STATE_DONE ; + + vb2_dst =v4l2_m2m_dst_buf_remove (ctx->m2m_ctx); +v4l2_m2m_buf_done (vb2_dst, state); + +mtk_v4l2_debug (2 ,"free frame buffer id:%d to done list" , + vb2_dst->vb2_buf.index); + +if (src_buf_req) +v4l2_ctrl_request_complete (src_buf_req, &ctx->ctrl_hdl); +} + +static struct vdec_fb *vdec_get_cap_buffer (struct mtk_vcodec_ctx *ctx) +{ +struct mtk_video_dec_buf *framebuf; +struct vb2_v4l2_buffer *vb2_v4l2; +struct vb2_buffer *dst_buf; +struct vdec_fb *pfb; + + vb2_v4l2 =v4l2_m2m_next_dst_buf (ctx->m2m_ctx); +if (!vb2_v4l2) { +mtk_v4l2_debug (1 ,"[%d] dst_buf empty!!" , ctx->id); +return NULL ; + } + + dst_buf = &vb2_v4l2->vb2_buf; + framebuf = container_of(vb2_v4l2, struct mtk_video_dec_buf, m2m_buf.vb); + + pfb = &framebuf->frame_buffer; + pfb->base_y.va =vb2_plane_vaddr (dst_buf,0 ); pfb->base_y.dma_addr =vb2_dma_contig_plane_dma_addr (dst_buf,0 ); pfb->base_y.size = ctx->q_data[MTK_Q_DATA_DST ].sizeimage[0 ];if (ctx->q_data[MTK_Q_DATA_DST ].fmt->num_planes ==2 ) { - pfb->base_c.va =NULL ; + pfb->base_c.va =vb2_plane_vaddr (dst_buf,1 ); pfb->base_c.dma_addr =vb2_dma_contig_plane_dma_addr (dst_buf,1 ); pfb->base_c.size = ctx->q_data[MTK_Q_DATA_DST ].sizeimage[1 ];
@@ -145,12 +175,12 @@ static void mtk_vdec_worker(struct work_struct *work)struct mtk_vcodec_ctx *ctx = container_of(work, struct mtk_vcodec_ctx, decode_work);struct mtk_vcodec_dev *dev = ctx->dev; -struct vb2_v4l2_buffer *vb2_v4l2_src, *vb2_v4l2_dst; +struct vb2_v4l2_buffer *vb2_v4l2_src;struct vb2_buffer *vb2_src;struct mtk_vcodec_mem *bs_src;struct mtk_video_dec_buf *dec_buf_src;struct media_request *src_buf_req; -struct vdec_fb *dst_buf; +enum vb2_buffer_state state;bool res_chg = false;int ret;
@@ -161,13 +191,6 @@ static void mtk_vdec_worker(struct work_struct *work)return ; } - vb2_v4l2_dst =v4l2_m2m_next_dst_buf (ctx->m2m_ctx); -if (!vb2_v4l2_dst) { -v4l2_m2m_job_finish (dev->m2m_dev_dec, ctx->m2m_ctx); -mtk_v4l2_debug (1 ,"[%d] no available destination buffer" , ctx->id); -return ; - } - vb2_src = &vb2_v4l2_src->vb2_buf; dec_buf_src = container_of(vb2_v4l2_src, struct mtk_video_dec_buf, m2m_buf.vb);
@@ -176,9 +199,15 @@ static void mtk_vdec_worker(struct work_struct *work)mtk_v4l2_debug (3 ,"[%d] (%d) id=%d, vb=%p" , ctx->id, vb2_src->vb2_queue->type, vb2_src->index, vb2_src); - bs_src->va =NULL ; + bs_src->va =vb2_plane_vaddr (vb2_src,0 ); bs_src->dma_addr =vb2_dma_contig_plane_dma_addr (vb2_src,0 ); bs_src->size = (size_t )vb2_src->planes[0 ].bytesused; +if (!bs_src->va) { +v4l2_m2m_job_finish (dev->m2m_dev_dec, ctx->m2m_ctx); +mtk_v4l2_err ("[%d] id=%d source buffer is NULL" , ctx->id, + vb2_src->index); +return ; + }mtk_v4l2_debug (3 ,"[%d] Bitstream VA=%p DMA=%pad Size=%zx vb=%p" , ctx->id, bs_src->va, &bs_src->dma_addr, bs_src->size, vb2_src);
@@ -189,9 +218,7 @@ static void mtk_vdec_worker(struct work_struct *work)else mtk_v4l2_err ("vb2 buffer media request is NULL" ); - dst_buf =vdec_get_cap_buffer (ctx, vb2_v4l2_dst); -v4l2_m2m_buf_copy_metadata (vb2_v4l2_src, vb2_v4l2_dst, true); - ret =vdec_if_decode (ctx, bs_src, dst_buf, &res_chg); + ret =vdec_if_decode (ctx, bs_src,NULL , &res_chg);if (ret) { mtk_v4l2_err(" <===[%d], src_buf[%d] sz=0x%zx pts=%llu vdec_if_decode() ret=%d res_chg=%d===>", ctx->id, vb2_src->index, bs_src->size,
@@ -203,10 +230,17 @@ static void mtk_vdec_worker(struct work_struct *work) } } -v4l2_m2m_buf_done_and_job_finish (dev->m2m_dev_dec, ctx->m2m_ctx, - ret ?VB2_BUF_STATE_ERROR :VB2_BUF_STATE_DONE ); - -v4l2_ctrl_request_complete (src_buf_req, &ctx->ctrl_hdl); + 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); + }else { +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); + } }static void vb2ops_vdec_stateless_buf_queue (struct vb2_buffer *vb)
@@ -336,6 +370,8 @@ const struct mtk_vcodec_dec_pdata mtk_vdec_8183_pdata = { .uses_stateless_api = true, .worker = mtk_vdec_worker, .flush_decoder = mtk_vdec_flush_decoder, + .cap_to_disp = mtk_vdec_stateless_cap_to_disp, + .get_cap_buffer = vdec_get_cap_buffer, .is_subdev_supported = false, .hw_arch = MTK_VDEC_PURE_SINGLE_CORE, };
@@ -354,6 +390,8 @@ const struct mtk_vcodec_dec_pdata mtk_lat_sig_core_pdata = { .uses_stateless_api = true, .worker = mtk_vdec_worker, .flush_decoder = mtk_vdec_flush_decoder, + .cap_to_disp = mtk_vdec_stateless_cap_to_disp, + .get_cap_buffer = vdec_get_cap_buffer, .is_subdev_supported = true, .hw_arch = MTK_VDEC_LAT_SINGLE_CORE, };
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +5 -1
@@ -350,7 +350,8 @@ enum mtk_vdec_hw_arch {* @ctrls_setup: init vcodec dec ctrls * @worker: worker to start a decode job * @flush_decoder: function that flushes the decoder -* +* @get_cap_buffer: get capture buffer from capture queue +* @cap_to_disp: put capture buffer to disp list for lat and core arch * @vdec_vb2_ops: struct vb2_ops * * @vdec_formats: supported video decoder formats
@@ -372,6 +373,9 @@ struct mtk_vcodec_dec_pdata {int (*ctrls_setup)(struct mtk_vcodec_ctx *ctx);void (*worker)(struct work_struct *work);int (*flush_decoder)(struct mtk_vcodec_ctx *ctx); +struct vdec_fb *(*get_cap_buffer)(struct mtk_vcodec_ctx *ctx); +void (*cap_to_disp)(struct mtk_vcodec_ctx *ctx,int error, +struct media_request *src_buf_req);struct vb2_ops *vdec_vb2_ops;
drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_if.c +10 -1
@@ -670,12 +670,15 @@ static void vdec_h264_slice_deinit(void *h_vdec) }static int vdec_h264_slice_decode (void *h_vdec,struct mtk_vcodec_mem *bs, -struct vdec_fb *fb,bool *res_chg) +struct vdec_fb *unused,bool *res_chg) {struct vdec_h264_slice_inst *inst = h_vdec;const struct v4l2_ctrl_h264_decode_params *dec_params =get_ctrl_ptr (inst->ctx,V4L2_CID_STATELESS_H264_DECODE_PARAMS );struct vdec_vpu_inst *vpu = &inst->vpu; +struct mtk_video_dec_buf *src_buf_info; +struct mtk_video_dec_buf *dst_buf_info; +struct vdec_fb *fb;u32 data[2 ];u64 y_fb_dma;u64 c_fb_dma;
@@ -685,6 +688,10 @@ static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,if (!bs)return vpu_dec_reset (vpu); + fb = inst->ctx->dev->vdec_pdata->get_cap_buffer (inst->ctx); + src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer); + dst_buf_info = container_of(fb, struct mtk_video_dec_buf, frame_buffer); + y_fb_dma = fb ? (u64 )fb->base_y.dma_addr :0 ; c_fb_dma = fb ? (u64 )fb->base_c.dma_addr :0 ;
@@ -696,6 +703,8 @@ static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs, inst->vsi_ctx.dec.c_fb_dma = c_fb_dma; inst->vsi_ctx.dec.vdec_fb_va = (u64 )(uintptr_t )fb; +v4l2_m2m_buf_copy_metadata (&src_buf_info->m2m_buf.vb, + &dst_buf_info->m2m_buf.vb, true);get_vdec_decode_parameters (inst); data[0 ] = bs->size;/*
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h +2 -0
@@ -43,6 +43,7 @@ struct vdec_msg_queue_ctx {* @wdma_err_addr: wdma error address used for lat hardware * @slice_bc_addr: slice bc address used for lat hardware * @ts_info: need to set timestamp from output to capture +* @src_buf_req: output buffer media request object * * @private_data: shared information used to lat and core hardware * @ctx: mtk vcodec context information
@@ -54,6 +55,7 @@ struct vdec_lat_buf {struct mtk_vcodec_mem wdma_err_addr;struct mtk_vcodec_mem slice_bc_addr;struct vb2_v4l2_buffer ts_info; +struct media_request *src_buf_req;void *private_data;struct mtk_vcodec_ctx *ctx;
Signature · 1 line
2.18.0
Yunfei Dong
maintainerPATCH v8 7/17 media: mediatek: vcodec: Refactor supported vdec formats and framesizes
In reply to Yunfei DongSupported output and capture format types for mt8192 are different with mt8183. Redefine parameters to store them.
--- .../media/platform/mediatek/vcodec/mtk_vcodec_dec.c | 8 ++++---- .../mediatek/vcodec/mtk_vcodec_dec_stateful.c | 13 ++++++++----- .../mediatek/vcodec/mtk_vcodec_dec_stateless.c | 13 +++++++------ .../media/platform/mediatek/vcodec/mtk_vcodec_drv.h | 13 +++++++++++-- 4 files changed, 30 insertions(+), 17 deletions(-)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c +4 -4
@@ -26,7 +26,7 @@ mtk_vdec_find_format(struct v4l2_format *f,const struct mtk_video_fmt *fmt;unsigned int k; -for (k =0 ; k < dec_pdata->num_formats; k++) { +for (k =0 ; k < *dec_pdata->num_formats; k++) { fmt = &dec_pdata->vdec_formats[k];if (fmt->fourcc == f->fmt.pix_mp.pixelformat)return fmt;
@@ -531,7 +531,7 @@ static int vidioc_enum_framesizes(struct file *file, void *priv,if (fsize->index !=0 )return -EINVAL ; -for (i =0 ; i < dec_pdata->num_framesizes; ++i) { +for (i =0 ; i < *dec_pdata->num_framesizes; ++i) {if (fsize->pixel_format != dec_pdata->vdec_framesizes[i].fourcc)continue ;
@@ -563,7 +563,7 @@ static int vidioc_enum_fmt(struct v4l2_fmtdesc *f, void *priv,const struct mtk_video_fmt *fmt;int i, j =0 ; -for (i =0 ; i < dec_pdata->num_formats; i++) { +for (i =0 ; i < *dec_pdata->num_formats; i++) {if (output_queue && dec_pdata->vdec_formats[i].type !=MTK_FMT_DEC )continue ;
@@ -576,7 +576,7 @@ static int vidioc_enum_fmt(struct v4l2_fmtdesc *f, void *priv, ++j; } -if (i == dec_pdata->num_formats) +if (i == *dec_pdata->num_formats)return -EINVAL ; fmt = &dec_pdata->vdec_formats[i];
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c +8 -5
@@ -37,7 +37,9 @@ static const struct mtk_video_fmt mtk_video_formats[] = { }, }; -#define NUM_FORMATS ARRAY_SIZE(mtk_video_formats) +static const unsigned int num_supported_formats = +ARRAY_SIZE (mtk_video_formats); +#define DEFAULT_OUT_FMT_IDX 0#define DEFAULT_CAP_FMT_IDX 3
@@ -59,7 +61,8 @@ static const struct mtk_codec_framesizes mtk_vdec_framesizes[] = { }, }; -#define NUM_SUPPORTED_FRAMESIZE ARRAY_SIZE(mtk_vdec_framesizes) +static const unsigned int num_supported_framesize = +ARRAY_SIZE (mtk_vdec_framesizes);/* * This function tries to clean all display buffers, the buffers will return
@@ -230,7 +233,7 @@ static void mtk_vdec_update_fmt(struct mtk_vcodec_ctx *ctx,unsigned int k; dst_q_data = &ctx->q_data[MTK_Q_DATA_DST ]; -for (k =0 ; k <NUM_FORMATS ; k++) { +for (k =0 ; k < num_supported_formats; k++) { fmt = &mtk_video_formats[k];if (fmt->fourcc == pixelformat) { mtk_v4l2_debug(1, "Update cap fourcc(%d -> %d)",
@@ -612,11 +615,11 @@ const struct mtk_vcodec_dec_pdata mtk_vdec_8173_pdata = { .ctrls_setup = mtk_vcodec_dec_ctrls_setup, .vdec_vb2_ops = &mtk_vdec_frame_vb2_ops, .vdec_formats = mtk_video_formats, - .num_formats = NUM_FORMATS, + .num_formats = &num_supported_formats, .default_out_fmt = &mtk_video_formats[DEFAULT_OUT_FMT_IDX], .default_cap_fmt = &mtk_video_formats[DEFAULT_CAP_FMT_IDX], .vdec_framesizes = mtk_vdec_framesizes, - .num_framesizes = NUM_SUPPORTED_FRAMESIZE, + .num_framesizes = &num_supported_framesize, .worker = mtk_vdec_worker, .flush_decoder = mtk_vdec_flush_decoder, .is_subdev_supported = false,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c +7 -6
@@ -94,7 +94,8 @@ static const struct mtk_video_fmt mtk_video_formats[] = { }, }; -#define NUM_FORMATS ARRAY_SIZE(mtk_video_formats) +static const unsigned int num_supported_formats =ARRAY_SIZE (mtk_video_formats); +#define DEFAULT_OUT_FMT_IDX 0#define DEFAULT_CAP_FMT_IDX 1
@@ -106,7 +107,7 @@ static const struct mtk_codec_framesizes mtk_vdec_framesizes[] = { }, }; -#define NUM_SUPPORTED_FRAMESIZE ARRAY_SIZE(mtk_vdec_framesizes) +static const unsigned int num_supported_framesize =ARRAY_SIZE (mtk_vdec_framesizes);static void mtk_vdec_stateless_cap_to_disp (struct mtk_vcodec_ctx *ctx,int error,struct media_request *src_buf_req)
@@ -362,11 +363,11 @@ const struct mtk_vcodec_dec_pdata mtk_vdec_8183_pdata = { .ctrls_setup = mtk_vcodec_dec_ctrls_setup, .vdec_vb2_ops = &mtk_vdec_request_vb2_ops, .vdec_formats = mtk_video_formats, - .num_formats = NUM_FORMATS, + .num_formats = &num_supported_formats, .default_out_fmt = &mtk_video_formats[DEFAULT_OUT_FMT_IDX], .default_cap_fmt = &mtk_video_formats[DEFAULT_CAP_FMT_IDX], .vdec_framesizes = mtk_vdec_framesizes, - .num_framesizes = NUM_SUPPORTED_FRAMESIZE, + .num_framesizes = &num_supported_framesize, .uses_stateless_api = true, .worker = mtk_vdec_worker, .flush_decoder = mtk_vdec_flush_decoder,
@@ -382,11 +383,11 @@ const struct mtk_vcodec_dec_pdata mtk_lat_sig_core_pdata = { .ctrls_setup = mtk_vcodec_dec_ctrls_setup, .vdec_vb2_ops = &mtk_vdec_request_vb2_ops, .vdec_formats = mtk_video_formats, - .num_formats = NUM_FORMATS, + .num_formats = &num_supported_formats, .default_out_fmt = &mtk_video_formats[DEFAULT_OUT_FMT_IDX], .default_cap_fmt = &mtk_video_formats[DEFAULT_CAP_FMT_IDX], .vdec_framesizes = mtk_vdec_framesizes, - .num_framesizes = NUM_SUPPORTED_FRAMESIZE, + .num_framesizes = &num_supported_framesize, .uses_stateless_api = true, .worker = mtk_vdec_worker, .flush_decoder = mtk_vdec_flush_decoder,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +11 -2
@@ -344,6 +344,15 @@ enum mtk_vdec_hw_arch { MTK_VDEC_LAT_SINGLE_CORE, }; +/* +* struct mtk_vdec_format_types - Structure used to get supported +* format types according to decoder capability +*/ +enum mtk_vdec_format_types { +MTK_VDEC_FORMAT_MM21 =0x20 , +MTK_VDEC_FORMAT_H264_SLICE =0x100 , +}; +/** * struct mtk_vcodec_dec_pdata - compatible data for each IC * @init_vdec_params: init vdec params
@@ -380,12 +389,12 @@ struct mtk_vcodec_dec_pdata {struct vb2_ops *vdec_vb2_ops;const struct mtk_video_fmt *vdec_formats; -const int num_formats; +const int *num_formats;const struct mtk_video_fmt *default_out_fmt;const struct mtk_video_fmt *default_cap_fmt;const struct mtk_codec_framesizes *vdec_framesizes; -const int num_framesizes; +const int *num_framesizes;enum mtk_vdec_hw_arch hw_arch;
Signature · 1 line
2.18.0
Yunfei Dong
maintainerPATCH v8 8/17 media: mediatek: vcodec: Getting supported decoder format types
In reply to Yunfei DongGetting supported output and capture queue format types according to decoder capability.
--- .../vcodec/mtk_vcodec_dec_stateless.c | 118 +++++++++++++----- 1 file changed, 84 insertions(+), 34 deletions(-)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c +84 -34
@@ -81,34 +81,23 @@ static const struct mtk_stateless_control mtk_stateless_controls[] = {#define NUM_CTRLS ARRAY_SIZE(mtk_stateless_controls) -static const struct mtk_video_fmt mtk_video_formats[] = { - { - .fourcc =V4L2_PIX_FMT_H264_SLICE , - .type =MTK_FMT_DEC , - .num_planes =1 , - }, - { - .fourcc =V4L2_PIX_FMT_MM21 , - .type =MTK_FMT_FRAME , - .num_planes =2 , - }, -}; - -static const unsigned int num_supported_formats =ARRAY_SIZE (mtk_video_formats); - -#define DEFAULT_OUT_FMT_IDX 0 -#define DEFAULT_CAP_FMT_IDX 1 - -static const struct mtk_codec_framesizes mtk_vdec_framesizes[] = { - { - .fourcc =V4L2_PIX_FMT_H264_SLICE , - .stepwise = {MTK_VDEC_MIN_W ,MTK_VDEC_MAX_W ,16 , -MTK_VDEC_MIN_H ,MTK_VDEC_MAX_H ,16 }, - }, +static struct mtk_video_fmt mtk_video_formats[2 ]; +static struct mtk_codec_framesizes mtk_vdec_framesizes[1 ]; + +static struct mtk_video_fmt default_out_format; +static struct mtk_video_fmt default_cap_format; +static unsigned int num_formats; +static unsigned int num_framesizes; + +static struct v4l2_frmsize_stepwise stepwise_fhd = { + .min_width =MTK_VDEC_MIN_W , + .max_width =MTK_VDEC_MAX_W , + .step_width =16 , + .min_height =MTK_VDEC_MIN_H , + .max_height =MTK_VDEC_MAX_H , + .step_height =16 }; -static const unsigned int num_supported_framesize =ARRAY_SIZE (mtk_vdec_framesizes); -static void mtk_vdec_stateless_cap_to_disp (struct mtk_vcodec_ctx *ctx,int error,struct media_request *src_buf_req) {
@@ -323,6 +312,62 @@ const struct media_device_ops mtk_vcodec_media_ops = { .req_queue = v4l2_m2m_request_queue, }; +static void mtk_vcodec_add_formats (unsigned int fourcc, +struct mtk_vcodec_ctx *ctx) +{ +struct mtk_vcodec_dev *dev = ctx->dev; +const struct mtk_vcodec_dec_pdata *pdata = dev->vdec_pdata; +int count_formats = *pdata->num_formats; +int count_framesizes = *pdata->num_framesizes; + +switch (fourcc) { +case V4L2_PIX_FMT_H264_SLICE : + mtk_video_formats[count_formats].fourcc = fourcc; + mtk_video_formats[count_formats].type =MTK_FMT_DEC ; + mtk_video_formats[count_formats].num_planes =1 ; + + mtk_vdec_framesizes[count_framesizes].fourcc = fourcc; + mtk_vdec_framesizes[count_framesizes].stepwise = stepwise_fhd; + num_framesizes++; +break ; +case V4L2_PIX_FMT_MM21 : + mtk_video_formats[count_formats].fourcc = fourcc; + mtk_video_formats[count_formats].type =MTK_FMT_FRAME ; + mtk_video_formats[count_formats].num_planes =2 ; +break ; +default : +mtk_v4l2_err ("Can not add unsupported format type" ); +return ; + } + + num_formats++; +mtk_v4l2_debug (3 ,"num_formats: %d num_frames:%d dec_capability: 0x%x" , + count_formats, count_framesizes, ctx->dev->dec_capability); +} + +static void mtk_vcodec_get_supported_formats (struct mtk_vcodec_ctx *ctx) +{ +int cap_format_count =0 , out_format_count =0 ; + +if (num_formats && num_framesizes) +return ; + +if (ctx->dev->dec_capability &MTK_VDEC_FORMAT_MM21 ) { +mtk_vcodec_add_formats (V4L2_PIX_FMT_MM21 , ctx); + cap_format_count++; + } +if (ctx->dev->dec_capability &MTK_VDEC_FORMAT_H264_SLICE ) { +mtk_vcodec_add_formats (V4L2_PIX_FMT_H264_SLICE , ctx); + out_format_count++; + } + +if (cap_format_count) + default_cap_format = mtk_video_formats[cap_format_count -1 ]; +if (out_format_count) + default_out_format = + mtk_video_formats[cap_format_count + out_format_count -1 ]; +} +static void mtk_init_vdec_params (struct mtk_vcodec_ctx *ctx) {struct vb2_queue *src_vq;
@@ -330,6 +375,11 @@ static void mtk_init_vdec_params(struct mtk_vcodec_ctx *ctx) src_vq =v4l2_m2m_get_vq (ctx->m2m_ctx,V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ); +if (!ctx->dev->vdec_pdata->is_subdev_supported) + ctx->dev->dec_capability |= +MTK_VDEC_FORMAT_H264_SLICE |MTK_VDEC_FORMAT_MM21 ; +mtk_vcodec_get_supported_formats (ctx); +/* Support request api for output plane */ src_vq->supports_requests = true; src_vq->requires_requests = true;
@@ -363,11 +413,11 @@ const struct mtk_vcodec_dec_pdata mtk_vdec_8183_pdata = { .ctrls_setup = mtk_vcodec_dec_ctrls_setup, .vdec_vb2_ops = &mtk_vdec_request_vb2_ops, .vdec_formats = mtk_video_formats, - .num_formats = &num_supported_formats, - .default_out_fmt = &mtk_video_formats[DEFAULT_OUT_FMT_IDX], - .default_cap_fmt = &mtk_video_formats[DEFAULT_CAP_FMT_IDX], + .num_formats = &num_formats, + .default_out_fmt = &default_out_format, + .default_cap_fmt = &default_cap_format, .vdec_framesizes = mtk_vdec_framesizes, - .num_framesizes = &num_supported_framesize, + .num_framesizes = &num_framesizes, .uses_stateless_api = true, .worker = mtk_vdec_worker, .flush_decoder = mtk_vdec_flush_decoder,
@@ -383,11 +433,11 @@ const struct mtk_vcodec_dec_pdata mtk_lat_sig_core_pdata = { .ctrls_setup = mtk_vcodec_dec_ctrls_setup, .vdec_vb2_ops = &mtk_vdec_request_vb2_ops, .vdec_formats = mtk_video_formats, - .num_formats = &num_supported_formats, - .default_out_fmt = &mtk_video_formats[DEFAULT_OUT_FMT_IDX], - .default_cap_fmt = &mtk_video_formats[DEFAULT_CAP_FMT_IDX], + .num_formats = &num_formats, + .default_out_fmt = &default_out_format, + .default_cap_fmt = &default_cap_format, .vdec_framesizes = mtk_vdec_framesizes, - .num_framesizes = &num_supported_framesize, + .num_framesizes = &num_framesizes, .uses_stateless_api = true, .worker = mtk_vdec_worker, .flush_decoder = mtk_vdec_flush_decoder,
Signature · 1 line
2.18.0
Yunfei Dong
maintainerPATCH v8 9/17 media: mediatek: vcodec: Add format to support MT21C
In reply to Yunfei DongNeeds to use mediatek compressed mode for mt8192 decoder.
--- .../platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c | 7 ++++++- drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c +6 -1
@@ -81,7 +81,7 @@ static const struct mtk_stateless_control mtk_stateless_controls[] = {#define NUM_CTRLS ARRAY_SIZE(mtk_stateless_controls) -static struct mtk_video_fmt mtk_video_formats[2 ]; +static struct mtk_video_fmt mtk_video_formats[3 ];static struct mtk_codec_framesizes mtk_vdec_framesizes[1 ];static struct mtk_video_fmt default_out_format;
@@ -331,6 +331,7 @@ static void mtk_vcodec_add_formats(unsigned int fourcc, num_framesizes++;break ;case V4L2_PIX_FMT_MM21 : +case V4L2_PIX_FMT_MT21C : mtk_video_formats[count_formats].fourcc = fourcc; mtk_video_formats[count_formats].type =MTK_FMT_FRAME ; mtk_video_formats[count_formats].num_planes =2 ;
@@ -356,6 +357,10 @@ static void mtk_vcodec_get_supported_formats(struct mtk_vcodec_ctx *ctx)mtk_vcodec_add_formats (V4L2_PIX_FMT_MM21 , ctx); cap_format_count++; } +if (ctx->dev->dec_capability &MTK_VDEC_FORMAT_MT21C ) { +mtk_vcodec_add_formats (V4L2_PIX_FMT_MT21C , ctx); + cap_format_count++; + }if (ctx->dev->dec_capability &MTK_VDEC_FORMAT_H264_SLICE ) {mtk_vcodec_add_formats (V4L2_PIX_FMT_H264_SLICE , ctx); out_format_count++;
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1 -0
@@ -350,6 +350,7 @@ enum mtk_vdec_hw_arch {*/ enum mtk_vdec_format_types {MTK_VDEC_FORMAT_MM21 =0x20 , +MTK_VDEC_FORMAT_MT21C =0x40 ,MTK_VDEC_FORMAT_H264_SLICE =0x100 , };
Signature · 1 line
2.18.0
Yunfei Dong
maintainerPATCH v8 10/17 media: mediatek: vcodec: disable vp8 4K capability
In reply to Yunfei DongFor vp8 not support 4K, need to disable it.
--- drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c +2 -1
@@ -446,7 +446,8 @@ static int vidioc_vdec_s_fmt(struct file *file, void *priv,if (fmt ==NULL )return -EINVAL ; -if (!(ctx->dev->dec_capability &VCODEC_CAPABILITY_4K_DISABLED )) { +if (!(ctx->dev->dec_capability &VCODEC_CAPABILITY_4K_DISABLED ) && + fmt->fourcc !=V4L2_PIX_FMT_VP8_FRAME ) {mtk_v4l2_debug (3 ,"4K is enabled" ); ctx->max_width =VCODEC_DEC_4K_CODED_WIDTH ; ctx->max_height =VCODEC_DEC_4K_CODED_HEIGHT ;
Signature · 1 line
2.18.0
Yunfei Dong
maintainerPATCH v8 11/17 media: mediatek: vcodec: Fix v4l2-compliance fail
In reply to Yunfei DongNeed to use default pic info when get pic info fail.
--- drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c +4 -1
@@ -485,11 +485,14 @@ static int vidioc_vdec_s_fmt(struct file *file, void *priv, ctx->picinfo.pic_w = pix_mp->width; ctx->picinfo.pic_h = pix_mp->height; +/* +* If get pic info fail, need to use the default pic info params, or +* v4l2-compliance will fail +*/ ret =vdec_if_get_param (ctx,GET_PARAM_PIC_INFO , &ctx->picinfo);if (ret) {mtk_v4l2_err ("[%d]Error!! Get GET_PARAM_PICTURE_INFO Fail" , ctx->id); -return -EINVAL ; } ctx->last_decoded_picinfo = ctx->picinfo;
Signature · 1 line
2.18.0
Yunfei Dong
maintainerPATCH v8 12/17 media: mediatek: vcodec: record capture queue format type
In reply to Yunfei DongThe capture queue format type may be differ depending on platform: for stateless decoder drivers, we need to calculate the capture buffer size according to the capture queue format type in SCP.
As a preparation for introducing drivers for stateless decoding, save the current capture queue type on a per vcodec context basis.
--- drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c | 2 ++ drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h | 2 ++ 2 files changed, 4 insertions(+)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c +2 -0
@@ -475,6 +475,8 @@ static int vidioc_vdec_s_fmt(struct file *file, void *priv, } ctx->state =MTK_STATE_INIT ; } + }else { + ctx->capture_fourcc = fmt->fourcc; }/*
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2 -0
@@ -274,6 +274,7 @@ struct vdec_pic_info {* to be used with encoder and stateful decoder. * @is_flushing: set to true if flushing is in progress. * @current_codec: current set input codec, in V4L2 pixel format +* @capture_fourcc: capture queue type in V4L2 pixel format * * @colorspace: enum v4l2_colorspace; supplemental to pixelformat * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding
@@ -321,6 +322,7 @@ struct mtk_vcodec_ctx {bool is_flushing;u32 current_codec; +u32 capture_fourcc;enum v4l2_colorspace colorspace;enum v4l2_ycbcr_encoding ycbcr_enc;
Signature · 1 line
2.18.0
Yunfei Dong
maintainerPATCH v8 13/17 media: mediatek: vcodec: Extract H264 common code
In reply to Yunfei DongMt8192 can use some of common code with mt8183. Moves them to a new file in order to reuse.
--- .../media/platform/mediatek/vcodec/Makefile | 1 + .../vcodec/vdec/vdec_h264_req_common.c | 310 +++++++++++++ .../vcodec/vdec/vdec_h264_req_common.h | 272 +++++++++++ .../mediatek/vcodec/vdec/vdec_h264_req_if.c | 427 ++---------------- 4 files changed, 627 insertions(+), 383 deletions(-) create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.h
drivers/media/platform/mediatek/vcodec/Makefile +1 -0
@@ -9,6 +9,7 @@ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \ vdec/vdec_vp8_if.o \ vdec/vdec_vp9_if.o \ vdec/vdec_h264_req_if.o \ + vdec/vdec_h264_req_common.o \ mtk_vcodec_dec_drv.o \ vdec_drv_if.o \ vdec_vpu_if.o \
drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c new file +310 -0
310 lines not on this page · raw message
drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.h new file +272 -0
272 lines not on this page · raw message
drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_if.c +44 -383
493 lines not on this page · raw message
Signature · 1 line
2.18.0
Yunfei Dong
maintainerPATCH v8 14/17 media: mediatek: vcodec: support stateless H.264 decoding for mt8192
In reply to Yunfei DongAdds h264 lat and core architecture driver for mt8192, and the decode mode is frame based for stateless decoder.
--- .../media/platform/mediatek/vcodec/Makefile | 1 + .../vcodec/vdec/vdec_h264_req_multi_if.c | 619 ++++++++++++++++++ .../platform/mediatek/vcodec/vdec_drv_if.c | 9 +- .../platform/mediatek/vcodec/vdec_drv_if.h | 1 + .../platform/mediatek/vcodec/vdec_vpu_if.h | 2 + include/linux/remoteproc/mtk_scp.h | 2 + 6 files changed, 633 insertions(+), 1 deletion(-) create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
drivers/media/platform/mediatek/vcodec/Makefile +1 -0
@@ -10,6 +10,7 @@ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \ vdec/vdec_vp9_if.o \ vdec/vdec_h264_req_if.o \ vdec/vdec_h264_req_common.o \ + vdec/vdec_h264_req_multi_if.o \ mtk_vcodec_dec_drv.o \ vdec_drv_if.o \ vdec_vpu_if.o \
drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c new file +619 -0
619 lines not on this page · raw message
drivers/media/platform/mediatek/vcodec/vdec_drv_if.c +8 -1
@@ -16,11 +16,18 @@int vdec_if_init (struct mtk_vcodec_ctx *ctx,unsigned int fourcc) { +enum mtk_vdec_hw_arch hw_arch = ctx->dev->vdec_pdata->hw_arch;int ret =0 ;switch (fourcc) {case V4L2_PIX_FMT_H264_SLICE : - ctx->dec_if = &vdec_h264_slice_if; +if (!ctx->dev->vdec_pdata->is_subdev_supported) { + ctx->dec_if = &vdec_h264_slice_if; + ctx->hw_id =MTK_VDEC_CORE ; + }else { + ctx->dec_if = &vdec_h264_slice_multi_if; + ctx->hw_id =IS_VDEC_LAT_ARCH (hw_arch) ?MTK_VDEC_LAT0 :MTK_VDEC_CORE ; + }break ;case V4L2_PIX_FMT_H264 : ctx->dec_if = &vdec_h264_if;
drivers/media/platform/mediatek/vcodec/vdec_drv_if.h +1 -0
@@ -56,6 +56,7 @@ struct vdec_fb_node {extern const struct vdec_common_if vdec_h264_if;extern const struct vdec_common_if vdec_h264_slice_if; +extern const struct vdec_common_if vdec_h264_slice_multi_if;extern const struct vdec_common_if vdec_vp8_if;extern const struct vdec_common_if vdec_vp9_if;
drivers/media/platform/mediatek/vcodec/vdec_vpu_if.h +2 -0
@@ -28,6 +28,7 @@ struct mtk_vcodec_ctx;* @wq : wait queue to wait VPU message ack * @handler : ipi handler for each decoder * @codec_type : use codec type to separate different codecs +* @capture_type: used capture type to separate different capture format * @fb_sz : frame buffer size of each plane */ struct vdec_vpu_inst {
@@ -43,6 +44,7 @@ struct vdec_vpu_inst {wait_queue_head_t wq;mtk_vcodec_ipi_handler handler;unsigned int codec_type; +unsigned int capture_type;unsigned int fb_sz[2 ]; };
include/linux/remoteproc/mtk_scp.h +2 -0
@@ -41,6 +41,8 @@ enum scp_ipi_id {SCP_IPI_ISP_FRAME ,SCP_IPI_FD_CMD ,SCP_IPI_CROS_HOST_CMD , +SCP_IPI_VDEC_LAT , +SCP_IPI_VDEC_CORE ,SCP_IPI_NS_SERVICE =0xFF , SCP_IPI_MAX = 0x100, };
Signature · 1 line
2.18.0
Yunfei Dong
maintainerPATCH v8 15/17 media: mediatek: vcodec: support stateless VP8 decoding
In reply to Yunfei DongAdd support for VP8 decoding using the stateless API, as supported by MT8192.
--- .../media/platform/mediatek/vcodec/Makefile | 1 + .../vcodec/mtk_vcodec_dec_stateless.c | 24 +- .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 1 + .../mediatek/vcodec/vdec/vdec_vp8_req_if.c | 437 ++++++++++++++++++ .../platform/mediatek/vcodec/vdec_drv_if.c | 4 + .../platform/mediatek/vcodec/vdec_drv_if.h | 1 + 6 files changed, 466 insertions(+), 2 deletions(-) create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c
drivers/media/platform/mediatek/vcodec/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-dec.o \ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \ vdec/vdec_vp8_if.o \ + vdec/vdec_vp8_req_if.o \ vdec/vdec_vp9_if.o \ vdec/vdec_h264_req_if.o \ vdec/vdec_h264_req_common.o \
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c +22 -2
@@ -76,13 +76,28 @@ static const struct mtk_stateless_control mtk_stateless_controls[] = { .max = V4L2_STATELESS_H264_START_CODE_ANNEX_B, }, .codec_type = V4L2_PIX_FMT_H264_SLICE, + }, + { + .cfg = { + .id = V4L2_CID_STATELESS_VP8_FRAME, + }, + .codec_type = V4L2_PIX_FMT_VP8_FRAME, + }, + { + .cfg = { + .id = V4L2_CID_MPEG_VIDEO_VP8_PROFILE, + .min = V4L2_MPEG_VIDEO_VP8_PROFILE_0, + .def = V4L2_MPEG_VIDEO_VP8_PROFILE_0, + .max = V4L2_MPEG_VIDEO_VP8_PROFILE_3, + }, + .codec_type = V4L2_PIX_FMT_VP8_FRAME, } };#define NUM_CTRLS ARRAY_SIZE(mtk_stateless_controls) -static struct mtk_video_fmt mtk_video_formats[3 ]; -static struct mtk_codec_framesizes mtk_vdec_framesizes[1 ]; +static struct mtk_video_fmt mtk_video_formats[4 ]; +static struct mtk_codec_framesizes mtk_vdec_framesizes[2 ];static struct mtk_video_fmt default_out_format;static struct mtk_video_fmt default_cap_format;
@@ -322,6 +337,7 @@ static void mtk_vcodec_add_formats(unsigned int fourcc,switch (fourcc) {case V4L2_PIX_FMT_H264_SLICE : +case V4L2_PIX_FMT_VP8_FRAME : mtk_video_formats[count_formats].fourcc = fourcc; mtk_video_formats[count_formats].type =MTK_FMT_DEC ; mtk_video_formats[count_formats].num_planes =1 ;
@@ -365,6 +381,10 @@ static void mtk_vcodec_get_supported_formats(struct mtk_vcodec_ctx *ctx)mtk_vcodec_add_formats (V4L2_PIX_FMT_H264_SLICE , ctx); out_format_count++; } +if (ctx->dev->dec_capability &MTK_VDEC_FORMAT_VP8_FRAME ) { +mtk_vcodec_add_formats (V4L2_PIX_FMT_VP8_FRAME , ctx); + out_format_count++; + }if (cap_format_count) default_cap_format = mtk_video_formats[cap_format_count -1 ];
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1 -0
@@ -354,6 +354,7 @@ enum mtk_vdec_format_types {MTK_VDEC_FORMAT_MM21 =0x20 ,MTK_VDEC_FORMAT_MT21C =0x40 ,MTK_VDEC_FORMAT_H264_SLICE =0x100 , + MTK_VDEC_FORMAT_VP8_FRAME = 0x200, };/**
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c new file +437 -0
437 lines not on this page · raw message
drivers/media/platform/mediatek/vcodec/vdec_drv_if.c +4 -0
@@ -33,6 +33,10 @@ int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc) ctx->dec_if = &vdec_h264_if; ctx->hw_id =MTK_VDEC_CORE ;break ; +case V4L2_PIX_FMT_VP8_FRAME : + ctx->dec_if = &vdec_vp8_slice_if; + ctx->hw_id =MTK_VDEC_CORE ; +break ;case V4L2_PIX_FMT_VP8 : ctx->dec_if = &vdec_vp8_if; ctx->hw_id =MTK_VDEC_CORE ;
drivers/media/platform/mediatek/vcodec/vdec_drv_if.h +1 -0
@@ -58,6 +58,7 @@ extern const struct vdec_common_if vdec_h264_if;extern const struct vdec_common_if vdec_h264_slice_if;extern const struct vdec_common_if vdec_h264_slice_multi_if;extern const struct vdec_common_if vdec_vp8_if; +extern const struct vdec_common_if vdec_vp8_slice_if;extern const struct vdec_common_if vdec_vp9_if;/**
Signature · 1 line
2.18.0
Yunfei Dong
maintainerPATCH v8 16/17 media: mediatek: vcodec: support stateless VP9 decoding
In reply to Yunfei DongAdd support for VP9 decoding using the stateless API,
as supported by MT8192. And the drivers is lat and core architecture.
---
changed compare with v7:
Using upstream interface to update vp9 prob tables.
--- .../media/platform/mediatek/vcodec/Makefile | 1 + .../vcodec/mtk_vcodec_dec_stateless.c | 26 +- .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 1 + .../vcodec/vdec/vdec_vp9_req_lat_if.c | 2072 +++++++++++++++++ .../platform/mediatek/vcodec/vdec_drv_if.c | 4 + .../platform/mediatek/vcodec/vdec_drv_if.h | 1 + 6 files changed, 2102 insertions(+), 3 deletions(-) create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
drivers/media/platform/mediatek/vcodec/Makefile +1 -0
@@ -9,6 +9,7 @@ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \ vdec/vdec_vp8_if.o \ vdec/vdec_vp8_req_if.o \ vdec/vdec_vp9_if.o \ + vdec/vdec_vp9_req_lat_if.o \ vdec/vdec_h264_req_if.o \ vdec/vdec_h264_req_common.o \ vdec/vdec_h264_req_multi_if.o \
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c +23 -3
@@ -91,13 +91,28 @@ static const struct mtk_stateless_control mtk_stateless_controls[] = { .max = V4L2_MPEG_VIDEO_VP8_PROFILE_3, }, .codec_type = V4L2_PIX_FMT_VP8_FRAME, - } + }, + { + .cfg = { + .id = V4L2_CID_STATELESS_VP9_FRAME, + }, + .codec_type = V4L2_PIX_FMT_VP9_FRAME, + }, + { + .cfg = { + .id = V4L2_CID_MPEG_VIDEO_VP9_PROFILE, + .min = V4L2_MPEG_VIDEO_VP9_PROFILE_0, + .def = V4L2_MPEG_VIDEO_VP9_PROFILE_0, + .max = V4L2_MPEG_VIDEO_VP9_PROFILE_3, + }, + .codec_type = V4L2_PIX_FMT_VP9_FRAME, + }, };#define NUM_CTRLS ARRAY_SIZE(mtk_stateless_controls) -static struct mtk_video_fmt mtk_video_formats[4 ]; -static struct mtk_codec_framesizes mtk_vdec_framesizes[2 ]; +static struct mtk_video_fmt mtk_video_formats[5 ]; +static struct mtk_codec_framesizes mtk_vdec_framesizes[3 ];static struct mtk_video_fmt default_out_format;static struct mtk_video_fmt default_cap_format;
@@ -338,6 +353,7 @@ static void mtk_vcodec_add_formats(unsigned int fourcc,switch (fourcc) {case V4L2_PIX_FMT_H264_SLICE :case V4L2_PIX_FMT_VP8_FRAME : +case V4L2_PIX_FMT_VP9_FRAME : mtk_video_formats[count_formats].fourcc = fourcc; mtk_video_formats[count_formats].type =MTK_FMT_DEC ; mtk_video_formats[count_formats].num_planes =1 ;
@@ -385,6 +401,10 @@ static void mtk_vcodec_get_supported_formats(struct mtk_vcodec_ctx *ctx)mtk_vcodec_add_formats (V4L2_PIX_FMT_VP8_FRAME , ctx); out_format_count++; } +if (ctx->dev->dec_capability &MTK_VDEC_FORMAT_VP9_FRAME ) { +mtk_vcodec_add_formats (V4L2_PIX_FMT_VP9_FRAME , ctx); + out_format_count++; + }if (cap_format_count) default_cap_format = mtk_video_formats[cap_format_count -1 ];
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1 -0
@@ -355,6 +355,7 @@ enum mtk_vdec_format_types {MTK_VDEC_FORMAT_MT21C =0x40 ,MTK_VDEC_FORMAT_H264_SLICE =0x100 ,MTK_VDEC_FORMAT_VP8_FRAME =0x200 , + MTK_VDEC_FORMAT_VP9_FRAME = 0x400, };/**
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c new file +2072 -0
2,072 lines not on this page · raw message
drivers/media/platform/mediatek/vcodec/vdec_drv_if.c +4 -0
@@ -45,6 +45,10 @@ int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc) ctx->dec_if = &vdec_vp9_if; ctx->hw_id =MTK_VDEC_CORE ;break ; +case V4L2_PIX_FMT_VP9_FRAME : + ctx->dec_if = &vdec_vp9_slice_lat_if; + ctx->hw_id =MTK_VDEC_LAT0 ; +break ;default :return -EINVAL ; }
drivers/media/platform/mediatek/vcodec/vdec_drv_if.h +1 -0
@@ -60,6 +60,7 @@ extern const struct vdec_common_if vdec_h264_slice_multi_if;extern const struct vdec_common_if vdec_vp8_if;extern const struct vdec_common_if vdec_vp8_slice_if;extern const struct vdec_common_if vdec_vp9_if; +extern const struct vdec_common_if vdec_vp9_slice_lat_if;/** * vdec_if_init() - initialize decode driver
Signature · 1 line
2.18.0
kernel test robot
build botRe: [PATCH v8, 16/17] media: mediatek: vcodec: support stateless VP9 decoding
Thank you for the patch! Yet something to improve:
Hi Yunfei,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on media-tree/master]
[also build test ERROR on linus/master next-20220331] [cannot apply to remoteproc/rproc-next linux/master v5.17] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Yunfei-Dong/media-mediatek-vcodec-Add-vdec-enable-disable-hardware-helpers/20220331-114806 base: git://linuxtv.org/media_tree.git master config: parisc-buildonly-randconfig-r002-20220331 (https://download.01.org/0day-ci/archive/20220331/[email protected]/config) compiler: hppa-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/7b396103061b487d6e9bc84be29de59e7eccc4c6
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Yunfei-Dong/media-mediatek-vcodec-Add-vdec-enable-disable-hardware-helpers/20220331-114806 git checkout 7b396103061b487d6e9bc84be29de59e7eccc4c6
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=parisc SHELL=/bin/bash drivers/media/platform/mediatek/vcodec/
If you fix the issue, kindly add following tag as appropriate
All error/warnings (new ones prefixed by >>):
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c: In function 'vdec_vp9_slice_map_counts_eob_coef':
>> drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:1235:69: error: assignment to 'u32 (*)[3]' {aka 'unsigned int (*)[3]'} from incompatible pointer type 'u32 (*)[4]' {aka 'unsigned int (*)[4]'} [-Werror=incompatible-pointer-types]
1235 | counts_helper->coeff[i][j][k][l][m] =
| ^
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:1242:69: error: assignment to 'u32 (*)[3]' {aka 'unsigned int (*)[3]'} from incompatible pointer type 'u32 (*)[4]' {aka 'unsigned int (*)[4]'} [-Werror=incompatible-pointer-types]
1242 | counts_helper->coeff[i][j][k][l][m] =
| ^
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c: In function 'vdec_vp9_slice_counts_map_helper':
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:1257:25: warning: unused variable 'm' [-Wunused-variable]
1257 | int i, j, k, l, m;
| ^
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:1257:22: warning: unused variable 'l' [-Wunused-variable]
1257 | int i, j, k, l, m;
| ^
In file included from include/linux/kernel.h:29,
from include/linux/cpumask.h:10,
from include/linux/mm_types_task.h:14,
from include/linux/mm_types.h:5,
from include/linux/buildid.h:5,
from include/linux/module.h:14,
from drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:7:
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c: In function 'vdec_vp9_slice_lat_decode':
>> include/linux/kern_levels.h:5:25: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 5 has type 'dma_addr_t' {aka 'unsigned int'} [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:418:25: note: in definition of macro 'printk_index_wrap'
418 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:132:17: note: in expansion of macro 'printk'
132 | printk(fmt, ##__VA_ARGS__); \
| ^~~~~~
include/linux/printk.h:576:9: note: in expansion of macro 'no_printk'
576 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~
include/linux/kern_levels.h:15:25: note: in expansion of macro 'KERN_SOH'
15 | #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
| ^~~~~~~~
include/linux/printk.h:576:19: note: in expansion of macro 'KERN_DEBUG'
576 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/../mtk_vcodec_util.h:45:9: note: in expansion of macro 'pr_debug'
45 | pr_debug("[MTK_VCODEC][%d]: " fmt "\n", \
| ^~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:1981:9: note: in expansion of macro 'mtk_vcodec_debug'
1981 | mtk_vcodec_debug(instance, "lat dma 1 0x%llx 0x%llx\n",
| ^~~~~~~~~~~~~~~~
include/linux/kern_levels.h:5:25: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 6 has type 'dma_addr_t' {aka 'unsigned int'} [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:418:25: note: in definition of macro 'printk_index_wrap'
418 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:132:17: note: in expansion of macro 'printk'
132 | printk(fmt, ##__VA_ARGS__); \
| ^~~~~~
include/linux/printk.h:576:9: note: in expansion of macro 'no_printk'
576 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~
include/linux/kern_levels.h:15:25: note: in expansion of macro 'KERN_SOH'
15 | #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
| ^~~~~~~~
include/linux/printk.h:576:19: note: in expansion of macro 'KERN_DEBUG'
576 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/../mtk_vcodec_util.h:45:9: note: in expansion of macro 'pr_debug'
45 | pr_debug("[MTK_VCODEC][%d]: " fmt "\n", \
| ^~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:1981:9: note: in expansion of macro 'mtk_vcodec_debug'
1981 | mtk_vcodec_debug(instance, "lat dma 1 0x%llx 0x%llx\n",
| ^~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c: In function 'vdec_vp9_slice_core_decode':
>> include/linux/kern_levels.h:5:25: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 5 has type 'dma_addr_t' {aka 'unsigned int'} [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:418:25: note: in definition of macro 'printk_index_wrap'
418 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:132:17: note: in expansion of macro 'printk'
132 | printk(fmt, ##__VA_ARGS__); \
| ^~~~~~
include/linux/printk.h:576:9: note: in expansion of macro 'no_printk'
576 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~
include/linux/kern_levels.h:15:25: note: in expansion of macro 'KERN_SOH'
15 | #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
| ^~~~~~~~
include/linux/printk.h:576:19: note: in expansion of macro 'KERN_DEBUG'
576 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/../mtk_vcodec_util.h:45:9: note: in expansion of macro 'pr_debug'
45 | pr_debug("[MTK_VCODEC][%d]: " fmt "\n", \
| ^~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:2050:9: note: in expansion of macro 'mtk_vcodec_debug'
2050 | mtk_vcodec_debug(instance, "core dma_addr_end 0x%llx\n", pfc->vsi.trans.dma_addr_end);
| ^~~~~~~~~~~~~~~~
At top level:
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:534:26: warning: 'vdec_vp9_slice_mv_fp_tree' defined but not used [-Wunused-const-variable=]
534 | static const signed char vdec_vp9_slice_mv_fp_tree[6] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:529:26: warning: 'vdec_vp9_slice_mv_class0_tree' defined but not used [-Wunused-const-variable=]
529 | static const signed char vdec_vp9_slice_mv_class0_tree[2] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:523:26: warning: 'vdec_vp9_slice_mv_class_tree' defined but not used [-Wunused-const-variable=]
523 | static const signed char vdec_vp9_slice_mv_class_tree[20] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:518:26: warning: 'vdec_vp9_slice_mv_joint_tree' defined but not used [-Wunused-const-variable=]
518 | static const signed char vdec_vp9_slice_mv_joint_tree[6] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:513:26: warning: 'vdec_vp9_slice_switchable_interp_tree' defined but not used [-Wunused-const-variable=]
513 | static const signed char vdec_vp9_slice_switchable_interp_tree[4] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:508:26: warning: 'vdec_vp9_slice_partition_tree' defined but not used [-Wunused-const-variable=]
508 | static const signed char vdec_vp9_slice_partition_tree[6] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:503:26: warning: 'vdec_vp9_slice_intra_mode_tree' defined but not used [-Wunused-const-variable=]
503 | static const signed char vdec_vp9_slice_intra_mode_tree[18] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:498:26: warning: 'vdec_vp9_slice_inter_mode_tree' defined but not used [-Wunused-const-variable=]
498 | static const signed char vdec_vp9_slice_inter_mode_tree[6] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~cc1: some warnings being treated as errors
vim +1235 drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
1217
1218 static
1219 void vdec_vp9_slice_map_counts_eob_coef(unsigned int i, unsigned int j, unsigned int k,
1220 struct vdec_vp9_slice_frame_counts *counts,
1221 struct v4l2_vp9_frame_symbol_counts *counts_helper)
1222 {
1223 u32 l, m;
1224
1225 /*
1226 * helper eo -> mtk eo
1227 * helpre e1 -> mtk c3
1228 * helper c0 -> c0
1229 * helper c1 -> c1
1230 * helper c2 -> c2
1231 */
1232 for (l = 0; l < 6; l++) {
1233 for (m = 0; m < VP9_BAND_6(l); m++) {
1234 if (l == 0) {
> 1235 counts_helper->coeff[i][j][k][l][m] =
1236 &counts->coef_probs[i][j][k].band_0[m];
1237 counts_helper->eob[i][j][k][l][m][0] =
1238 &counts->eob_branch[i][j][k].band_0[m];
1239 counts_helper->eob[i][j][k][l][m][1] =
1240 &counts->coef_probs[i][j][k].band_0[m][3];
1241 } else {
1242 counts_helper->coeff[i][j][k][l][m] =
1243 &counts->coef_probs[i][j][k].band_1_5[l - 1][m];
1244 counts_helper->eob[i][j][k][l][m][0] =
1245 &counts->eob_branch[i][j][k].band_1_5[l - 1][m];
1246 counts_helper->eob[i][j][k][l][m][1] =
1247 &counts->coef_probs[i][j][k].band_1_5[l - 1][m][3];
1248 }
1249 }
1250 }
1251 }
1252
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
kernel test robot
build botRe: [PATCH v8, 16/17] media: mediatek: vcodec: support stateless VP9 decoding
In reply to Yunfei DongThank you for the patch! Yet something to improve:
Hi Yunfei,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on media-tree/master]
[also build test ERROR on linus/master next-20220331] [cannot apply to remoteproc/rproc-next linux/master v5.17] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Yunfei-Dong/media-mediatek-vcodec-Add-vdec-enable-disable-hardware-helpers/20220331-114806 base: git://linuxtv.org/media_tree.git master config: powerpc-allmodconfig (https://download.01.org/0day-ci/archive/20220331/[email protected]/config) compiler: powerpc-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/7b396103061b487d6e9bc84be29de59e7eccc4c6
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Yunfei-Dong/media-mediatek-vcodec-Add-vdec-enable-disable-hardware-helpers/20220331-114806 git checkout 7b396103061b487d6e9bc84be29de59e7eccc4c6
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=powerpc SHELL=/bin/bash drivers/media/
If you fix the issue, kindly add following tag as appropriate
All error/warnings (new ones prefixed by >>):
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c: In function 'vdec_vp9_slice_map_counts_eob_coef':
>> drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:1235:69: error: assignment to 'u32 (*)[3]' {aka 'unsigned int (*)[3]'} from incompatible pointer type 'u32 (*)[4]' {aka 'unsigned int (*)[4]'} [-Werror=incompatible-pointer-types]
1235 | counts_helper->coeff[i][j][k][l][m] =
| ^
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:1242:69: error: assignment to 'u32 (*)[3]' {aka 'unsigned int (*)[3]'} from incompatible pointer type 'u32 (*)[4]' {aka 'unsigned int (*)[4]'} [-Werror=incompatible-pointer-types]
1242 | counts_helper->coeff[i][j][k][l][m] =
| ^
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c: In function 'vdec_vp9_slice_counts_map_helper':
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:1257:25: warning: unused variable 'm' [-Wunused-variable]
1257 | int i, j, k, l, m;
| ^
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:1257:22: warning: unused variable 'l' [-Wunused-variable]
1257 | int i, j, k, l, m;
| ^
In file included from drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:12:
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c: In function 'vdec_vp9_slice_lat_decode':
>> drivers/media/platform/mediatek/vcodec/vdec/../mtk_vcodec_util.h:29:21: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 6 has type 'dma_addr_t' {aka 'unsigned int'} [-Wformat=]
29 | #define pr_fmt(fmt) "%s(),%d: " fmt, __func__, __LINE__
| ^~~~~~~~~~~
include/linux/dynamic_debug.h:134:29: note: in expansion of macro 'pr_fmt'
134 | func(&id, ##__VA_ARGS__); \
| ^~~~~~~~~~~
include/linux/dynamic_debug.h:152:9: note: in expansion of macro '__dynamic_func_call'
152 | __dynamic_func_call(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/dynamic_debug.h:162:9: note: in expansion of macro '_dynamic_func_call'
162 | _dynamic_func_call(fmt, __dynamic_pr_debug, \
| ^~~~~~~~~~~~~~~~~~
include/linux/printk.h:570:9: note: in expansion of macro 'dynamic_pr_debug'
570 | dynamic_pr_debug(fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/../mtk_vcodec_util.h:45:9: note: in expansion of macro 'pr_debug'
45 | pr_debug("[MTK_VCODEC][%d]: " fmt "\n", \
| ^~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:1981:9: note: in expansion of macro 'mtk_vcodec_debug'
1981 | mtk_vcodec_debug(instance, "lat dma 1 0x%llx 0x%llx\n",
| ^~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/../mtk_vcodec_util.h:29:21: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 7 has type 'dma_addr_t' {aka 'unsigned int'} [-Wformat=]
29 | #define pr_fmt(fmt) "%s(),%d: " fmt, __func__, __LINE__
| ^~~~~~~~~~~
include/linux/dynamic_debug.h:134:29: note: in expansion of macro 'pr_fmt'
134 | func(&id, ##__VA_ARGS__); \
| ^~~~~~~~~~~
include/linux/dynamic_debug.h:152:9: note: in expansion of macro '__dynamic_func_call'
152 | __dynamic_func_call(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/dynamic_debug.h:162:9: note: in expansion of macro '_dynamic_func_call'
162 | _dynamic_func_call(fmt, __dynamic_pr_debug, \
| ^~~~~~~~~~~~~~~~~~
include/linux/printk.h:570:9: note: in expansion of macro 'dynamic_pr_debug'
570 | dynamic_pr_debug(fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/../mtk_vcodec_util.h:45:9: note: in expansion of macro 'pr_debug'
45 | pr_debug("[MTK_VCODEC][%d]: " fmt "\n", \
| ^~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:1981:9: note: in expansion of macro 'mtk_vcodec_debug'
1981 | mtk_vcodec_debug(instance, "lat dma 1 0x%llx 0x%llx\n",
| ^~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c: In function 'vdec_vp9_slice_core_decode':
>> drivers/media/platform/mediatek/vcodec/vdec/../mtk_vcodec_util.h:29:21: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 6 has type 'dma_addr_t' {aka 'unsigned int'} [-Wformat=]
29 | #define pr_fmt(fmt) "%s(),%d: " fmt, __func__, __LINE__
| ^~~~~~~~~~~
include/linux/dynamic_debug.h:134:29: note: in expansion of macro 'pr_fmt'
134 | func(&id, ##__VA_ARGS__); \
| ^~~~~~~~~~~
include/linux/dynamic_debug.h:152:9: note: in expansion of macro '__dynamic_func_call'
152 | __dynamic_func_call(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/dynamic_debug.h:162:9: note: in expansion of macro '_dynamic_func_call'
162 | _dynamic_func_call(fmt, __dynamic_pr_debug, \
| ^~~~~~~~~~~~~~~~~~
include/linux/printk.h:570:9: note: in expansion of macro 'dynamic_pr_debug'
570 | dynamic_pr_debug(fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/../mtk_vcodec_util.h:45:9: note: in expansion of macro 'pr_debug'
45 | pr_debug("[MTK_VCODEC][%d]: " fmt "\n", \
| ^~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:2050:9: note: in expansion of macro 'mtk_vcodec_debug'
2050 | mtk_vcodec_debug(instance, "core dma_addr_end 0x%llx\n", pfc->vsi.trans.dma_addr_end);
| ^~~~~~~~~~~~~~~~
At top level:
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:534:26: warning: 'vdec_vp9_slice_mv_fp_tree' defined but not used [-Wunused-const-variable=]
534 | static const signed char vdec_vp9_slice_mv_fp_tree[6] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:529:26: warning: 'vdec_vp9_slice_mv_class0_tree' defined but not used [-Wunused-const-variable=]
529 | static const signed char vdec_vp9_slice_mv_class0_tree[2] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:523:26: warning: 'vdec_vp9_slice_mv_class_tree' defined but not used [-Wunused-const-variable=]
523 | static const signed char vdec_vp9_slice_mv_class_tree[20] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:518:26: warning: 'vdec_vp9_slice_mv_joint_tree' defined but not used [-Wunused-const-variable=]
518 | static const signed char vdec_vp9_slice_mv_joint_tree[6] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:513:26: warning: 'vdec_vp9_slice_switchable_interp_tree' defined but not used [-Wunused-const-variable=]
513 | static const signed char vdec_vp9_slice_switchable_interp_tree[4] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:508:26: warning: 'vdec_vp9_slice_partition_tree' defined but not used [-Wunused-const-variable=]
508 | static const signed char vdec_vp9_slice_partition_tree[6] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:503:26: warning: 'vdec_vp9_slice_intra_mode_tree' defined but not used [-Wunused-const-variable=]
503 | static const signed char vdec_vp9_slice_intra_mode_tree[18] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:498:26: warning: 'vdec_vp9_slice_inter_mode_tree' defined but not used [-Wunused-const-variable=]
498 | static const signed char vdec_vp9_slice_inter_mode_tree[6] = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~cc1: some warnings being treated as errors
vim +1235 drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
1217
1218 static
1219 void vdec_vp9_slice_map_counts_eob_coef(unsigned int i, unsigned int j, unsigned int k,
1220 struct vdec_vp9_slice_frame_counts *counts,
1221 struct v4l2_vp9_frame_symbol_counts *counts_helper)
1222 {
1223 u32 l, m;
1224
1225 /*
1226 * helper eo -> mtk eo
1227 * helpre e1 -> mtk c3
1228 * helper c0 -> c0
1229 * helper c1 -> c1
1230 * helper c2 -> c2
1231 */
1232 for (l = 0; l < 6; l++) {
1233 for (m = 0; m < VP9_BAND_6(l); m++) {
1234 if (l == 0) {
> 1235 counts_helper->coeff[i][j][k][l][m] =
1236 &counts->coef_probs[i][j][k].band_0[m];
1237 counts_helper->eob[i][j][k][l][m][0] =
1238 &counts->eob_branch[i][j][k].band_0[m];
1239 counts_helper->eob[i][j][k][l][m][1] =
1240 &counts->coef_probs[i][j][k].band_0[m][3];
1241 } else {
1242 counts_helper->coeff[i][j][k][l][m] =
1243 &counts->coef_probs[i][j][k].band_1_5[l - 1][m];
1244 counts_helper->eob[i][j][k][l][m][0] =
1245 &counts->eob_branch[i][j][k].band_1_5[l - 1][m];
1246 counts_helper->eob[i][j][k][l][m][1] =
1247 &counts->coef_probs[i][j][k].band_1_5[l - 1][m][3];
1248 }
1249 }
1250 }
1251 }
1252
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
Re: [PATCH v8, 16/17] media: mediatek: vcodec: support stateless VP9 decoding
In reply to Yunfei DongHi Yunfei,
Le jeudi 31 mars 2022 à 10:48 +0800, Yunfei Dong a écrit :
Quoted 7 lines
Add support for VP9 decoding using the stateless API,
as supported by MT8192. And the drivers is lat and core architecture.Signed-off-by George Sun <[email protected]>Signed-off-by Xiaoyong Lu <[email protected]>Signed-off-by Yunfei Dong <[email protected]>Reviewed-by AngeloGioacchino Del Regno <[email protected]>
Reviewed-by should be dropped when large rework happens. In this case, the probability updated has been rewritten to use the common code (thanks for porting it). Unfortunately, running fluster tests shows massive regression (was 275/303) before):
Ran 34/303 tests successfully
H.264 (91/135) and VP9 (59/61) are same as before. Any idea ? What was your test results ?
Quoted 2,197 lines
---
changed compare with v7:
Using upstream interface to update vp9 prob tables.--- .../media/platform/mediatek/vcodec/Makefile | 1 + .../vcodec/mtk_vcodec_dec_stateless.c | 26 +- .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 1 + .../vcodec/vdec/vdec_vp9_req_lat_if.c | 2072 +++++++++++++++++ .../platform/mediatek/vcodec/vdec_drv_if.c | 4 + .../platform/mediatek/vcodec/vdec_drv_if.h | 1 + 6 files changed, 2102 insertions(+), 3 deletions(-) create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.cdrivers/media/platform/mediatek/vcodec/Makefile +1
-0@@ -9,6 +9,7 @@ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \ vdec/vdec_vp8_if.o \ vdec/vdec_vp8_req_if.o \ vdec/vdec_vp9_if.o \ + vdec/vdec_vp9_req_lat_if.o \ vdec/vdec_h264_req_if.o \ vdec/vdec_h264_req_common.o \ vdec/vdec_h264_req_multi_if.o \drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c +23
-3@@ -91,13 +91,28 @@ static const struct mtk_stateless_control mtk_stateless_controls[] = { .max = V4L2_MPEG_VIDEO_VP8_PROFILE_3, }, .codec_type = V4L2_PIX_FMT_VP8_FRAME, - } + }, + { + .cfg = { + .id = V4L2_CID_STATELESS_VP9_FRAME, + }, + .codec_type = V4L2_PIX_FMT_VP9_FRAME, + }, + { + .cfg = { + .id = V4L2_CID_MPEG_VIDEO_VP9_PROFILE, + .min = V4L2_MPEG_VIDEO_VP9_PROFILE_0, + .def = V4L2_MPEG_VIDEO_VP9_PROFILE_0, + .max = V4L2_MPEG_VIDEO_VP9_PROFILE_3, + }, + .codec_type = V4L2_PIX_FMT_VP9_FRAME, + }, };#define NUM_CTRLS ARRAY_SIZE(mtk_stateless_controls) -static struct mtk_video_fmt mtk_video_formats[4 ]; -static struct mtk_codec_framesizes mtk_vdec_framesizes[2 ]; +static struct mtk_video_fmt mtk_video_formats[5 ]; +static struct mtk_codec_framesizes mtk_vdec_framesizes[3 ];static struct mtk_video_fmt default_out_format;static struct mtk_video_fmt default_cap_format;@@ -338,6 +353,7 @@ static void mtk_vcodec_add_formats(unsigned int fourcc,switch (fourcc) {case V4L2_PIX_FMT_H264_SLICE :case V4L2_PIX_FMT_VP8_FRAME : +case V4L2_PIX_FMT_VP9_FRAME : mtk_video_formats[count_formats].fourcc = fourcc; mtk_video_formats[count_formats].type =MTK_FMT_DEC ; mtk_video_formats[count_formats].num_planes =1 ;@@ -385,6 +401,10 @@ static void mtk_vcodec_get_supported_formats(struct mtk_vcodec_ctx *ctx)mtk_vcodec_add_formats (V4L2_PIX_FMT_VP8_FRAME , ctx); out_format_count++; } +if (ctx->dev->dec_capability &MTK_VDEC_FORMAT_VP9_FRAME ) { +mtk_vcodec_add_formats (V4L2_PIX_FMT_VP9_FRAME , ctx); + out_format_count++; + }if (cap_format_count) default_cap_format = mtk_video_formats[cap_format_count -1 ];drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0@@ -355,6 +355,7 @@ enum mtk_vdec_format_types {MTK_VDEC_FORMAT_MT21C =0x40 ,MTK_VDEC_FORMAT_H264_SLICE =0x100 ,MTK_VDEC_FORMAT_VP8_FRAME =0x200 , + MTK_VDEC_FORMAT_VP9_FRAME = 0x400, };/** drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c new file +2072
-0@@ -0,0 +1,2072 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2021 MediaTek Inc. +* Author: George Sun <[email protected]> +*/ + +#include <linux/module.h> +#include <linux/slab.h> +#include <media/videobuf2-dma-contig.h> +#include <media/v4l2-vp9.h> + +#include "../mtk_vcodec_util.h" +#include "../mtk_vcodec_dec.h" +#include "../mtk_vcodec_intr.h" +#include "../vdec_drv_base.h" +#include "../vdec_drv_if.h" +#include "../vdec_vpu_if.h" + +/* reset_frame_context defined in VP9 spec */ +#define VP9_RESET_FRAME_CONTEXT_NONE0 0 +#define VP9_RESET_FRAME_CONTEXT_NONE1 1 +#define VP9_RESET_FRAME_CONTEXT_SPEC 2 +#define VP9_RESET_FRAME_CONTEXT_ALL 3 + +#define VP9_TILE_BUF_SIZE 4096 +#define VP9_PROB_BUF_SIZE 2560 +#define VP9_COUNTS_BUF_SIZE 16384 + +#define HDR_FLAG (x) (!!((hdr)->flags & V4L2_VP9_FRAME_FLAG_##x)) +#define LF_FLAG (x) (!!((lf)->flags & V4L2_VP9_LOOP_FILTER_FLAG_##x)) +#define SEG_FLAG (x) (!!((seg)->flags & V4L2_VP9_SEGMENTATION_FLAG_##x)) +#define VP9_BAND_6 (band) ((band) == 0 ? 3 : 6) + +/* +* struct vdec_vp9_slice_frame_ctx - vp9 prob tables footprint +*/ +struct vdec_vp9_slice_frame_ctx { +struct { +u8 probs[6 ][3 ]; +u8 padding[2 ]; + } coef_probs[4 ][2 ][2 ][6 ]; + +u8 y_mode_prob[4 ][16 ]; +u8 switch_interp_prob[4 ][16 ]; +u8 seg[32 ];/* ignore */ +u8 comp_inter_prob[16 ]; +u8 comp_ref_prob[16 ]; +u8 single_ref_prob[5 ][2 ]; +u8 single_ref_prob_padding[6 ]; + +u8 joint[3 ]; +u8 joint_padding[13 ]; +struct { +u8 sign; +u8 classes[10 ]; +u8 padding[5 ]; + } sign_classes[2 ]; +struct { +u8 class0[1 ]; +u8 bits[10 ]; +u8 padding[5 ]; + } class0_bits[2 ]; +struct { +u8 class0_fp[2 ][3 ]; +u8 fp[3 ]; +u8 class0_hp; +u8 hp; +u8 padding[5 ]; + } class0_fp_hp[2 ]; + +u8 uv_mode_prob[10 ][16 ]; +u8 uv_mode_prob_padding[2 ][16 ]; + +u8 partition_prob[16 ][4 ]; + +u8 inter_mode_probs[7 ][4 ]; +u8 skip_probs[4 ]; + +u8 tx_p8x8[2 ][4 ]; +u8 tx_p16x16[2 ][4 ]; +u8 tx_p32x32[2 ][4 ]; +u8 intra_inter_prob[8 ]; +}; + +/* +* struct vdec_vp9_slice_frame_counts - vp9 counts tables footprint +*/ +struct vdec_vp9_slice_frame_counts { +union { +struct { +u32 band_0[3 ]; +u32 padding0[1 ]; +u32 band_1_5[5 ][6 ]; +u32 padding1[2 ]; + } eob_branch[4 ][2 ][2 ]; +u32 eob_branch_space[256 *4 ]; + }; + +struct { +u32 band_0[3 ][4 ]; +u32 band_1_5[5 ][6 ][4 ]; + } coef_probs[4 ][2 ][2 ]; + +u32 intra_inter[4 ][2 ]; +u32 comp_inter[5 ][2 ]; +u32 comp_inter_padding[2 ]; +u32 comp_ref[5 ][2 ]; +u32 comp_ref_padding[2 ]; +u32 single_ref[5 ][2 ][2 ]; +u32 inter_mode[7 ][4 ]; +u32 y_mode[4 ][12 ]; +u32 uv_mode[10 ][10 ]; +u32 partition[16 ][4 ]; +u32 switchable_interp[4 ][4 ]; + +u32 tx_p8x8[2 ][2 ]; +u32 tx_p16x16[2 ][4 ]; +u32 tx_p32x32[2 ][4 ]; + +u32 skip[3 ][4 ]; + +u32 joint[4 ]; + +struct { +u32 sign[2 ]; +u32 class0[2 ]; +u32 classes[12 ]; +u32 bits[10 ][2 ]; +u32 padding[4 ]; +u32 class0_fp[2 ][4 ]; +u32 fp[4 ]; +u32 class0_hp[2 ]; +u32 hp[2 ]; + } mvcomp[2 ]; + +u32 reserved[126 ][4 ]; +}; + +/** +* struct vdec_vp9_slice_counts_map - vp9 counts tables to map +* v4l2_vp9_frame_symbol_counts +* @skip: skip counts. +* @y_mode: Y prediction mode counts. +* @filter: interpolation filter counts. +* @mv_joint: motion vector joint counts. +* @sign: motion vector sign counts. +* @classes: motion vector class counts. +* @class0: motion vector class0 bit counts. +* @bits: motion vector bits counts. +* @class0_fp: motion vector class0 fractional bit counts. +* @fp: motion vector fractional bit counts. +* @class0_hp: motion vector class0 high precision fractional bit counts. +* @hp: motion vector high precision fractional bit counts. +*/ +struct vdec_vp9_slice_counts_map { +u32 skip[3 ][2 ]; +u32 y_mode[4 ][10 ]; +u32 filter[4 ][3 ]; +u32 sign[2 ][2 ]; +u32 classes[2 ][11 ]; +u32 class0[2 ][2 ]; +u32 bits[2 ][10 ][2 ]; +u32 class0_fp[2 ][2 ][4 ]; +u32 fp[2 ][4 ]; +u32 class0_hp[2 ][2 ]; +u32 hp[2 ][2 ]; +}; + +/* +* struct vdec_vp9_slice_uncompressed_header - vp9 uncompressed header syntax +* used for decoding +*/ +struct vdec_vp9_slice_uncompressed_header { +u8 profile; +u8 last_frame_type; +u8 frame_type; + +u8 last_show_frame; +u8 show_frame; +u8 error_resilient_mode; + +u8 bit_depth; +u8 padding0[1 ]; +u16 last_frame_width; +u16 last_frame_height; +u16 frame_width; +u16 frame_height; + +u8 intra_only; +u8 reset_frame_context; +u8 ref_frame_sign_bias[4 ]; +u8 allow_high_precision_mv; +u8 interpolation_filter; + +u8 refresh_frame_context; +u8 frame_parallel_decoding_mode; +u8 frame_context_idx; + +/* loop_filter_params */ +u8 loop_filter_level; +u8 loop_filter_sharpness; +u8 loop_filter_delta_enabled; +s8 loop_filter_ref_deltas[4 ]; +s8 loop_filter_mode_deltas[2 ]; + +/* quantization_params */ +u8 base_q_idx; +s8 delta_q_y_dc; +s8 delta_q_uv_dc; +s8 delta_q_uv_ac; + +/* segmentation_params */ +u8 segmentation_enabled; +u8 segmentation_update_map; +u8 segmentation_tree_probs[7 ]; +u8 padding1[1 ]; +u8 segmentation_temporal_udpate; +u8 segmentation_pred_prob[3 ]; +u8 segmentation_update_data; +u8 segmentation_abs_or_delta_update; +u8 feature_enabled[8 ]; +s16 feature_value[8 ][4 ]; + +/* tile_info */ +u8 tile_cols_log2; +u8 tile_rows_log2; +u8 padding2[2 ]; + +u16 uncompressed_header_size; +u16 header_size_in_bytes; + +/* LAT OUT, CORE IN */ +u32 dequant[8 ][4 ]; +}; + +/* +* struct vdec_vp9_slice_compressed_header - vp9 compressed header syntax +* used for decoding. +*/ +struct vdec_vp9_slice_compressed_header { +u8 tx_mode; +u8 ref_mode; +u8 comp_fixed_ref; +u8 comp_var_ref[2 ]; +u8 padding[3 ]; +}; + +/* +* struct vdec_vp9_slice_tiles - vp9 tile syntax +*/ +struct vdec_vp9_slice_tiles { +u32 size[4 ][64 ]; +u32 mi_rows[4 ]; +u32 mi_cols[64 ]; +u8 actual_rows; +u8 padding[7 ]; +}; + +/* +* struct vdec_vp9_slice_reference - vp9 reference frame information +*/ +struct vdec_vp9_slice_reference { +u16 frame_width; +u16 frame_height; +u8 bit_depth; +u8 subsampling_x; +u8 subsampling_y; +u8 padding; +}; + +/* +* struct vdec_vp9_slice_frame - vp9 syntax used for decoding +*/ +struct vdec_vp9_slice_frame { +struct vdec_vp9_slice_uncompressed_header uh; +struct vdec_vp9_slice_compressed_header ch; +struct vdec_vp9_slice_tiles tiles; +struct vdec_vp9_slice_reference ref[3 ]; +}; + +/* +* struct vdec_vp9_slice_init_vsi - VSI used to initialize instance +*/ +struct vdec_vp9_slice_init_vsi { +unsigned int architecture; +unsigned int reserved; +u64 core_vsi; +/* default frame context's position in MicroP */ +u64 default_frame_ctx; +}; + +/* +* struct vdec_vp9_slice_mem - memory address and size +*/ +struct vdec_vp9_slice_mem { +union { +u64 buf; +dma_addr_t dma_addr; + }; +union { +size_t size; +dma_addr_t dma_addr_end; +u64 padding; + }; +}; + +/* +* struct vdec_vp9_slice_bs - input buffer for decoding +*/ +struct vdec_vp9_slice_bs { +struct vdec_vp9_slice_mem buf; +struct vdec_vp9_slice_mem frame; +}; + +/* +* struct vdec_vp9_slice_fb - frame buffer for decoding +*/ +struct vdec_vp9_slice_fb { +struct vdec_vp9_slice_mem y; +struct vdec_vp9_slice_mem c; +}; + +/* +* struct vdec_vp9_slice_state - decoding state +*/ +struct vdec_vp9_slice_state { +int err; +unsigned int full; +unsigned int timeout; +unsigned int perf; + +unsigned int crc[12 ]; +}; + +/** +* struct vdec_vp9_slice_vsi - exchange decoding information +* between Main CPU and MicroP +* +* @bs: input buffer +* @fb: output buffer +* @ref: 3 reference buffers +* @mv: mv working buffer +* @seg: segmentation working buffer +* @tile: tile buffer +* @prob: prob table buffer, used to set/update prob table +* @counts: counts table buffer, used to update prob table +* @ube: general buffer +* @trans: trans buffer position in general buffer +* @err_map: error buffer +* @row_info: row info buffer +* @frame: decoding syntax +* @state: decoding state +*/ +struct vdec_vp9_slice_vsi { +/* used in LAT stage */ +struct vdec_vp9_slice_bs bs; +/* used in Core stage */ +struct vdec_vp9_slice_fb fb; +struct vdec_vp9_slice_fb ref[3 ]; + +struct vdec_vp9_slice_mem mv[2 ]; +struct vdec_vp9_slice_mem seg[2 ]; +struct vdec_vp9_slice_mem tile; +struct vdec_vp9_slice_mem prob; +struct vdec_vp9_slice_mem counts; + +/* LAT stage's output, Core stage's input */ +struct vdec_vp9_slice_mem ube; +struct vdec_vp9_slice_mem trans; +struct vdec_vp9_slice_mem err_map; +struct vdec_vp9_slice_mem row_info; + +/* decoding parameters */ +struct vdec_vp9_slice_frame frame; + +struct vdec_vp9_slice_state state; +}; + +/** +* struct vdec_vp9_slice_pfc - per-frame context that contains a local vsi. +* pass it from lat to core +* +* @vsi: local vsi. copy to/from remote vsi before/after decoding +* @ref_idx: reference buffer index +* @seq: picture sequence +* @state: decoding state +*/ +struct vdec_vp9_slice_pfc { +struct vdec_vp9_slice_vsi vsi; + +u64 ref_idx[3 ]; + +int seq; + +/* LAT/Core CRC */ +struct vdec_vp9_slice_state state[2 ]; +}; + +/* +* enum vdec_vp9_slice_resolution_level +*/ +enum vdec_vp9_slice_resolution_level { +VP9_RES_NONE , +VP9_RES_FHD , +VP9_RES_4K , +VP9_RES_8K , +}; + +/* +* struct vdec_vp9_slice_ref - picture's width & height should kept +* for later decoding as reference picture +*/ +struct vdec_vp9_slice_ref { +unsigned int width; +unsigned int height; +}; + +/** +* struct vdec_vp9_slice_instance - represent one vp9 instance +* +* @ctx: pointer to codec's context +* @vpu: VPU instance +* @seq: global picture sequence +* @level: level of current resolution +* @width: width of last picture +* @height: height of last picture +* @frame_type: frame_type of last picture +* @irq: irq to Main CPU or MicroP +* @show_frame: show_frame of last picture +* @dpb: picture information (width/height) for reference +* @mv: mv working buffer +* @seg: segmentation working buffer +* @tile: tile buffer +* @prob: prob table buffer, used to set/update prob table +* @counts: counts table buffer, used to update prob table +* @frame_ctx: 4 frame context according to VP9 Spec +* @frame_ctx_helper: 4 frame context according to newest kernel spec +* @dirty: state of each frame context +* @init_vsi: vsi used for initialized VP9 instance +* @vsi: vsi used for decoding/flush ... +* @core_vsi: vsi used for Core stage +* @counts_map: used map to counts_helper +* &counts_helper: counts table according to newest kernel spec +*/ +struct vdec_vp9_slice_instance { +struct mtk_vcodec_ctx *ctx; +struct vdec_vpu_inst vpu; + +int seq; + +enum vdec_vp9_slice_resolution_level level; + +/* for resolution change and get_pic_info */ +unsigned int width; +unsigned int height; + +/* for last_frame_type */ +unsigned int frame_type; +unsigned int irq; + +unsigned int show_frame; + +/* maintain vp9 reference frame state */ +struct vdec_vp9_slice_ref dpb[VB2_MAX_FRAME ]; + +/* +* normal working buffers +* mv[0]/seg[0]/tile/prob/counts is used for LAT +* mv[1]/seg[1] is used for CORE +*/ +struct mtk_vcodec_mem mv[2 ]; +struct mtk_vcodec_mem seg[2 ]; +struct mtk_vcodec_mem tile; +struct mtk_vcodec_mem prob; +struct mtk_vcodec_mem counts; + +/* 4 prob tables */ +struct vdec_vp9_slice_frame_ctx frame_ctx[4 ]; +/*4 helper tables */ +struct v4l2_vp9_frame_context frame_ctx_helper; +unsigned char dirty[4 ]; + +/* MicroP vsi */ +union { +struct vdec_vp9_slice_init_vsi *init_vsi; +struct vdec_vp9_slice_vsi *vsi; + }; +struct vdec_vp9_slice_vsi *core_vsi; + +struct vdec_vp9_slice_counts_map counts_map; +struct v4l2_vp9_frame_symbol_counts counts_helper; +}; + +/* +* (2, (0, (1, 3))) +* max level = 2 +*/ +static const signed char vdec_vp9_slice_inter_mode_tree[6 ] = { +-2 ,2 ,0 ,4 ,-1 ,-3 +}; + +/* max level = 6 */ +static const signed char vdec_vp9_slice_intra_mode_tree[18 ] = { +0 ,2 ,-9 ,4 ,-1 ,6 ,8 ,12 ,-2 ,10 ,-4 ,-5 ,-3 ,14 ,-8 ,16 ,-6 ,-7 +}; + +/* max level = 2 */ +static const signed char vdec_vp9_slice_partition_tree[6 ] = { +0 ,2 ,-1 ,4 ,-2 ,-3 +}; + +/* max level = 1 */ +static const signed char vdec_vp9_slice_switchable_interp_tree[4 ] = { +0 ,2 ,-1 ,-2 +}; + +/* max level = 2 */ +static const signed char vdec_vp9_slice_mv_joint_tree[6 ] = { +0 ,2 ,-1 ,4 ,-2 ,-3 +}; + +/* max level = 6 */ +static const signed char vdec_vp9_slice_mv_class_tree[20 ] = { +0 ,2 ,-1 ,4 ,6 ,8 ,-2 ,-3 ,10 ,12 , +-4 ,-5 ,-6 ,14 ,16 ,18 ,-7 ,-8 ,-9 ,-10 +}; + +/* max level = 0 */ +static const signed char vdec_vp9_slice_mv_class0_tree[2 ] = { +0 ,-1 +}; + +/* max level = 2 */ +static const signed char vdec_vp9_slice_mv_fp_tree[6 ] = { +0 ,2 ,-1 ,4 ,-2 ,-3 +}; + +/* +* all VP9 instances could share this default frame context. +*/ +static struct vdec_vp9_slice_frame_ctx *vdec_vp9_slice_default_frame_ctx; +static DEFINE_MUTEX (vdec_vp9_slice_frame_ctx_lock); + +static int vdec_vp9_slice_core_decode (struct vdec_lat_buf *lat_buf); + +static int vdec_vp9_slice_init_default_frame_ctx (struct vdec_vp9_slice_instance *instance) +{ +struct vdec_vp9_slice_frame_ctx *remote_frame_ctx; +struct vdec_vp9_slice_frame_ctx *frame_ctx; +struct mtk_vcodec_ctx *ctx; +struct vdec_vp9_slice_init_vsi *vsi; +int ret =0 ; + + ctx = instance->ctx; + vsi = instance->vpu.vsi; +if (!ctx || !vsi) +return -EINVAL ; + + remote_frame_ctx =mtk_vcodec_fw_map_dm_addr (ctx->dev->fw_handler, + (u32 )vsi->default_frame_ctx); +if (!remote_frame_ctx) { +mtk_vcodec_err (instance,"failed to map default frame ctx\n" ); +return -EINVAL ; + } + +mutex_lock (&vdec_vp9_slice_frame_ctx_lock); +if (vdec_vp9_slice_default_frame_ctx) + goto out; + + frame_ctx =kmalloc (sizeof (*frame_ctx),GFP_KERNEL ); +if (!frame_ctx) { + ret = -ENOMEM ; + goto out; + } + +memcpy_fromio (frame_ctx, remote_frame_ctx,sizeof (*frame_ctx)); + vdec_vp9_slice_default_frame_ctx = frame_ctx; + +out: +mutex_unlock (&vdec_vp9_slice_frame_ctx_lock); + +return ret; +} + +static int vdec_vp9_slice_alloc_working_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi) +{ +struct mtk_vcodec_ctx *ctx = instance->ctx; +enum vdec_vp9_slice_resolution_level level; +/* super blocks */ +unsigned int max_sb_w; +unsigned int max_sb_h; +unsigned int max_w; +unsigned int max_h; +unsigned int w; +unsigned int h; +size_t size; +int ret; +int i; + + w = vsi->frame.uh.frame_width; + h = vsi->frame.uh.frame_height; + +if (w >VCODEC_DEC_4K_CODED_WIDTH || + h >VCODEC_DEC_4K_CODED_HEIGHT ) { +return -EINVAL ; + }else if (w >MTK_VDEC_MAX_W || h >MTK_VDEC_MAX_H ) { +/* 4K */ + level =VP9_RES_4K ; + max_w =VCODEC_DEC_4K_CODED_WIDTH ; + max_h =VCODEC_DEC_4K_CODED_HEIGHT ; + }else { +/* FHD */ + level =VP9_RES_FHD ; + max_w =MTK_VDEC_MAX_W ; + max_h =MTK_VDEC_MAX_H ; + } + +if (level == instance->level) +return 0 ; + +mtk_vcodec_debug (instance,"resolution level changed, from %u to %u, %ux%u" , + instance->level, level, w, h); + + max_sb_w =DIV_ROUND_UP (max_w,64 ); + max_sb_h =DIV_ROUND_UP (max_h,64 ); + ret = -ENOMEM ; + +/* +* Lat-flush must wait core idle, otherwise core will +* use released buffers +*/ + + size = (max_sb_w * max_sb_h +2 ) *576 ; +for (i =0 ; i <2 ; i++) { +if (instance->mv[i].va) +mtk_vcodec_mem_free (ctx, &instance->mv[i]); + instance->mv[i].size = size; +if (mtk_vcodec_mem_alloc (ctx, &instance->mv[i])) + goto err; + } + + size = (max_sb_w * max_sb_h *32 ) +256 ; +for (i =0 ; i <2 ; i++) { +if (instance->seg[i].va) +mtk_vcodec_mem_free (ctx, &instance->seg[i]); + instance->seg[i].size = size; +if (mtk_vcodec_mem_alloc (ctx, &instance->seg[i])) + goto err; + } + +if (!instance->tile.va) { + instance->tile.size =VP9_TILE_BUF_SIZE ; +if (mtk_vcodec_mem_alloc (ctx, &instance->tile)) + goto err; + } + +if (!instance->prob.va) { + instance->prob.size =VP9_PROB_BUF_SIZE ; +if (mtk_vcodec_mem_alloc (ctx, &instance->prob)) + goto err; + } + +if (!instance->counts.va) { + instance->counts.size =VP9_COUNTS_BUF_SIZE ; +if (mtk_vcodec_mem_alloc (ctx, &instance->counts)) + goto err; + } + + instance->level = level; +return 0 ; + +err: + instance->level =VP9_RES_NONE ; +return ret; +} + +static void vdec_vp9_slice_free_working_buffer (struct vdec_vp9_slice_instance *instance) +{ +struct mtk_vcodec_ctx *ctx = instance->ctx; +int i; + +for (i =0 ; i <ARRAY_SIZE (instance->mv); i++) { +if (instance->mv[i].va) +mtk_vcodec_mem_free (ctx, &instance->mv[i]); + } +for (i =0 ; i <ARRAY_SIZE (instance->seg); i++) { +if (instance->seg[i].va) +mtk_vcodec_mem_free (ctx, &instance->seg[i]); + } +if (instance->tile.va) +mtk_vcodec_mem_free (ctx, &instance->tile); +if (instance->prob.va) +mtk_vcodec_mem_free (ctx, &instance->prob); +if (instance->counts.va) +mtk_vcodec_mem_free (ctx, &instance->counts); + + instance->level =VP9_RES_NONE ; +} + +static void vdec_vp9_slice_vsi_from_remote (struct vdec_vp9_slice_vsi *vsi, +struct vdec_vp9_slice_vsi *remote_vsi, +int skip) +{ +struct vdec_vp9_slice_frame *rf; +struct vdec_vp9_slice_frame *f; + +/* +* compressed header +* dequant +* buffer position +* decode state +*/ +if (!skip) { + rf = &remote_vsi->frame; + f = &vsi->frame; +memcpy_fromio (&f->ch, &rf->ch,sizeof (f->ch)); +memcpy_fromio (&f->uh.dequant, &rf->uh.dequant,sizeof (f->uh.dequant)); +memcpy_fromio (&vsi->trans, &remote_vsi->trans,sizeof (vsi->trans)); + } + +memcpy_fromio (&vsi->state, &remote_vsi->state,sizeof (vsi->state)); +} + +static void vdec_vp9_slice_vsi_to_remote (struct vdec_vp9_slice_vsi *vsi, +struct vdec_vp9_slice_vsi *remote_vsi) +{ +memcpy_toio (remote_vsi, vsi,sizeof (*vsi)); +} + +static int vdec_vp9_slice_tile_offset (int idx,int mi_num,int tile_log2) +{ +int sbs = (mi_num +7 ) >>3 ; +int offset = ((idx * sbs) >> tile_log2) <<3 ; + +return offset < mi_num ? offset : mi_num; +} + +static int vdec_vp9_slice_setup_lat_from_src_buf (struct vdec_vp9_slice_instance *instance, +struct vdec_lat_buf *lat_buf) +{ +struct vb2_v4l2_buffer *src; +struct vb2_v4l2_buffer *dst; + + src =v4l2_m2m_next_src_buf (instance->ctx->m2m_ctx); +if (!src) +return -EINVAL ; + + lat_buf->src_buf_req = src->vb2_buf.req_obj.req; + + dst = &lat_buf->ts_info; +v4l2_m2m_buf_copy_metadata (src, dst, true); +return 0 ; +} + +static void vdec_vp9_slice_setup_hdr (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_uncompressed_header *uh, +struct v4l2_ctrl_vp9_frame *hdr) +{ +int i; + + uh->profile = hdr->profile; + uh->last_frame_type = instance->frame_type; + uh->frame_type = !HDR_FLAG (KEY_FRAME ); + uh->last_show_frame = instance->show_frame; + uh->show_frame =HDR_FLAG (SHOW_FRAME ); + uh->error_resilient_mode =HDR_FLAG (ERROR_RESILIENT ); + uh->bit_depth = hdr->bit_depth; + uh->last_frame_width = instance->width; + uh->last_frame_height = instance->height; + uh->frame_width = hdr->frame_width_minus_1 +1 ; + uh->frame_height = hdr->frame_height_minus_1 +1 ; + uh->intra_only =HDR_FLAG (INTRA_ONLY ); +/* map v4l2 enum to values defined in VP9 spec for firmware */ +switch (hdr->reset_frame_context) { +case V4L2_VP9_RESET_FRAME_CTX_NONE : + uh->reset_frame_context =VP9_RESET_FRAME_CONTEXT_NONE0 ; +break ; +case V4L2_VP9_RESET_FRAME_CTX_SPEC : + uh->reset_frame_context =VP9_RESET_FRAME_CONTEXT_SPEC ; +break ; +case V4L2_VP9_RESET_FRAME_CTX_ALL : + uh->reset_frame_context =VP9_RESET_FRAME_CONTEXT_ALL ; +break ; +default : + uh->reset_frame_context =VP9_RESET_FRAME_CONTEXT_NONE0 ; +break ; + } +/* +* ref_frame_sign_bias specifies the intended direction +* of the motion vector in time for each reference frame. +* - INTRA_FRAME = 0, +* - LAST_FRAME = 1, +* - GOLDEN_FRAME = 2, +* - ALTREF_FRAME = 3, +* ref_frame_sign_bias[INTRA_FRAME] is always 0 +* and VDA only passes another 3 directions +*/ + uh->ref_frame_sign_bias[0 ] =0 ; +for (i =0 ; i <3 ; i++) + uh->ref_frame_sign_bias[i +1 ] = + !!(hdr->ref_frame_sign_bias & (1 << i)); + uh->allow_high_precision_mv =HDR_FLAG (ALLOW_HIGH_PREC_MV ); + uh->interpolation_filter = hdr->interpolation_filter; + uh->refresh_frame_context =HDR_FLAG (REFRESH_FRAME_CTX ); + uh->frame_parallel_decoding_mode =HDR_FLAG (PARALLEL_DEC_MODE ); + uh->frame_context_idx = hdr->frame_context_idx; + +/* tile info */ + uh->tile_cols_log2 = hdr->tile_cols_log2; + uh->tile_rows_log2 = hdr->tile_rows_log2; + + uh->uncompressed_header_size = hdr->uncompressed_header_size; + uh->header_size_in_bytes = hdr->compressed_header_size; +} + +static void vdec_vp9_slice_setup_frame_ctx (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_uncompressed_header *uh, +struct v4l2_ctrl_vp9_frame *hdr) +{ +int error_resilient_mode; +int reset_frame_context; +int key_frame; +int intra_only; +int i; + + key_frame =HDR_FLAG (KEY_FRAME ); + intra_only =HDR_FLAG (INTRA_ONLY ); + error_resilient_mode =HDR_FLAG (ERROR_RESILIENT ); + reset_frame_context = uh->reset_frame_context; + +/* +* according to "6.2 Uncompressed header syntax" in +* "VP9 Bitstream & Decoding Process Specification", +* reset @frame_context_idx when (FrameIsIntra || error_resilient_mode) +*/ +if (key_frame || intra_only || error_resilient_mode) { +/* +* @reset_frame_context specifies +* whether the frame context should be +* reset to default values: +* 0 or 1 means do not reset any frame context +* 2 resets just the context specified in the frame header +* 3 resets all contexts +*/ +if (key_frame || error_resilient_mode || + reset_frame_context ==3 ) { +/* use default table */ +for (i =0 ; i <4 ; i++) + instance->dirty[i] =0 ; + }else if (reset_frame_context ==2 ) { + instance->dirty[uh->frame_context_idx] =0 ; + } + uh->frame_context_idx =0 ; + } +} + +static void vdec_vp9_slice_setup_loop_filter (struct vdec_vp9_slice_uncompressed_header *uh, +struct v4l2_vp9_loop_filter *lf) +{ +int i; + + uh->loop_filter_level = lf->level; + uh->loop_filter_sharpness = lf->sharpness; + uh->loop_filter_delta_enabled =LF_FLAG (DELTA_ENABLED ); +for (i =0 ; i <4 ; i++) + uh->loop_filter_ref_deltas[i] = lf->ref_deltas[i]; +for (i =0 ; i <2 ; i++) + uh->loop_filter_mode_deltas[i] = lf->mode_deltas[i]; +} + +static void vdec_vp9_slice_setup_quantization (struct vdec_vp9_slice_uncompressed_header *uh, +struct v4l2_vp9_quantization *quant) +{ + uh->base_q_idx = quant->base_q_idx; + uh->delta_q_y_dc = quant->delta_q_y_dc; + uh->delta_q_uv_dc = quant->delta_q_uv_dc; + uh->delta_q_uv_ac = quant->delta_q_uv_ac; +} + +static void vdec_vp9_slice_setup_segmentation (struct vdec_vp9_slice_uncompressed_header *uh, +struct v4l2_vp9_segmentation *seg) +{ +int i; +int j; + + uh->segmentation_enabled =SEG_FLAG (ENABLED ); + uh->segmentation_update_map =SEG_FLAG (UPDATE_MAP ); +for (i =0 ; i <7 ; i++) + uh->segmentation_tree_probs[i] = seg->tree_probs[i]; + uh->segmentation_temporal_udpate =SEG_FLAG (TEMPORAL_UPDATE ); +for (i =0 ; i <3 ; i++) + uh->segmentation_pred_prob[i] = seg->pred_probs[i]; + uh->segmentation_update_data =SEG_FLAG (UPDATE_DATA ); + uh->segmentation_abs_or_delta_update =SEG_FLAG (ABS_OR_DELTA_UPDATE ); +for (i =0 ; i <8 ; i++) { + uh->feature_enabled[i] = seg->feature_enabled[i]; +for (j =0 ; j <4 ; j++) + uh->feature_value[i][j] = seg->feature_data[i][j]; + } +} + +static int vdec_vp9_slice_setup_tile (struct vdec_vp9_slice_vsi *vsi, +struct v4l2_ctrl_vp9_frame *hdr) +{ +unsigned int rows_log2; +unsigned int cols_log2; +unsigned int rows; +unsigned int cols; +unsigned int mi_rows; +unsigned int mi_cols; +struct vdec_vp9_slice_tiles *tiles; +int offset; +int start; +int end; +int i; + + rows_log2 = hdr->tile_rows_log2; + cols_log2 = hdr->tile_cols_log2; + rows =1 << rows_log2; + cols =1 << cols_log2; + tiles = &vsi->frame.tiles; + tiles->actual_rows =0 ; + +if (rows >4 || cols >64 ) +return -EINVAL ; + +/* setup mi rows/cols information */ + mi_rows = (hdr->frame_height_minus_1 +1 +7 ) >>3 ; + mi_cols = (hdr->frame_width_minus_1 +1 +7 ) >>3 ; + +for (i =0 ; i < rows; i++) { + start =vdec_vp9_slice_tile_offset (i, mi_rows, rows_log2); + end =vdec_vp9_slice_tile_offset (i +1 , mi_rows, rows_log2); + offset = end - start; + tiles->mi_rows[i] = (offset +7 ) >>3 ; +if (tiles->mi_rows[i]) + tiles->actual_rows++; + } + +for (i =0 ; i < cols; i++) { + start =vdec_vp9_slice_tile_offset (i, mi_cols, cols_log2); + end =vdec_vp9_slice_tile_offset (i +1 , mi_cols, cols_log2); + offset = end - start; + tiles->mi_cols[i] = (offset +7 ) >>3 ; + } + +return 0 ; +} + +static void vdec_vp9_slice_setup_state (struct vdec_vp9_slice_vsi *vsi) +{ +memset (&vsi->state,0 ,sizeof (vsi->state)); +} + +static void vdec_vp9_slice_setup_ref_idx (struct vdec_vp9_slice_pfc *pfc, +struct v4l2_ctrl_vp9_frame *hdr) +{ + pfc->ref_idx[0 ] = hdr->last_frame_ts; + pfc->ref_idx[1 ] = hdr->golden_frame_ts; + pfc->ref_idx[2 ] = hdr->alt_frame_ts; +} + +static int vdec_vp9_slice_setup_pfc (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_pfc *pfc) +{ +struct v4l2_ctrl_vp9_frame *hdr; +struct vdec_vp9_slice_uncompressed_header *uh; +struct v4l2_ctrl *hdr_ctrl; +struct vdec_vp9_slice_vsi *vsi; +int ret; + +/* frame header */ + hdr_ctrl =v4l2_ctrl_find (&instance->ctx->ctrl_hdl,V4L2_CID_STATELESS_VP9_FRAME ); +if (!hdr_ctrl || !hdr_ctrl->p_cur.p) +return -EINVAL ; + + hdr = hdr_ctrl->p_cur.p; + vsi = &pfc->vsi; + uh = &vsi->frame.uh; + +/* setup vsi information */ +vdec_vp9_slice_setup_hdr (instance, uh, hdr); +vdec_vp9_slice_setup_frame_ctx (instance, uh, hdr); +vdec_vp9_slice_setup_loop_filter (uh, &hdr->lf); +vdec_vp9_slice_setup_quantization (uh, &hdr->quant); +vdec_vp9_slice_setup_segmentation (uh, &hdr->seg); + ret =vdec_vp9_slice_setup_tile (vsi, hdr); +if (ret) +return ret; +vdec_vp9_slice_setup_state (vsi); + +/* core stage needs buffer index to get ref y/c ... */ +vdec_vp9_slice_setup_ref_idx (pfc, hdr); + + pfc->seq = instance->seq; + instance->seq++; + +return 0 ; +} + +static int vdec_vp9_slice_setup_lat_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi, +struct mtk_vcodec_mem *bs, +struct vdec_lat_buf *lat_buf) +{ +int i; + + vsi->bs.buf.dma_addr = bs->dma_addr; + vsi->bs.buf.size = bs->size; + vsi->bs.frame.dma_addr = bs->dma_addr; + vsi->bs.frame.size = bs->size; + +for (i =0 ; i <2 ; i++) { + vsi->mv[i].dma_addr = instance->mv[i].dma_addr; + vsi->mv[i].size = instance->mv[i].size; + } +for (i =0 ; i <2 ; i++) { + vsi->seg[i].dma_addr = instance->seg[i].dma_addr; + vsi->seg[i].size = instance->seg[i].size; + } + vsi->tile.dma_addr = instance->tile.dma_addr; + vsi->tile.size = instance->tile.size; + vsi->prob.dma_addr = instance->prob.dma_addr; + vsi->prob.size = instance->prob.size; + vsi->counts.dma_addr = instance->counts.dma_addr; + vsi->counts.size = instance->counts.size; + + vsi->ube.dma_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr; + vsi->ube.size = lat_buf->ctx->msg_queue.wdma_addr.size; + vsi->trans.dma_addr = lat_buf->ctx->msg_queue.wdma_wptr_addr; +/* used to store trans end */ + vsi->trans.dma_addr_end = lat_buf->ctx->msg_queue.wdma_rptr_addr; + vsi->err_map.dma_addr = lat_buf->wdma_err_addr.dma_addr; + vsi->err_map.size = lat_buf->wdma_err_addr.size; + + vsi->row_info.buf =0 ; + vsi->row_info.size =0 ; + +return 0 ; +} + +static int vdec_vp9_slice_setup_prob_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi) +{ +struct vdec_vp9_slice_frame_ctx *frame_ctx; +struct vdec_vp9_slice_uncompressed_header *uh; + + uh = &vsi->frame.uh; + +mtk_vcodec_debug (instance,"ctx dirty %u idx %d\n" , + instance->dirty[uh->frame_context_idx], + uh->frame_context_idx); + +if (instance->dirty[uh->frame_context_idx]) + frame_ctx = &instance->frame_ctx[uh->frame_context_idx]; +else + frame_ctx = vdec_vp9_slice_default_frame_ctx; +memcpy (instance->prob.va, frame_ctx,sizeof (*frame_ctx)); + +return 0 ; +} + +static void vdec_vp9_slice_setup_seg_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi, +struct mtk_vcodec_mem *buf) +{ +struct vdec_vp9_slice_uncompressed_header *uh; + +/* reset segment buffer */ + uh = &vsi->frame.uh; +if (uh->frame_type ==0 || + uh->intra_only || + uh->error_resilient_mode || + uh->frame_width != instance->width || + uh->frame_height != instance->height) { +mtk_vcodec_debug (instance,"reset seg\n" ); +memset (buf->va,0 , buf->size); + } +} + +/* +* parse tiles according to `6.4 Decode tiles syntax` +* in "vp9-bitstream-specification" +* +* frame contains uncompress header, compressed header and several tiles. +* this function parses tiles' position and size, stores them to tile buffer +* for decoding. +*/ +static int vdec_vp9_slice_setup_tile_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi, +struct mtk_vcodec_mem *bs) +{ +struct vdec_vp9_slice_uncompressed_header *uh; +unsigned int rows_log2; +unsigned int cols_log2; +unsigned int rows; +unsigned int cols; +unsigned int mi_row; +unsigned int mi_col; +unsigned int offset; +unsigned int pa; +unsigned int size; +struct vdec_vp9_slice_tiles *tiles; +unsigned char *pos; +unsigned char *end; +unsigned char *va; +unsigned int *tb; +int i; +int j; + + uh = &vsi->frame.uh; + rows_log2 = uh->tile_rows_log2; + cols_log2 = uh->tile_cols_log2; + rows =1 << rows_log2; + cols =1 << cols_log2; + +if (rows >4 || cols >64 ) { +mtk_vcodec_err (instance,"tile_rows %u tile_cols %u\n" , + rows, cols); +return -EINVAL ; + } + + offset = uh->uncompressed_header_size + + uh->header_size_in_bytes; +if (bs->size <= offset) { +mtk_vcodec_err (instance,"bs size %zu tile offset %u\n" , + bs->size, offset); +return -EINVAL ; + } + + tiles = &vsi->frame.tiles; +/* setup tile buffer */ + + va = (unsigned char *)bs->va; + pos = va + offset; + end = va + bs->size; +/* truncated */ + pa = (unsigned int )bs->dma_addr + offset; + tb = instance->tile.va; +for (i =0 ; i < rows; i++) { +for (j =0 ; j < cols; j++) { +if (i == rows -1 && + j == cols -1 ) { + size = (unsigned int )(end - pos); + }else { +if (end - pos <4 ) +return -EINVAL ; + + size = (pos[0 ] <<24 ) | (pos[1 ] <<16 ) | + (pos[2 ] <<8 ) | pos[3 ]; + pos +=4 ; + pa +=4 ; + offset +=4 ; +if (end - pos < size) +return -EINVAL ; + } + tiles->size[i][j] = size; +if (tiles->mi_rows[i]) { + *tb++ = (size <<3 ) + ((offset <<3 ) &0x7f ); + *tb++ = pa & ~0xf ; + *tb++ = (pa <<3 ) &0x7f ; + mi_row = (tiles->mi_rows[i] -1 ) &0x1ff ; + mi_col = (tiles->mi_cols[j] -1 ) &0x3f ; + *tb++ = (mi_row <<6 ) + mi_col; + } + pos += size; + pa += size; + offset += size; + } + } + +return 0 ; +} + +static int vdec_vp9_slice_setup_lat (struct vdec_vp9_slice_instance *instance, +struct mtk_vcodec_mem *bs, +struct vdec_lat_buf *lat_buf, +struct vdec_vp9_slice_pfc *pfc) +{ +struct vdec_vp9_slice_vsi *vsi = &pfc->vsi; +int ret; + + ret =vdec_vp9_slice_setup_lat_from_src_buf (instance, lat_buf); +if (ret) + goto err; + + ret =vdec_vp9_slice_setup_pfc (instance, pfc); +if (ret) + goto err; + + ret =vdec_vp9_slice_alloc_working_buffer (instance, vsi); +if (ret) + goto err; + + ret =vdec_vp9_slice_setup_lat_buffer (instance, vsi, bs, lat_buf); +if (ret) + goto err; + +vdec_vp9_slice_setup_seg_buffer (instance, vsi, &instance->seg[0 ]); + +/* setup prob/tile buffers for LAT */ + + ret =vdec_vp9_slice_setup_prob_buffer (instance, vsi); +if (ret) + goto err; + + ret =vdec_vp9_slice_setup_tile_buffer (instance, vsi, bs); +if (ret) + goto err; + +return 0 ; + +err: +return ret; +} + +static +void vdec_vp9_slice_map_counts_eob_coef (unsigned int i,unsigned int j,unsigned int k, +struct vdec_vp9_slice_frame_counts *counts, +struct v4l2_vp9_frame_symbol_counts *counts_helper) +{ +u32 l, m; + +/* +* helper eo -> mtk eo +* helpre e1 -> mtk c3 +* helper c0 -> c0 +* helper c1 -> c1 +* helper c2 -> c2 +*/ +for (l =0 ; l <6 ; l++) { +for (m =0 ; m <VP9_BAND_6 (l); m++) { +if (l ==0 ) { + counts_helper->coeff[i][j][k][l][m] = + &counts->coef_probs[i][j][k].band_0[m]; + counts_helper->eob[i][j][k][l][m][0 ] = + &counts->eob_branch[i][j][k].band_0[m]; + counts_helper->eob[i][j][k][l][m][1 ] = + &counts->coef_probs[i][j][k].band_0[m][3 ]; + }else { + counts_helper->coeff[i][j][k][l][m] = + &counts->coef_probs[i][j][k].band_1_5[l -1 ][m]; + counts_helper->eob[i][j][k][l][m][0 ] = + &counts->eob_branch[i][j][k].band_1_5[l -1 ][m]; + counts_helper->eob[i][j][k][l][m][1 ] = + &counts->coef_probs[i][j][k].band_1_5[l -1 ][m][3 ]; + } + } + } +} + +static void vdec_vp9_slice_counts_map_helper (struct vdec_vp9_slice_counts_map *counts_map, +struct vdec_vp9_slice_frame_counts *counts, +struct v4l2_vp9_frame_symbol_counts *counts_helper) +{ +int i, j, k, l, m; + + counts_helper->partition = &counts->partition; + counts_helper->intra_inter = &counts->intra_inter; + counts_helper->tx32p = &counts->tx_p32x32; + counts_helper->tx16p = &counts->tx_p16x16; + counts_helper->tx8p = &counts->tx_p8x8; + counts_helper->uv_mode = &counts->uv_mode; + + counts_helper->comp = &counts->comp_inter; + counts_helper->comp_ref = &counts->comp_ref; + counts_helper->single_ref = &counts->single_ref; + counts_helper->mv_mode = &counts->inter_mode; + counts_helper->mv_joint = &counts->joint; + +for (i =0 ; i <ARRAY_SIZE (counts_map->skip); i++) +memcpy (counts_map->skip[i], counts->skip[i], +sizeof (counts_map->skip[0 ])); + counts_helper->skip = &counts_map->skip; + +for (i =0 ; i <ARRAY_SIZE (counts_map->y_mode); i++) +memcpy (counts_map->y_mode[i], counts->y_mode[i], +sizeof (counts_map->y_mode[0 ])); + counts_helper->y_mode = &counts_map->y_mode; + +for (i =0 ; i <ARRAY_SIZE (counts_map->filter); i++) +memcpy (counts_map->filter[i], counts->switchable_interp[i], +sizeof (counts_map->filter[0 ])); + counts_helper->filter = &counts_map->filter; + +for (i =0 ; i <ARRAY_SIZE (counts_map->sign); i++) +memcpy (counts_map->sign[i], counts->mvcomp[i].sign, +sizeof (counts_map->sign[0 ])); + counts_helper->sign = &counts_map->sign; + +for (i =0 ; i <ARRAY_SIZE (counts_map->classes); i++) +memcpy (counts_map->classes[i], counts->mvcomp[i].classes, +sizeof (counts_map->classes[0 ])); + counts_helper->classes = &counts_map->classes; + +for (i =0 ; i <ARRAY_SIZE (counts_map->class0); i++) +memcpy (counts_map->class0[i], counts->mvcomp[i].class0, +sizeof (counts_map->class0[0 ])); + counts_helper->class0 = &counts_map->class0; + +for (i =0 ; i <ARRAY_SIZE (counts_map->bits); i++) +for (j =0 ; j <ARRAY_SIZE (counts_map->bits[0 ]); j++) +memcpy (counts_map->bits[i][j], counts->mvcomp[i].bits[j], +sizeof (counts_map->bits[0 ][0 ])); + counts_helper->bits = &counts_map->bits; + +for (i =0 ; i <ARRAY_SIZE (counts_map->class0_fp); i++) +for (j =0 ; j <ARRAY_SIZE (counts_map->class0_fp[0 ]); j++) +memcpy (counts_map->class0_fp[i][j], counts->mvcomp[i].class0_fp[j], +sizeof (counts_map->class0_fp[0 ][0 ])); + counts_helper->class0_fp = &counts_map->class0_fp; + +for (i =0 ; i <ARRAY_SIZE (counts_map->fp); i++) +memcpy (counts_map->fp[i], counts->mvcomp[i].fp, +sizeof (counts_map->fp[0 ])); + counts_helper->fp = &counts_map->fp; + +for (i =0 ; i <ARRAY_SIZE (counts_map->class0_hp); i++) +memcpy (counts_map->class0_hp[i], counts->mvcomp[i].class0_hp, +sizeof (counts_map->class0_hp[0 ])); + counts_helper->class0_hp = &counts_map->class0_hp; + +for (i =0 ; i <ARRAY_SIZE (counts_map->hp); i++) +memcpy (counts_map->hp[i], counts->mvcomp[i].hp,sizeof (counts_map->hp[0 ])); + + counts_helper->hp = &counts_map->hp; + +for (i =0 ; i <4 ; i++) +for (j =0 ; j <2 ; j++) +for (k =0 ; k <2 ; k++) +vdec_vp9_slice_map_counts_eob_coef (i, j, k, counts, counts_helper); +} + +static void vdec_vp9_slice_map_to_coef (unsigned int i,unsigned int j,unsigned int k, +struct vdec_vp9_slice_frame_ctx *frame_ctx, +struct v4l2_vp9_frame_context *frame_ctx_helper) +{ +u32 l, m; + +for (l =0 ; l <ARRAY_SIZE (frame_ctx_helper->coef[0 ][0 ][0 ]); l++) { +for (m =0 ; m <VP9_BAND_6 (l); m++) { +memcpy (frame_ctx_helper->coef[i][j][k][l][m], + frame_ctx->coef_probs[i][j][k][l].probs[m], +sizeof (frame_ctx_helper->coef[i][j][k][l][0 ])); + } + } +} + +static void vdec_vp9_slice_map_from_coef (unsigned int i,unsigned int j,unsigned int k, +struct vdec_vp9_slice_frame_ctx *frame_ctx, +struct v4l2_vp9_frame_context *frame_ctx_helper) +{ +u32 l, m; + +for (l =0 ; l <ARRAY_SIZE (frame_ctx_helper->coef[0 ][0 ][0 ]); l++) { +for (m =0 ; m <VP9_BAND_6 (l); m++) { +memcpy (frame_ctx->coef_probs[i][j][k][l].probs[m], + frame_ctx_helper->coef[i][j][k][l][m], +sizeof (frame_ctx_helper->coef[i][j][k][l][0 ])); + } + } +} + +static +void vdec_vp9_slice_framectx_map_helper (bool frame_is_intra, +struct vdec_vp9_slice_frame_ctx *pre_frame_ctx, +struct vdec_vp9_slice_frame_ctx *frame_ctx, +struct v4l2_vp9_frame_context *frame_ctx_helper) +{ +struct v4l2_vp9_frame_mv_context *mv = &frame_ctx_helper->mv; +u32 i, j, k; + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->coef); i++) +for (j =0 ; j <ARRAY_SIZE (frame_ctx_helper->coef[0 ]); j++) +for (k =0 ; k <ARRAY_SIZE (frame_ctx_helper->coef[0 ][0 ]); k++) +vdec_vp9_slice_map_to_coef (i, j, k, pre_frame_ctx, + frame_ctx_helper); + +/* +* use previous prob when frame is not intra or +* we should use the prob updated by the compressed header parse +*/ +if (!frame_is_intra) + frame_ctx = pre_frame_ctx; + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx8); i++) +memcpy (frame_ctx_helper->tx8[i], frame_ctx->tx_p8x8[i], +sizeof (frame_ctx_helper->tx8[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx16); i++) +memcpy (frame_ctx_helper->tx16[i], frame_ctx->tx_p16x16[i], +sizeof (frame_ctx_helper->tx16[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx32); i++) +memcpy (frame_ctx_helper->tx32[i], frame_ctx->tx_p32x32[i], +sizeof (frame_ctx_helper->tx32[0 ])); + +memcpy (frame_ctx_helper->skip, frame_ctx->skip_probs,sizeof (frame_ctx_helper->skip)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->inter_mode); i++) +memcpy (frame_ctx_helper->inter_mode[i], frame_ctx->inter_mode_probs[i], +sizeof (frame_ctx_helper->inter_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->interp_filter); i++) +memcpy (frame_ctx_helper->interp_filter[i], frame_ctx->switch_interp_prob[i], +sizeof (frame_ctx_helper->interp_filter[0 ])); + +memcpy (frame_ctx_helper->is_inter, frame_ctx->intra_inter_prob, +sizeof (frame_ctx_helper->is_inter)); + +memcpy (frame_ctx_helper->comp_mode, frame_ctx->comp_inter_prob, +sizeof (frame_ctx_helper->comp_mode)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->single_ref); i++) +memcpy (frame_ctx_helper->single_ref[i], frame_ctx->single_ref_prob[i], +sizeof (frame_ctx_helper->single_ref[0 ])); + +memcpy (frame_ctx_helper->comp_ref, frame_ctx->comp_ref_prob, +sizeof (frame_ctx_helper->comp_ref)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->y_mode); i++) +memcpy (frame_ctx_helper->y_mode[i], frame_ctx->y_mode_prob[i], +sizeof (frame_ctx_helper->y_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->uv_mode); i++) +memcpy (frame_ctx_helper->uv_mode[i], frame_ctx->uv_mode_prob[i], +sizeof (frame_ctx_helper->uv_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->partition); i++) +memcpy (frame_ctx_helper->partition[i], frame_ctx->partition_prob[i], +sizeof (frame_ctx_helper->partition[0 ])); + +memcpy (mv->joint, frame_ctx->joint,sizeof (mv->joint)); + +for (i =0 ; i <ARRAY_SIZE (mv->sign); i++) + mv->sign[i] = frame_ctx->sign_classes[i].sign; + +for (i =0 ; i <ARRAY_SIZE (mv->classes); i++) +memcpy (mv->classes[i], frame_ctx->sign_classes[i].classes, +sizeof (mv->classes[i])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_bit); i++) + mv->class0_bit[i] = frame_ctx->class0_bits[i].class0[0 ]; + +for (i =0 ; i <ARRAY_SIZE (mv->bits); i++) +memcpy (mv->bits[i], frame_ctx->class0_bits[i].bits,sizeof (mv->bits[0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_fr); i++) +for (j =0 ; j <ARRAY_SIZE (mv->class0_fr[0 ]); j++) +memcpy (mv->class0_fr[i][j], frame_ctx->class0_fp_hp[i].class0_fp[j], +sizeof (mv->class0_fr[0 ][0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->fr); i++) +memcpy (mv->fr[i], frame_ctx->class0_fp_hp[i].fp,sizeof (mv->fr[0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_hp); i++) + mv->class0_hp[i] = frame_ctx->class0_fp_hp[i].class0_hp; + +for (i =0 ; i <ARRAY_SIZE (mv->hp); i++) + mv->hp[i] = frame_ctx->class0_fp_hp[i].hp; +} + +static void vdec_vp9_slice_helper_map_framectx (struct v4l2_vp9_frame_context *frame_ctx_helper, +struct vdec_vp9_slice_frame_ctx *frame_ctx) +{ +struct v4l2_vp9_frame_mv_context *mv = &frame_ctx_helper->mv; +u32 i, j, k; + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx8); i++) +memcpy (frame_ctx->tx_p8x8[i], frame_ctx_helper->tx8[i], +sizeof (frame_ctx_helper->tx8[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx16); i++) +memcpy (frame_ctx->tx_p16x16[i], frame_ctx_helper->tx16[i], +sizeof (frame_ctx_helper->tx16[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx32); i++) +memcpy (frame_ctx->tx_p32x32[i], frame_ctx_helper->tx32[i], +sizeof (frame_ctx_helper->tx32[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->coef); i++) +for (j =0 ; j <ARRAY_SIZE (frame_ctx_helper->coef[0 ]); j++) +for (k =0 ; k <ARRAY_SIZE (frame_ctx_helper->coef[0 ][0 ]); k++) +vdec_vp9_slice_map_from_coef (i, j, k, frame_ctx, + frame_ctx_helper); + +memcpy (frame_ctx->skip_probs, frame_ctx_helper->skip,sizeof (frame_ctx_helper->skip)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->inter_mode); i++) +memcpy (frame_ctx->inter_mode_probs[i], frame_ctx_helper->inter_mode[i], +sizeof (frame_ctx_helper->inter_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->interp_filter); i++) +memcpy (frame_ctx->switch_interp_prob[i], frame_ctx_helper->interp_filter[i], +sizeof (frame_ctx_helper->interp_filter[0 ])); + +memcpy (frame_ctx->intra_inter_prob, frame_ctx_helper->is_inter, +sizeof (frame_ctx_helper->is_inter)); + +memcpy (frame_ctx->comp_inter_prob, frame_ctx_helper->comp_mode, +sizeof (frame_ctx_helper->comp_mode)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->single_ref); i++) +memcpy (frame_ctx->single_ref_prob[i], frame_ctx_helper->single_ref[i], +sizeof (frame_ctx_helper->single_ref[0 ])); + +memcpy (frame_ctx->comp_ref_prob, frame_ctx_helper->comp_ref, +sizeof (frame_ctx_helper->comp_ref)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->y_mode); i++) +memcpy (frame_ctx->y_mode_prob[i], frame_ctx_helper->y_mode[i], +sizeof (frame_ctx_helper->y_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->uv_mode); i++) +memcpy (frame_ctx->uv_mode_prob[i], frame_ctx_helper->uv_mode[i], +sizeof (frame_ctx_helper->uv_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->partition); i++) +memcpy (frame_ctx->partition_prob[i], frame_ctx_helper->partition[i], +sizeof (frame_ctx_helper->partition[0 ])); + +memcpy (frame_ctx->joint, mv->joint,sizeof (mv->joint)); + +for (i =0 ; i <ARRAY_SIZE (mv->sign); i++) + frame_ctx->sign_classes[i].sign = mv->sign[i]; + +for (i =0 ; i <ARRAY_SIZE (mv->classes); i++) +memcpy (frame_ctx->sign_classes[i].classes, mv->classes[i], +sizeof (mv->classes[i])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_bit); i++) + frame_ctx->class0_bits[i].class0[0 ] = mv->class0_bit[i]; + +for (i =0 ; i <ARRAY_SIZE (mv->bits); i++) +memcpy (frame_ctx->class0_bits[i].bits, mv->bits[i],sizeof (mv->bits[0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_fr); i++) +for (j =0 ; j <ARRAY_SIZE (mv->class0_fr[0 ]); j++) +memcpy (frame_ctx->class0_fp_hp[i].class0_fp[j], mv->class0_fr[i][j], +sizeof (mv->class0_fr[0 ][0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->fr); i++) +memcpy (frame_ctx->class0_fp_hp[i].fp, mv->fr[i],sizeof (mv->fr[0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_hp); i++) + frame_ctx->class0_fp_hp[i].class0_hp = mv->class0_hp[i]; + +for (i =0 ; i <ARRAY_SIZE (mv->hp); i++) + frame_ctx->class0_fp_hp[i].hp = mv->hp[i]; +} + +static int vdec_vp9_slice_update_prob (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi) +{ +struct vdec_vp9_slice_frame_ctx *pre_frame_ctx; +struct v4l2_vp9_frame_context *pre_frame_ctx_helper; +struct vdec_vp9_slice_frame_ctx *frame_ctx; +struct vdec_vp9_slice_frame_counts *counts; +struct v4l2_vp9_frame_symbol_counts *counts_helper; +struct vdec_vp9_slice_uncompressed_header *uh; +bool frame_is_intra; +bool use_128; + + uh = &vsi->frame.uh; + pre_frame_ctx = &instance->frame_ctx[uh->frame_context_idx]; + pre_frame_ctx_helper = &instance->frame_ctx_helper; + frame_ctx = (struct vdec_vp9_slice_frame_ctx *)instance->prob.va; + counts = (struct vdec_vp9_slice_frame_counts *)instance->counts.va; + counts_helper = &instance->counts_helper; + +if (!uh->refresh_frame_context) +return 0 ; + +if (!uh->frame_parallel_decoding_mode) { +vdec_vp9_slice_counts_map_helper (&instance->counts_map, counts, counts_helper); + + frame_is_intra = !vsi->frame.uh.frame_type || vsi->frame.uh.intra_only; +/* check default prob */ +if (!instance->dirty[uh->frame_context_idx]) +vdec_vp9_slice_framectx_map_helper (frame_is_intra, + vdec_vp9_slice_default_frame_ctx, + frame_ctx, + pre_frame_ctx_helper); +else +vdec_vp9_slice_framectx_map_helper (frame_is_intra, + pre_frame_ctx, + frame_ctx, + pre_frame_ctx_helper); + + use_128 = !frame_is_intra && !vsi->frame.uh.last_frame_type; +v4l2_vp9_adapt_coef_probs (pre_frame_ctx_helper, + counts_helper, + use_128, + frame_is_intra); +if (!frame_is_intra) +v4l2_vp9_adapt_noncoef_probs (pre_frame_ctx_helper, + counts_helper, +V4L2_VP9_REFERENCE_MODE_SINGLE_REFERENCE , + vsi->frame.uh.interpolation_filter, + vsi->frame.ch.tx_mode, + vsi->frame.uh.allow_high_precision_mv ? +V4L2_VP9_FRAME_FLAG_ALLOW_HIGH_PREC_MV :0 ); +vdec_vp9_slice_helper_map_framectx (pre_frame_ctx_helper, pre_frame_ctx); + }else { +memcpy (pre_frame_ctx, frame_ctx,sizeof (*frame_ctx)); + } + + instance->dirty[uh->frame_context_idx] =1 ; + +return 0 ; +} + +static int vdec_vp9_slice_update_lat (struct vdec_vp9_slice_instance *instance, +struct vdec_lat_buf *lat_buf, +struct vdec_vp9_slice_pfc *pfc) +{ +struct vdec_vp9_slice_vsi *vsi; + + vsi = &pfc->vsi; +memcpy (&pfc->state[0 ], &vsi->state,sizeof (vsi->state)); + +mtk_vcodec_debug (instance,"Frame %u LAT CRC 0x%08x %lx %lx\n" , + pfc->seq, vsi->state.crc[0 ], + (unsigned long )vsi->trans.dma_addr, + (unsigned long )vsi->trans.dma_addr_end); + +/* buffer full, need to re-decode */ +if (vsi->state.full) { +/* buffer not enough */ +if (vsi->trans.dma_addr_end - vsi->trans.dma_addr == + vsi->ube.size) +return -ENOMEM ; +return -EAGAIN ; + } + +vdec_vp9_slice_update_prob (instance, vsi); + + instance->width = vsi->frame.uh.frame_width; + instance->height = vsi->frame.uh.frame_height; + instance->frame_type = vsi->frame.uh.frame_type; + instance->show_frame = vsi->frame.uh.show_frame; + +return 0 ; +} + +static int vdec_vp9_slice_setup_core_to_dst_buf (struct vdec_vp9_slice_instance *instance, +struct vdec_lat_buf *lat_buf) +{ +struct vb2_v4l2_buffer *dst; + + dst =v4l2_m2m_next_dst_buf (instance->ctx->m2m_ctx); +if (!dst) +return -EINVAL ; + +v4l2_m2m_buf_copy_metadata (&lat_buf->ts_info, dst, true); +return 0 ; +} + +static int vdec_vp9_slice_setup_core_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_pfc *pfc, +struct vdec_vp9_slice_vsi *vsi, +struct vdec_fb *fb, +struct vdec_lat_buf *lat_buf) +{ +struct vb2_buffer *vb; +struct vb2_queue *vq; +struct vdec_vp9_slice_reference *ref; +int plane; +int size; +int idx; +int w; +int h; +int i; + + plane = instance->ctx->q_data[MTK_Q_DATA_DST ].fmt->num_planes; + w = vsi->frame.uh.frame_width; + h = vsi->frame.uh.frame_height; + size =ALIGN (w,64 ) *ALIGN (h,64 ); + +/* frame buffer */ + vsi->fb.y.dma_addr = fb->base_y.dma_addr; +if (plane ==1 ) + vsi->fb.c.dma_addr = fb->base_y.dma_addr + size; +else + vsi->fb.c.dma_addr = fb->base_c.dma_addr; + +/* reference buffers */ + vq =v4l2_m2m_get_vq (instance->ctx->m2m_ctx, +V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ); +if (!vq) +return -EINVAL ; + +/* get current output buffer */ + vb = &v4l2_m2m_next_dst_buf (instance->ctx->m2m_ctx)->vb2_buf; +if (!vb) +return -EINVAL ; + +/* update internal buffer's width/height */ +for (i =0 ; i < vq->num_buffers; i++) { +if (vb == vq->bufs[i]) { + instance->dpb[i].width = w; + instance->dpb[i].height = h; +break ; + } + } + +/* +* get buffer's width/height from instance +* get buffer address from vb2buf +*/ +for (i =0 ; i <3 ; i++) { + ref = &vsi->frame.ref[i]; + idx =vb2_find_timestamp (vq, pfc->ref_idx[i],0 ); +if (idx <0 ) { + ref->frame_width = w; + ref->frame_height = h; +memset (&vsi->ref[i],0 ,sizeof (vsi->ref[i])); + }else { + ref->frame_width = instance->dpb[idx].width; + ref->frame_height = instance->dpb[idx].height; + vb = vq->bufs[idx]; + vsi->ref[i].y.dma_addr = +vb2_dma_contig_plane_dma_addr (vb,0 ); +if (plane ==1 ) + vsi->ref[i].c.dma_addr = + vsi->ref[i].y.dma_addr + size; +else + vsi->ref[i].c.dma_addr = +vb2_dma_contig_plane_dma_addr (vb,1 ); + } + } + +return 0 ; +} + +static int vdec_vp9_slice_setup_core (struct vdec_vp9_slice_instance *instance, +struct vdec_fb *fb, +struct vdec_lat_buf *lat_buf, +struct vdec_vp9_slice_pfc *pfc) +{ +struct vdec_vp9_slice_vsi *vsi = &pfc->vsi; +int ret; + +vdec_vp9_slice_setup_state (vsi); + + ret =vdec_vp9_slice_setup_core_to_dst_buf (instance, lat_buf); +if (ret) + goto err; + + ret =vdec_vp9_slice_setup_core_buffer (instance, pfc, vsi, fb, lat_buf); +if (ret) + goto err; + +vdec_vp9_slice_setup_seg_buffer (instance, vsi, &instance->seg[1 ]); + +return 0 ; + +err: +return ret; +} + +static int vdec_vp9_slice_update_core (struct vdec_vp9_slice_instance *instance, +struct vdec_lat_buf *lat_buf, +struct vdec_vp9_slice_pfc *pfc) +{ +struct vdec_vp9_slice_vsi *vsi; + + vsi = &pfc->vsi; +memcpy (&pfc->state[1 ], &vsi->state,sizeof (vsi->state)); + +mtk_vcodec_debug (instance,"Frame %u Y_CRC %08x %08x %08x %08x\n" , + pfc->seq, + vsi->state.crc[0 ], vsi->state.crc[1 ], + vsi->state.crc[2 ], vsi->state.crc[3 ]); +mtk_vcodec_debug (instance,"Frame %u C_CRC %08x %08x %08x %08x\n" , + pfc->seq, + vsi->state.crc[4 ], vsi->state.crc[5 ], + vsi->state.crc[6 ], vsi->state.crc[7 ]); + +return 0 ; +} + +static int vdec_vp9_slice_init (struct mtk_vcodec_ctx *ctx) +{ +struct vdec_vp9_slice_instance *instance; +struct vdec_vp9_slice_init_vsi *vsi; +int ret; + + instance =kzalloc (sizeof (*instance),GFP_KERNEL ); +if (!instance) +return -ENOMEM ; + + instance->ctx = ctx; + instance->vpu.id =SCP_IPI_VDEC_LAT ; + instance->vpu.core_id =SCP_IPI_VDEC_CORE ; + instance->vpu.ctx = ctx; + instance->vpu.codec_type = ctx->current_codec; + + ret =vpu_dec_init (&instance->vpu); +if (ret) { +mtk_vcodec_err (instance,"failed to init vpu dec, ret %d\n" , ret); + goto error_vpu_init; + } + +/* init vsi and global flags */ + + vsi = instance->vpu.vsi; +if (!vsi) { +mtk_vcodec_err (instance,"failed to get VP9 vsi\n" ); + ret = -EINVAL ; + goto error_vsi; + } + instance->init_vsi = vsi; + instance->core_vsi =mtk_vcodec_fw_map_dm_addr (ctx->dev->fw_handler, + (u32 )vsi->core_vsi); +if (!instance->core_vsi) { +mtk_vcodec_err (instance,"failed to get VP9 core vsi\n" ); + ret = -EINVAL ; + goto error_vsi; + } + + instance->irq =1 ; + + ret =vdec_vp9_slice_init_default_frame_ctx (instance); +if (ret) + goto error_default_frame_ctx; + + ctx->drv_handle = instance; + +return 0 ; + +error_default_frame_ctx: +error_vsi: +vpu_dec_deinit (&instance->vpu); +error_vpu_init: +kfree (instance); +return ret; +} + +static void vdec_vp9_slice_deinit (void *h_vdec) +{ +struct vdec_vp9_slice_instance *instance = h_vdec; + +if (!instance) +return ; + +vpu_dec_deinit (&instance->vpu); +vdec_vp9_slice_free_working_buffer (instance); +vdec_msg_queue_deinit (&instance->ctx->msg_queue, instance->ctx); +kfree (instance); +} + +static int vdec_vp9_slice_flush (void *h_vdec,struct mtk_vcodec_mem *bs, +struct vdec_fb *fb,bool *res_chg) +{ +struct vdec_vp9_slice_instance *instance = h_vdec; + +mtk_vcodec_debug (instance,"flush ...\n" ); + +vdec_msg_queue_wait_lat_buf_full (&instance->ctx->msg_queue); +return vpu_dec_reset (&instance->vpu); +} + +static void vdec_vp9_slice_get_pic_info (struct vdec_vp9_slice_instance *instance) +{ +struct mtk_vcodec_ctx *ctx = instance->ctx; +unsigned int data[3 ]; + +mtk_vcodec_debug (instance,"w %u h %u\n" , + ctx->picinfo.pic_w, ctx->picinfo.pic_h); + + data[0 ] = ctx->picinfo.pic_w; + data[1 ] = ctx->picinfo.pic_h; + data[2 ] = ctx->capture_fourcc; +vpu_dec_get_param (&instance->vpu, data,3 ,GET_PARAM_PIC_INFO ); + + ctx->picinfo.buf_w =ALIGN (ctx->picinfo.pic_w,64 ); + ctx->picinfo.buf_h =ALIGN (ctx->picinfo.pic_h,64 ); + ctx->picinfo.fb_sz[0 ] = instance->vpu.fb_sz[0 ]; + ctx->picinfo.fb_sz[1 ] = instance->vpu.fb_sz[1 ]; +} + +static void vdec_vp9_slice_get_dpb_size (struct vdec_vp9_slice_instance *instance, +unsigned int *dpb_sz) +{ +/* refer VP9 specification */ + *dpb_sz =9 ; +} + +static int vdec_vp9_slice_get_param (void *h_vdec,enum vdec_get_param_type type,void *out) +{ +struct vdec_vp9_slice_instance *instance = h_vdec; + +switch (type) { +case GET_PARAM_PIC_INFO : +vdec_vp9_slice_get_pic_info (instance); +break ; +case GET_PARAM_DPB_SIZE : +vdec_vp9_slice_get_dpb_size (instance, out); +break ; +case GET_PARAM_CROP_INFO : +mtk_vcodec_debug (instance,"No need to get vp9 crop information." ); +break ; +default : +mtk_vcodec_err (instance,"invalid get parameter type=%d\n" , + type); +return -EINVAL ; + } + +return 0 ; +} + +static int vdec_vp9_slice_lat_decode (void *h_vdec,struct mtk_vcodec_mem *bs, +struct vdec_fb *fb,bool *res_chg) +{ +struct vdec_vp9_slice_instance *instance = h_vdec; +struct vdec_lat_buf *lat_buf; +struct vdec_vp9_slice_pfc *pfc; +struct vdec_vp9_slice_vsi *vsi; +struct mtk_vcodec_ctx *ctx; +int ret; + +if (!instance || !instance->ctx) +return -EINVAL ; + ctx = instance->ctx; + +/* init msgQ for the first time */ +if (vdec_msg_queue_init (&ctx->msg_queue, ctx, + vdec_vp9_slice_core_decode, +sizeof (*pfc))) +return -ENOMEM ; + +/* bs NULL means flush decoder */ +if (!bs) +return vdec_vp9_slice_flush (h_vdec, bs, fb, res_chg); + + lat_buf =vdec_msg_queue_dqbuf (&instance->ctx->msg_queue.lat_ctx); +if (!lat_buf) { +mtk_vcodec_err (instance,"Failed to get VP9 lat buf\n" ); +return -EBUSY ; + } + pfc = (struct vdec_vp9_slice_pfc *)lat_buf->private_data; +if (!pfc) +return -EINVAL ; + vsi = &pfc->vsi; + + ret =vdec_vp9_slice_setup_lat (instance, bs, lat_buf, pfc); +if (ret) { +mtk_vcodec_err (instance,"Failed to setup VP9 lat ret %d\n" , ret); +return ret; + } +vdec_vp9_slice_vsi_to_remote (vsi, instance->vsi); + + ret =vpu_dec_start (&instance->vpu,0 ,0 ); +if (ret) { +mtk_vcodec_err (instance,"Failed to dec VP9 ret %d\n" , ret); +return ret; + } + +if (instance->irq) { + ret =mtk_vcodec_wait_for_done_ctx (ctx,MTK_INST_IRQ_RECEIVED , +WAIT_INTR_TIMEOUT_MS ,MTK_VDEC_LAT0 ); +/* update remote vsi if decode timeout */ +if (ret) { +mtk_vcodec_err (instance,"VP9 decode timeout %d pic %d\n" , ret, pfc->seq); +writel (1 , &instance->vsi->state.timeout); + } +vpu_dec_end (&instance->vpu); + } + +vdec_vp9_slice_vsi_from_remote (vsi, instance->vsi,0 ); + ret =vdec_vp9_slice_update_lat (instance, lat_buf, pfc); + +/* LAT trans full, no more UBE or decode timeout */ +if (ret) { +mtk_vcodec_err (instance,"VP9 decode error: %d\n" , ret); +return ret; + } + +mtk_vcodec_debug (instance,"lat dma 1 0x%llx 0x%llx\n" , + pfc->vsi.trans.dma_addr, pfc->vsi.trans.dma_addr_end); + +vdec_msg_queue_update_ube_wptr (&ctx->msg_queue, + vsi->trans.dma_addr_end + + ctx->msg_queue.wdma_addr.dma_addr); +vdec_msg_queue_qbuf (&ctx->dev->msg_queue_core_ctx, lat_buf); + +return 0 ; +} + +static int vdec_vp9_slice_core_decode (struct vdec_lat_buf *lat_buf) +{ +struct vdec_vp9_slice_instance *instance; +struct vdec_vp9_slice_pfc *pfc; +struct mtk_vcodec_ctx *ctx =NULL ; +struct vdec_fb *fb =NULL ; +int ret = -EINVAL ; + +if (!lat_buf) + goto err; + + pfc = lat_buf->private_data; + ctx = lat_buf->ctx; +if (!pfc || !ctx) + goto err; + + instance = ctx->drv_handle; +if (!instance) + goto err; + + fb = ctx->dev->vdec_pdata->get_cap_buffer (ctx); +if (!fb) { + ret = -EBUSY ; + goto err; + } + + ret =vdec_vp9_slice_setup_core (instance, fb, lat_buf, pfc); +if (ret) { +mtk_vcodec_err (instance,"vdec_vp9_slice_setup_core\n" ); + goto err; + } +vdec_vp9_slice_vsi_to_remote (&pfc->vsi, instance->core_vsi); + + ret =vpu_dec_core (&instance->vpu); +if (ret) { +mtk_vcodec_err (instance,"vpu_dec_core\n" ); + goto err; + } + +if (instance->irq) { + ret =mtk_vcodec_wait_for_done_ctx (ctx,MTK_INST_IRQ_RECEIVED , +WAIT_INTR_TIMEOUT_MS ,MTK_VDEC_CORE ); +/* update remote vsi if decode timeout */ +if (ret) { +mtk_vcodec_err (instance,"VP9 core timeout pic %d\n" , pfc->seq); +writel (1 , &instance->core_vsi->state.timeout); + } +vpu_dec_core_end (&instance->vpu); + } + +vdec_vp9_slice_vsi_from_remote (&pfc->vsi, instance->core_vsi,1 ); + ret =vdec_vp9_slice_update_core (instance, lat_buf, pfc); +if (ret) { +mtk_vcodec_err (instance,"vdec_vp9_slice_update_core\n" ); + goto err; + } + + pfc->vsi.trans.dma_addr_end += ctx->msg_queue.wdma_addr.dma_addr; +mtk_vcodec_debug (instance,"core dma_addr_end 0x%llx\n" , 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); + +return 0 ; + +err: +if (ctx) { +/* always update read pointer */ +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); + } +return ret; +} + +const struct vdec_common_if vdec_vp9_slice_lat_if = { + .init = vdec_vp9_slice_init, + .decode = vdec_vp9_slice_lat_decode, + .get_param = vdec_vp9_slice_get_param, + .deinit = vdec_vp9_slice_deinit, +};drivers/media/platform/mediatek/vcodec/vdec_drv_if.c +4
-0@@ -45,6 +45,10 @@ int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc) ctx->dec_if = &vdec_vp9_if; ctx->hw_id =MTK_VDEC_CORE ;break ; +case V4L2_PIX_FMT_VP9_FRAME : + ctx->dec_if = &vdec_vp9_slice_lat_if; + ctx->hw_id =MTK_VDEC_LAT0 ; +break ;default :return -EINVAL ; }drivers/media/platform/mediatek/vcodec/vdec_drv_if.h +1
-0@@ -60,6 +60,7 @@ extern const struct vdec_common_if vdec_h264_slice_multi_if;extern const struct vdec_common_if vdec_vp8_if;extern const struct vdec_common_if vdec_vp8_slice_if;extern const struct vdec_common_if vdec_vp9_if; +extern const struct vdec_common_if vdec_vp9_slice_lat_if;/** * vdec_if_init() - initialize decode driver
Re: [PATCH v8, 16/17] media: mediatek: vcodec: support stateless VP9 decoding
Le mercredi 06 avril 2022 à 15:23 -0400, Nicolas Dufresne a écrit :
Quoted 16 lines
Hi Yunfei,
Le jeudi 31 mars 2022 à 10:48 +0800, Yunfei Dong a écrit :
Quoted 7 lines
Add support for VP9 decoding using the stateless API,
as supported by MT8192. And the drivers is lat and core architecture.Signed-off-by George Sun <[email protected]>Signed-off-by Xiaoyong Lu <[email protected]>Signed-off-by Yunfei Dong <[email protected]>Reviewed-by AngeloGioacchino Del Regno <[email protected]>Reviewed-by should be dropped when large rework happens. In this case, the probability updated has been rewritten to use the common code (thanks for porting it). Unfortunately, running fluster tests shows massive regression (was 275/303) before):
Quoted 4 lines
Ran 34/303 tests successfully
H.264 (91/135) and VP9 (59/61) are same as before. Any idea ? What was your test results ?
Build warnings were badly fixed in my tree. I'll comment inline, but everything was catched by the CI, a V9 will be neede to finish cleanup build and doc warnings. Note that Xiaoyong Lu also had crop info reading, I don't know if this is needed.
Quoted 2,199 lines
Quoted 2,198 lines
---
changed compare with v7:
Using upstream interface to update vp9 prob tables.--- .../media/platform/mediatek/vcodec/Makefile | 1 + .../vcodec/mtk_vcodec_dec_stateless.c | 26 +- .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 1 + .../vcodec/vdec/vdec_vp9_req_lat_if.c | 2072 +++++++++++++++++ .../platform/mediatek/vcodec/vdec_drv_if.c | 4 + .../platform/mediatek/vcodec/vdec_drv_if.h | 1 + 6 files changed, 2102 insertions(+), 3 deletions(-) create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.cdrivers/media/platform/mediatek/vcodec/Makefile +1
-0@@ -9,6 +9,7 @@ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \ vdec/vdec_vp8_if.o \ vdec/vdec_vp8_req_if.o \ vdec/vdec_vp9_if.o \ + vdec/vdec_vp9_req_lat_if.o \ vdec/vdec_h264_req_if.o \ vdec/vdec_h264_req_common.o \ vdec/vdec_h264_req_multi_if.o \drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c +23
-3@@ -91,13 +91,28 @@ static const struct mtk_stateless_control mtk_stateless_controls[] = { .max = V4L2_MPEG_VIDEO_VP8_PROFILE_3, }, .codec_type = V4L2_PIX_FMT_VP8_FRAME, - } + }, + { + .cfg = { + .id = V4L2_CID_STATELESS_VP9_FRAME, + }, + .codec_type = V4L2_PIX_FMT_VP9_FRAME, + }, + { + .cfg = { + .id = V4L2_CID_MPEG_VIDEO_VP9_PROFILE, + .min = V4L2_MPEG_VIDEO_VP9_PROFILE_0, + .def = V4L2_MPEG_VIDEO_VP9_PROFILE_0, + .max = V4L2_MPEG_VIDEO_VP9_PROFILE_3, + }, + .codec_type = V4L2_PIX_FMT_VP9_FRAME, + }, };#define NUM_CTRLS ARRAY_SIZE(mtk_stateless_controls) -static struct mtk_video_fmt mtk_video_formats[4 ]; -static struct mtk_codec_framesizes mtk_vdec_framesizes[2 ]; +static struct mtk_video_fmt mtk_video_formats[5 ]; +static struct mtk_codec_framesizes mtk_vdec_framesizes[3 ];static struct mtk_video_fmt default_out_format;static struct mtk_video_fmt default_cap_format;@@ -338,6 +353,7 @@ static void mtk_vcodec_add_formats(unsigned int fourcc,switch (fourcc) {case V4L2_PIX_FMT_H264_SLICE :case V4L2_PIX_FMT_VP8_FRAME : +case V4L2_PIX_FMT_VP9_FRAME : mtk_video_formats[count_formats].fourcc = fourcc; mtk_video_formats[count_formats].type =MTK_FMT_DEC ; mtk_video_formats[count_formats].num_planes =1 ;@@ -385,6 +401,10 @@ static void mtk_vcodec_get_supported_formats(struct mtk_vcodec_ctx *ctx)mtk_vcodec_add_formats (V4L2_PIX_FMT_VP8_FRAME , ctx); out_format_count++; } +if (ctx->dev->dec_capability &MTK_VDEC_FORMAT_VP9_FRAME ) { +mtk_vcodec_add_formats (V4L2_PIX_FMT_VP9_FRAME , ctx); + out_format_count++; + }if (cap_format_count) default_cap_format = mtk_video_formats[cap_format_count -1 ];drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0@@ -355,6 +355,7 @@ enum mtk_vdec_format_types {MTK_VDEC_FORMAT_MT21C =0x40 ,MTK_VDEC_FORMAT_H264_SLICE =0x100 ,MTK_VDEC_FORMAT_VP8_FRAME =0x200 , + MTK_VDEC_FORMAT_VP9_FRAME = 0x400, };/** drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c new file +2072
-0@@ -0,0 +1,2072 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2021 MediaTek Inc. +* Author: George Sun <[email protected]> +*/ + +#include <linux/module.h> +#include <linux/slab.h> +#include <media/videobuf2-dma-contig.h> +#include <media/v4l2-vp9.h> + +#include "../mtk_vcodec_util.h" +#include "../mtk_vcodec_dec.h" +#include "../mtk_vcodec_intr.h" +#include "../vdec_drv_base.h" +#include "../vdec_drv_if.h" +#include "../vdec_vpu_if.h" + +/* reset_frame_context defined in VP9 spec */ +#define VP9_RESET_FRAME_CONTEXT_NONE0 0 +#define VP9_RESET_FRAME_CONTEXT_NONE1 1 +#define VP9_RESET_FRAME_CONTEXT_SPEC 2 +#define VP9_RESET_FRAME_CONTEXT_ALL 3 + +#define VP9_TILE_BUF_SIZE 4096 +#define VP9_PROB_BUF_SIZE 2560 +#define VP9_COUNTS_BUF_SIZE 16384 + +#define HDR_FLAG (x) (!!((hdr)->flags & V4L2_VP9_FRAME_FLAG_##x)) +#define LF_FLAG (x) (!!((lf)->flags & V4L2_VP9_LOOP_FILTER_FLAG_##x)) +#define SEG_FLAG (x) (!!((seg)->flags & V4L2_VP9_SEGMENTATION_FLAG_##x)) +#define VP9_BAND_6 (band) ((band) == 0 ? 3 : 6) + +/* +* struct vdec_vp9_slice_frame_ctx - vp9 prob tables footprint +*/ +struct vdec_vp9_slice_frame_ctx { +struct { +u8 probs[6 ][3 ]; +u8 padding[2 ]; + } coef_probs[4 ][2 ][2 ][6 ]; + +u8 y_mode_prob[4 ][16 ]; +u8 switch_interp_prob[4 ][16 ]; +u8 seg[32 ];/* ignore */ +u8 comp_inter_prob[16 ]; +u8 comp_ref_prob[16 ]; +u8 single_ref_prob[5 ][2 ]; +u8 single_ref_prob_padding[6 ]; + +u8 joint[3 ]; +u8 joint_padding[13 ]; +struct { +u8 sign; +u8 classes[10 ]; +u8 padding[5 ]; + } sign_classes[2 ]; +struct { +u8 class0[1 ]; +u8 bits[10 ]; +u8 padding[5 ]; + } class0_bits[2 ]; +struct { +u8 class0_fp[2 ][3 ]; +u8 fp[3 ]; +u8 class0_hp; +u8 hp; +u8 padding[5 ]; + } class0_fp_hp[2 ]; + +u8 uv_mode_prob[10 ][16 ]; +u8 uv_mode_prob_padding[2 ][16 ]; + +u8 partition_prob[16 ][4 ]; + +u8 inter_mode_probs[7 ][4 ]; +u8 skip_probs[4 ]; + +u8 tx_p8x8[2 ][4 ]; +u8 tx_p16x16[2 ][4 ]; +u8 tx_p32x32[2 ][4 ]; +u8 intra_inter_prob[8 ]; +}; + +/* +* struct vdec_vp9_slice_frame_counts - vp9 counts tables footprint +*/ +struct vdec_vp9_slice_frame_counts { +union { +struct { +u32 band_0[3 ]; +u32 padding0[1 ]; +u32 band_1_5[5 ][6 ]; +u32 padding1[2 ]; + } eob_branch[4 ][2 ][2 ]; +u32 eob_branch_space[256 *4 ]; + }; + +struct { +u32 band_0[3 ][4 ]; +u32 band_1_5[5 ][6 ][4 ]; + } coef_probs[4 ][2 ][2 ]; + +u32 intra_inter[4 ][2 ]; +u32 comp_inter[5 ][2 ]; +u32 comp_inter_padding[2 ]; +u32 comp_ref[5 ][2 ]; +u32 comp_ref_padding[2 ]; +u32 single_ref[5 ][2 ][2 ]; +u32 inter_mode[7 ][4 ]; +u32 y_mode[4 ][12 ]; +u32 uv_mode[10 ][10 ]; +u32 partition[16 ][4 ]; +u32 switchable_interp[4 ][4 ]; + +u32 tx_p8x8[2 ][2 ]; +u32 tx_p16x16[2 ][4 ]; +u32 tx_p32x32[2 ][4 ]; + +u32 skip[3 ][4 ]; + +u32 joint[4 ]; + +struct { +u32 sign[2 ]; +u32 class0[2 ]; +u32 classes[12 ]; +u32 bits[10 ][2 ]; +u32 padding[4 ]; +u32 class0_fp[2 ][4 ]; +u32 fp[4 ]; +u32 class0_hp[2 ]; +u32 hp[2 ]; + } mvcomp[2 ]; + +u32 reserved[126 ][4 ]; +}; + +/** +* struct vdec_vp9_slice_counts_map - vp9 counts tables to map +* v4l2_vp9_frame_symbol_counts +* @skip: skip counts. +* @y_mode: Y prediction mode counts. +* @filter: interpolation filter counts. +* @mv_joint: motion vector joint counts. +* @sign: motion vector sign counts. +* @classes: motion vector class counts. +* @class0: motion vector class0 bit counts. +* @bits: motion vector bits counts. +* @class0_fp: motion vector class0 fractional bit counts. +* @fp: motion vector fractional bit counts. +* @class0_hp: motion vector class0 high precision fractional bit counts. +* @hp: motion vector high precision fractional bit counts. +*/ +struct vdec_vp9_slice_counts_map { +u32 skip[3 ][2 ]; +u32 y_mode[4 ][10 ]; +u32 filter[4 ][3 ]; +u32 sign[2 ][2 ]; +u32 classes[2 ][11 ]; +u32 class0[2 ][2 ]; +u32 bits[2 ][10 ][2 ]; +u32 class0_fp[2 ][2 ][4 ]; +u32 fp[2 ][4 ]; +u32 class0_hp[2 ][2 ]; +u32 hp[2 ][2 ]; +}; + +/* +* struct vdec_vp9_slice_uncompressed_header - vp9 uncompressed header syntax +* used for decoding +*/ +struct vdec_vp9_slice_uncompressed_header { +u8 profile; +u8 last_frame_type; +u8 frame_type; + +u8 last_show_frame; +u8 show_frame; +u8 error_resilient_mode; + +u8 bit_depth; +u8 padding0[1 ]; +u16 last_frame_width; +u16 last_frame_height; +u16 frame_width; +u16 frame_height; + +u8 intra_only; +u8 reset_frame_context; +u8 ref_frame_sign_bias[4 ]; +u8 allow_high_precision_mv; +u8 interpolation_filter; + +u8 refresh_frame_context; +u8 frame_parallel_decoding_mode; +u8 frame_context_idx; + +/* loop_filter_params */ +u8 loop_filter_level; +u8 loop_filter_sharpness; +u8 loop_filter_delta_enabled; +s8 loop_filter_ref_deltas[4 ]; +s8 loop_filter_mode_deltas[2 ]; + +/* quantization_params */ +u8 base_q_idx; +s8 delta_q_y_dc; +s8 delta_q_uv_dc; +s8 delta_q_uv_ac; + +/* segmentation_params */ +u8 segmentation_enabled; +u8 segmentation_update_map; +u8 segmentation_tree_probs[7 ]; +u8 padding1[1 ]; +u8 segmentation_temporal_udpate; +u8 segmentation_pred_prob[3 ]; +u8 segmentation_update_data; +u8 segmentation_abs_or_delta_update; +u8 feature_enabled[8 ]; +s16 feature_value[8 ][4 ]; + +/* tile_info */ +u8 tile_cols_log2; +u8 tile_rows_log2; +u8 padding2[2 ]; + +u16 uncompressed_header_size; +u16 header_size_in_bytes; + +/* LAT OUT, CORE IN */ +u32 dequant[8 ][4 ]; +}; + +/* +* struct vdec_vp9_slice_compressed_header - vp9 compressed header syntax +* used for decoding. +*/ +struct vdec_vp9_slice_compressed_header { +u8 tx_mode; +u8 ref_mode; +u8 comp_fixed_ref; +u8 comp_var_ref[2 ]; +u8 padding[3 ]; +}; + +/* +* struct vdec_vp9_slice_tiles - vp9 tile syntax +*/ +struct vdec_vp9_slice_tiles { +u32 size[4 ][64 ]; +u32 mi_rows[4 ]; +u32 mi_cols[64 ]; +u8 actual_rows; +u8 padding[7 ]; +}; + +/* +* struct vdec_vp9_slice_reference - vp9 reference frame information +*/ +struct vdec_vp9_slice_reference { +u16 frame_width; +u16 frame_height; +u8 bit_depth; +u8 subsampling_x; +u8 subsampling_y; +u8 padding; +}; + +/* +* struct vdec_vp9_slice_frame - vp9 syntax used for decoding +*/ +struct vdec_vp9_slice_frame { +struct vdec_vp9_slice_uncompressed_header uh; +struct vdec_vp9_slice_compressed_header ch; +struct vdec_vp9_slice_tiles tiles; +struct vdec_vp9_slice_reference ref[3 ]; +}; + +/* +* struct vdec_vp9_slice_init_vsi - VSI used to initialize instance +*/ +struct vdec_vp9_slice_init_vsi { +unsigned int architecture; +unsigned int reserved; +u64 core_vsi; +/* default frame context's position in MicroP */ +u64 default_frame_ctx; +}; + +/* +* struct vdec_vp9_slice_mem - memory address and size +*/ +struct vdec_vp9_slice_mem { +union { +u64 buf; +dma_addr_t dma_addr; + }; +union { +size_t size; +dma_addr_t dma_addr_end; +u64 padding; + }; +}; + +/* +* struct vdec_vp9_slice_bs - input buffer for decoding +*/ +struct vdec_vp9_slice_bs { +struct vdec_vp9_slice_mem buf; +struct vdec_vp9_slice_mem frame; +}; + +/* +* struct vdec_vp9_slice_fb - frame buffer for decoding +*/ +struct vdec_vp9_slice_fb { +struct vdec_vp9_slice_mem y; +struct vdec_vp9_slice_mem c; +}; + +/* +* struct vdec_vp9_slice_state - decoding state +*/ +struct vdec_vp9_slice_state { +int err; +unsigned int full; +unsigned int timeout; +unsigned int perf; + +unsigned int crc[12 ]; +}; + +/** +* struct vdec_vp9_slice_vsi - exchange decoding information +* between Main CPU and MicroP +* +* @bs: input buffer +* @fb: output buffer +* @ref: 3 reference buffers +* @mv: mv working buffer +* @seg: segmentation working buffer +* @tile: tile buffer +* @prob: prob table buffer, used to set/update prob table +* @counts: counts table buffer, used to update prob table +* @ube: general buffer +* @trans: trans buffer position in general buffer +* @err_map: error buffer +* @row_info: row info buffer +* @frame: decoding syntax +* @state: decoding state +*/ +struct vdec_vp9_slice_vsi { +/* used in LAT stage */ +struct vdec_vp9_slice_bs bs; +/* used in Core stage */ +struct vdec_vp9_slice_fb fb; +struct vdec_vp9_slice_fb ref[3 ]; + +struct vdec_vp9_slice_mem mv[2 ]; +struct vdec_vp9_slice_mem seg[2 ]; +struct vdec_vp9_slice_mem tile; +struct vdec_vp9_slice_mem prob; +struct vdec_vp9_slice_mem counts; + +/* LAT stage's output, Core stage's input */ +struct vdec_vp9_slice_mem ube; +struct vdec_vp9_slice_mem trans; +struct vdec_vp9_slice_mem err_map; +struct vdec_vp9_slice_mem row_info; + +/* decoding parameters */ +struct vdec_vp9_slice_frame frame; + +struct vdec_vp9_slice_state state; +}; + +/** +* struct vdec_vp9_slice_pfc - per-frame context that contains a local vsi. +* pass it from lat to core +* +* @vsi: local vsi. copy to/from remote vsi before/after decoding +* @ref_idx: reference buffer index +* @seq: picture sequence +* @state: decoding state +*/ +struct vdec_vp9_slice_pfc { +struct vdec_vp9_slice_vsi vsi; + +u64 ref_idx[3 ]; + +int seq; + +/* LAT/Core CRC */ +struct vdec_vp9_slice_state state[2 ]; +}; + +/* +* enum vdec_vp9_slice_resolution_level +*/ +enum vdec_vp9_slice_resolution_level { +VP9_RES_NONE , +VP9_RES_FHD , +VP9_RES_4K , +VP9_RES_8K , +}; + +/* +* struct vdec_vp9_slice_ref - picture's width & height should kept +* for later decoding as reference picture +*/ +struct vdec_vp9_slice_ref { +unsigned int width; +unsigned int height; +}; + +/** +* struct vdec_vp9_slice_instance - represent one vp9 instance +* +* @ctx: pointer to codec's context +* @vpu: VPU instance +* @seq: global picture sequence +* @level: level of current resolution +* @width: width of last picture +* @height: height of last picture +* @frame_type: frame_type of last picture +* @irq: irq to Main CPU or MicroP +* @show_frame: show_frame of last picture +* @dpb: picture information (width/height) for reference +* @mv: mv working buffer +* @seg: segmentation working buffer +* @tile: tile buffer +* @prob: prob table buffer, used to set/update prob table +* @counts: counts table buffer, used to update prob table +* @frame_ctx: 4 frame context according to VP9 Spec +* @frame_ctx_helper: 4 frame context according to newest kernel spec +* @dirty: state of each frame context +* @init_vsi: vsi used for initialized VP9 instance +* @vsi: vsi used for decoding/flush ... +* @core_vsi: vsi used for Core stage +* @counts_map: used map to counts_helper +* &counts_helper: counts table according to newest kernel spec +*/ +struct vdec_vp9_slice_instance { +struct mtk_vcodec_ctx *ctx; +struct vdec_vpu_inst vpu; + +int seq; + +enum vdec_vp9_slice_resolution_level level; + +/* for resolution change and get_pic_info */ +unsigned int width; +unsigned int height; + +/* for last_frame_type */ +unsigned int frame_type; +unsigned int irq; + +unsigned int show_frame; + +/* maintain vp9 reference frame state */ +struct vdec_vp9_slice_ref dpb[VB2_MAX_FRAME ]; + +/* +* normal working buffers +* mv[0]/seg[0]/tile/prob/counts is used for LAT +* mv[1]/seg[1] is used for CORE +*/ +struct mtk_vcodec_mem mv[2 ]; +struct mtk_vcodec_mem seg[2 ]; +struct mtk_vcodec_mem tile; +struct mtk_vcodec_mem prob; +struct mtk_vcodec_mem counts; + +/* 4 prob tables */ +struct vdec_vp9_slice_frame_ctx frame_ctx[4 ]; +/*4 helper tables */ +struct v4l2_vp9_frame_context frame_ctx_helper; +unsigned char dirty[4 ]; + +/* MicroP vsi */ +union { +struct vdec_vp9_slice_init_vsi *init_vsi; +struct vdec_vp9_slice_vsi *vsi; + }; +struct vdec_vp9_slice_vsi *core_vsi; + +struct vdec_vp9_slice_counts_map counts_map; +struct v4l2_vp9_frame_symbol_counts counts_helper; +}; + +/* +* (2, (0, (1, 3))) +* max level = 2 +*/ +static const signed char vdec_vp9_slice_inter_mode_tree[6 ] = { +-2 ,2 ,0 ,4 ,-1 ,-3 +}; + +/* max level = 6 */ +static const signed char vdec_vp9_slice_intra_mode_tree[18 ] = { +0 ,2 ,-9 ,4 ,-1 ,6 ,8 ,12 ,-2 ,10 ,-4 ,-5 ,-3 ,14 ,-8 ,16 ,-6 ,-7 +}; + +/* max level = 2 */ +static const signed char vdec_vp9_slice_partition_tree[6 ] = { +0 ,2 ,-1 ,4 ,-2 ,-3 +}; + +/* max level = 1 */ +static const signed char vdec_vp9_slice_switchable_interp_tree[4 ] = { +0 ,2 ,-1 ,-2 +}; + +/* max level = 2 */ +static const signed char vdec_vp9_slice_mv_joint_tree[6 ] = { +0 ,2 ,-1 ,4 ,-2 ,-3 +}; + +/* max level = 6 */ +static const signed char vdec_vp9_slice_mv_class_tree[20 ] = { +0 ,2 ,-1 ,4 ,6 ,8 ,-2 ,-3 ,10 ,12 , +-4 ,-5 ,-6 ,14 ,16 ,18 ,-7 ,-8 ,-9 ,-10 +}; + +/* max level = 0 */ +static const signed char vdec_vp9_slice_mv_class0_tree[2 ] = { +0 ,-1 +}; + +/* max level = 2 */ +static const signed char vdec_vp9_slice_mv_fp_tree[6 ] = { +0 ,2 ,-1 ,4 ,-2 ,-3 +}; + +/* +* all VP9 instances could share this default frame context. +*/ +static struct vdec_vp9_slice_frame_ctx *vdec_vp9_slice_default_frame_ctx; +static DEFINE_MUTEX (vdec_vp9_slice_frame_ctx_lock); + +static int vdec_vp9_slice_core_decode (struct vdec_lat_buf *lat_buf); + +static int vdec_vp9_slice_init_default_frame_ctx (struct vdec_vp9_slice_instance *instance) +{ +struct vdec_vp9_slice_frame_ctx *remote_frame_ctx; +struct vdec_vp9_slice_frame_ctx *frame_ctx; +struct mtk_vcodec_ctx *ctx; +struct vdec_vp9_slice_init_vsi *vsi; +int ret =0 ; + + ctx = instance->ctx; + vsi = instance->vpu.vsi; +if (!ctx || !vsi) +return -EINVAL ; + + remote_frame_ctx =mtk_vcodec_fw_map_dm_addr (ctx->dev->fw_handler, + (u32 )vsi->default_frame_ctx); +if (!remote_frame_ctx) { +mtk_vcodec_err (instance,"failed to map default frame ctx\n" ); +return -EINVAL ; + } + +mutex_lock (&vdec_vp9_slice_frame_ctx_lock); +if (vdec_vp9_slice_default_frame_ctx) + goto out; + + frame_ctx =kmalloc (sizeof (*frame_ctx),GFP_KERNEL ); +if (!frame_ctx) { + ret = -ENOMEM ; + goto out; + } + +memcpy_fromio (frame_ctx, remote_frame_ctx,sizeof (*frame_ctx)); + vdec_vp9_slice_default_frame_ctx = frame_ctx; + +out: +mutex_unlock (&vdec_vp9_slice_frame_ctx_lock); + +return ret; +} + +static int vdec_vp9_slice_alloc_working_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi) +{ +struct mtk_vcodec_ctx *ctx = instance->ctx; +enum vdec_vp9_slice_resolution_level level; +/* super blocks */ +unsigned int max_sb_w; +unsigned int max_sb_h; +unsigned int max_w; +unsigned int max_h; +unsigned int w; +unsigned int h; +size_t size; +int ret; +int i; + + w = vsi->frame.uh.frame_width; + h = vsi->frame.uh.frame_height; + +if (w >VCODEC_DEC_4K_CODED_WIDTH || + h >VCODEC_DEC_4K_CODED_HEIGHT ) { +return -EINVAL ; + }else if (w >MTK_VDEC_MAX_W || h >MTK_VDEC_MAX_H ) { +/* 4K */ + level =VP9_RES_4K ; + max_w =VCODEC_DEC_4K_CODED_WIDTH ; + max_h =VCODEC_DEC_4K_CODED_HEIGHT ; + }else { +/* FHD */ + level =VP9_RES_FHD ; + max_w =MTK_VDEC_MAX_W ; + max_h =MTK_VDEC_MAX_H ; + } + +if (level == instance->level) +return 0 ; + +mtk_vcodec_debug (instance,"resolution level changed, from %u to %u, %ux%u" , + instance->level, level, w, h); + + max_sb_w =DIV_ROUND_UP (max_w,64 ); + max_sb_h =DIV_ROUND_UP (max_h,64 ); + ret = -ENOMEM ; + +/* +* Lat-flush must wait core idle, otherwise core will +* use released buffers +*/ + + size = (max_sb_w * max_sb_h +2 ) *576 ; +for (i =0 ; i <2 ; i++) { +if (instance->mv[i].va) +mtk_vcodec_mem_free (ctx, &instance->mv[i]); + instance->mv[i].size = size; +if (mtk_vcodec_mem_alloc (ctx, &instance->mv[i])) + goto err; + } + + size = (max_sb_w * max_sb_h *32 ) +256 ; +for (i =0 ; i <2 ; i++) { +if (instance->seg[i].va) +mtk_vcodec_mem_free (ctx, &instance->seg[i]); + instance->seg[i].size = size; +if (mtk_vcodec_mem_alloc (ctx, &instance->seg[i])) + goto err; + } + +if (!instance->tile.va) { + instance->tile.size =VP9_TILE_BUF_SIZE ; +if (mtk_vcodec_mem_alloc (ctx, &instance->tile)) + goto err; + } + +if (!instance->prob.va) { + instance->prob.size =VP9_PROB_BUF_SIZE ; +if (mtk_vcodec_mem_alloc (ctx, &instance->prob)) + goto err; + } + +if (!instance->counts.va) { + instance->counts.size =VP9_COUNTS_BUF_SIZE ; +if (mtk_vcodec_mem_alloc (ctx, &instance->counts)) + goto err; + } + + instance->level = level; +return 0 ; + +err: + instance->level =VP9_RES_NONE ; +return ret; +} + +static void vdec_vp9_slice_free_working_buffer (struct vdec_vp9_slice_instance *instance) +{ +struct mtk_vcodec_ctx *ctx = instance->ctx; +int i; + +for (i =0 ; i <ARRAY_SIZE (instance->mv); i++) { +if (instance->mv[i].va) +mtk_vcodec_mem_free (ctx, &instance->mv[i]); + } +for (i =0 ; i <ARRAY_SIZE (instance->seg); i++) { +if (instance->seg[i].va) +mtk_vcodec_mem_free (ctx, &instance->seg[i]); + } +if (instance->tile.va) +mtk_vcodec_mem_free (ctx, &instance->tile); +if (instance->prob.va) +mtk_vcodec_mem_free (ctx, &instance->prob); +if (instance->counts.va) +mtk_vcodec_mem_free (ctx, &instance->counts); + + instance->level =VP9_RES_NONE ; +} + +static void vdec_vp9_slice_vsi_from_remote (struct vdec_vp9_slice_vsi *vsi, +struct vdec_vp9_slice_vsi *remote_vsi, +int skip) +{ +struct vdec_vp9_slice_frame *rf; +struct vdec_vp9_slice_frame *f; + +/* +* compressed header +* dequant +* buffer position +* decode state +*/ +if (!skip) { + rf = &remote_vsi->frame; + f = &vsi->frame; +memcpy_fromio (&f->ch, &rf->ch,sizeof (f->ch)); +memcpy_fromio (&f->uh.dequant, &rf->uh.dequant,sizeof (f->uh.dequant)); +memcpy_fromio (&vsi->trans, &remote_vsi->trans,sizeof (vsi->trans)); + } + +memcpy_fromio (&vsi->state, &remote_vsi->state,sizeof (vsi->state)); +} + +static void vdec_vp9_slice_vsi_to_remote (struct vdec_vp9_slice_vsi *vsi, +struct vdec_vp9_slice_vsi *remote_vsi) +{ +memcpy_toio (remote_vsi, vsi,sizeof (*vsi)); +} + +static int vdec_vp9_slice_tile_offset (int idx,int mi_num,int tile_log2) +{ +int sbs = (mi_num +7 ) >>3 ; +int offset = ((idx * sbs) >> tile_log2) <<3 ; + +return offset < mi_num ? offset : mi_num; +} + +static int vdec_vp9_slice_setup_lat_from_src_buf (struct vdec_vp9_slice_instance *instance, +struct vdec_lat_buf *lat_buf) +{ +struct vb2_v4l2_buffer *src; +struct vb2_v4l2_buffer *dst; + + src =v4l2_m2m_next_src_buf (instance->ctx->m2m_ctx); +if (!src) +return -EINVAL ; + + lat_buf->src_buf_req = src->vb2_buf.req_obj.req; + + dst = &lat_buf->ts_info; +v4l2_m2m_buf_copy_metadata (src, dst, true); +return 0 ; +} + +static void vdec_vp9_slice_setup_hdr (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_uncompressed_header *uh, +struct v4l2_ctrl_vp9_frame *hdr) +{ +int i; + + uh->profile = hdr->profile; + uh->last_frame_type = instance->frame_type; + uh->frame_type = !HDR_FLAG (KEY_FRAME ); + uh->last_show_frame = instance->show_frame; + uh->show_frame =HDR_FLAG (SHOW_FRAME ); + uh->error_resilient_mode =HDR_FLAG (ERROR_RESILIENT ); + uh->bit_depth = hdr->bit_depth; + uh->last_frame_width = instance->width; + uh->last_frame_height = instance->height; + uh->frame_width = hdr->frame_width_minus_1 +1 ; + uh->frame_height = hdr->frame_height_minus_1 +1 ; + uh->intra_only =HDR_FLAG (INTRA_ONLY ); +/* map v4l2 enum to values defined in VP9 spec for firmware */ +switch (hdr->reset_frame_context) { +case V4L2_VP9_RESET_FRAME_CTX_NONE : + uh->reset_frame_context =VP9_RESET_FRAME_CONTEXT_NONE0 ; +break ; +case V4L2_VP9_RESET_FRAME_CTX_SPEC : + uh->reset_frame_context =VP9_RESET_FRAME_CONTEXT_SPEC ; +break ; +case V4L2_VP9_RESET_FRAME_CTX_ALL : + uh->reset_frame_context =VP9_RESET_FRAME_CONTEXT_ALL ; +break ; +default : + uh->reset_frame_context =VP9_RESET_FRAME_CONTEXT_NONE0 ; +break ; + } +/* +* ref_frame_sign_bias specifies the intended direction +* of the motion vector in time for each reference frame. +* - INTRA_FRAME = 0, +* - LAST_FRAME = 1, +* - GOLDEN_FRAME = 2, +* - ALTREF_FRAME = 3, +* ref_frame_sign_bias[INTRA_FRAME] is always 0 +* and VDA only passes another 3 directions +*/ + uh->ref_frame_sign_bias[0 ] =0 ; +for (i =0 ; i <3 ; i++) + uh->ref_frame_sign_bias[i +1 ] = + !!(hdr->ref_frame_sign_bias & (1 << i)); + uh->allow_high_precision_mv =HDR_FLAG (ALLOW_HIGH_PREC_MV ); + uh->interpolation_filter = hdr->interpolation_filter; + uh->refresh_frame_context =HDR_FLAG (REFRESH_FRAME_CTX ); + uh->frame_parallel_decoding_mode =HDR_FLAG (PARALLEL_DEC_MODE ); + uh->frame_context_idx = hdr->frame_context_idx; + +/* tile info */ + uh->tile_cols_log2 = hdr->tile_cols_log2; + uh->tile_rows_log2 = hdr->tile_rows_log2; + + uh->uncompressed_header_size = hdr->uncompressed_header_size; + uh->header_size_in_bytes = hdr->compressed_header_size; +} + +static void vdec_vp9_slice_setup_frame_ctx (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_uncompressed_header *uh, +struct v4l2_ctrl_vp9_frame *hdr) +{ +int error_resilient_mode; +int reset_frame_context; +int key_frame; +int intra_only; +int i; + + key_frame =HDR_FLAG (KEY_FRAME ); + intra_only =HDR_FLAG (INTRA_ONLY ); + error_resilient_mode =HDR_FLAG (ERROR_RESILIENT ); + reset_frame_context = uh->reset_frame_context; + +/* +* according to "6.2 Uncompressed header syntax" in +* "VP9 Bitstream & Decoding Process Specification", +* reset @frame_context_idx when (FrameIsIntra || error_resilient_mode) +*/ +if (key_frame || intra_only || error_resilient_mode) { +/* +* @reset_frame_context specifies +* whether the frame context should be +* reset to default values: +* 0 or 1 means do not reset any frame context +* 2 resets just the context specified in the frame header +* 3 resets all contexts +*/ +if (key_frame || error_resilient_mode || + reset_frame_context ==3 ) { +/* use default table */ +for (i =0 ; i <4 ; i++) + instance->dirty[i] =0 ; + }else if (reset_frame_context ==2 ) { + instance->dirty[uh->frame_context_idx] =0 ; + } + uh->frame_context_idx =0 ; + } +} + +static void vdec_vp9_slice_setup_loop_filter (struct vdec_vp9_slice_uncompressed_header *uh, +struct v4l2_vp9_loop_filter *lf) +{ +int i; + + uh->loop_filter_level = lf->level; + uh->loop_filter_sharpness = lf->sharpness; + uh->loop_filter_delta_enabled =LF_FLAG (DELTA_ENABLED ); +for (i =0 ; i <4 ; i++) + uh->loop_filter_ref_deltas[i] = lf->ref_deltas[i]; +for (i =0 ; i <2 ; i++) + uh->loop_filter_mode_deltas[i] = lf->mode_deltas[i]; +} + +static void vdec_vp9_slice_setup_quantization (struct vdec_vp9_slice_uncompressed_header *uh, +struct v4l2_vp9_quantization *quant) +{ + uh->base_q_idx = quant->base_q_idx; + uh->delta_q_y_dc = quant->delta_q_y_dc; + uh->delta_q_uv_dc = quant->delta_q_uv_dc; + uh->delta_q_uv_ac = quant->delta_q_uv_ac; +} + +static void vdec_vp9_slice_setup_segmentation (struct vdec_vp9_slice_uncompressed_header *uh, +struct v4l2_vp9_segmentation *seg) +{ +int i; +int j; + + uh->segmentation_enabled =SEG_FLAG (ENABLED ); + uh->segmentation_update_map =SEG_FLAG (UPDATE_MAP ); +for (i =0 ; i <7 ; i++) + uh->segmentation_tree_probs[i] = seg->tree_probs[i]; + uh->segmentation_temporal_udpate =SEG_FLAG (TEMPORAL_UPDATE ); +for (i =0 ; i <3 ; i++) + uh->segmentation_pred_prob[i] = seg->pred_probs[i]; + uh->segmentation_update_data =SEG_FLAG (UPDATE_DATA ); + uh->segmentation_abs_or_delta_update =SEG_FLAG (ABS_OR_DELTA_UPDATE ); +for (i =0 ; i <8 ; i++) { + uh->feature_enabled[i] = seg->feature_enabled[i]; +for (j =0 ; j <4 ; j++) + uh->feature_value[i][j] = seg->feature_data[i][j]; + } +} + +static int vdec_vp9_slice_setup_tile (struct vdec_vp9_slice_vsi *vsi, +struct v4l2_ctrl_vp9_frame *hdr) +{ +unsigned int rows_log2; +unsigned int cols_log2; +unsigned int rows; +unsigned int cols; +unsigned int mi_rows; +unsigned int mi_cols; +struct vdec_vp9_slice_tiles *tiles; +int offset; +int start; +int end; +int i; + + rows_log2 = hdr->tile_rows_log2; + cols_log2 = hdr->tile_cols_log2; + rows =1 << rows_log2; + cols =1 << cols_log2; + tiles = &vsi->frame.tiles; + tiles->actual_rows =0 ; + +if (rows >4 || cols >64 ) +return -EINVAL ; + +/* setup mi rows/cols information */ + mi_rows = (hdr->frame_height_minus_1 +1 +7 ) >>3 ; + mi_cols = (hdr->frame_width_minus_1 +1 +7 ) >>3 ; + +for (i =0 ; i < rows; i++) { + start =vdec_vp9_slice_tile_offset (i, mi_rows, rows_log2); + end =vdec_vp9_slice_tile_offset (i +1 , mi_rows, rows_log2); + offset = end - start; + tiles->mi_rows[i] = (offset +7 ) >>3 ; +if (tiles->mi_rows[i]) + tiles->actual_rows++; + } + +for (i =0 ; i < cols; i++) { + start =vdec_vp9_slice_tile_offset (i, mi_cols, cols_log2); + end =vdec_vp9_slice_tile_offset (i +1 , mi_cols, cols_log2); + offset = end - start; + tiles->mi_cols[i] = (offset +7 ) >>3 ; + } + +return 0 ; +} + +static void vdec_vp9_slice_setup_state (struct vdec_vp9_slice_vsi *vsi) +{ +memset (&vsi->state,0 ,sizeof (vsi->state)); +} + +static void vdec_vp9_slice_setup_ref_idx (struct vdec_vp9_slice_pfc *pfc, +struct v4l2_ctrl_vp9_frame *hdr) +{ + pfc->ref_idx[0 ] = hdr->last_frame_ts; + pfc->ref_idx[1 ] = hdr->golden_frame_ts; + pfc->ref_idx[2 ] = hdr->alt_frame_ts; +} + +static int vdec_vp9_slice_setup_pfc (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_pfc *pfc) +{ +struct v4l2_ctrl_vp9_frame *hdr; +struct vdec_vp9_slice_uncompressed_header *uh; +struct v4l2_ctrl *hdr_ctrl; +struct vdec_vp9_slice_vsi *vsi; +int ret; + +/* frame header */ + hdr_ctrl =v4l2_ctrl_find (&instance->ctx->ctrl_hdl,V4L2_CID_STATELESS_VP9_FRAME ); +if (!hdr_ctrl || !hdr_ctrl->p_cur.p) +return -EINVAL ; + + hdr = hdr_ctrl->p_cur.p; + vsi = &pfc->vsi; + uh = &vsi->frame.uh; + +/* setup vsi information */ +vdec_vp9_slice_setup_hdr (instance, uh, hdr); +vdec_vp9_slice_setup_frame_ctx (instance, uh, hdr); +vdec_vp9_slice_setup_loop_filter (uh, &hdr->lf); +vdec_vp9_slice_setup_quantization (uh, &hdr->quant); +vdec_vp9_slice_setup_segmentation (uh, &hdr->seg); + ret =vdec_vp9_slice_setup_tile (vsi, hdr); +if (ret) +return ret; +vdec_vp9_slice_setup_state (vsi); + +/* core stage needs buffer index to get ref y/c ... */ +vdec_vp9_slice_setup_ref_idx (pfc, hdr); + + pfc->seq = instance->seq; + instance->seq++; + +return 0 ; +} + +static int vdec_vp9_slice_setup_lat_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi, +struct mtk_vcodec_mem *bs, +struct vdec_lat_buf *lat_buf) +{ +int i; + + vsi->bs.buf.dma_addr = bs->dma_addr; + vsi->bs.buf.size = bs->size; + vsi->bs.frame.dma_addr = bs->dma_addr; + vsi->bs.frame.size = bs->size; + +for (i =0 ; i <2 ; i++) { + vsi->mv[i].dma_addr = instance->mv[i].dma_addr; + vsi->mv[i].size = instance->mv[i].size; + } +for (i =0 ; i <2 ; i++) { + vsi->seg[i].dma_addr = instance->seg[i].dma_addr; + vsi->seg[i].size = instance->seg[i].size; + } + vsi->tile.dma_addr = instance->tile.dma_addr; + vsi->tile.size = instance->tile.size; + vsi->prob.dma_addr = instance->prob.dma_addr; + vsi->prob.size = instance->prob.size; + vsi->counts.dma_addr = instance->counts.dma_addr; + vsi->counts.size = instance->counts.size; + + vsi->ube.dma_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr; + vsi->ube.size = lat_buf->ctx->msg_queue.wdma_addr.size; + vsi->trans.dma_addr = lat_buf->ctx->msg_queue.wdma_wptr_addr; +/* used to store trans end */ + vsi->trans.dma_addr_end = lat_buf->ctx->msg_queue.wdma_rptr_addr; + vsi->err_map.dma_addr = lat_buf->wdma_err_addr.dma_addr; + vsi->err_map.size = lat_buf->wdma_err_addr.size; + + vsi->row_info.buf =0 ; + vsi->row_info.size =0 ; + +return 0 ; +} + +static int vdec_vp9_slice_setup_prob_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi) +{ +struct vdec_vp9_slice_frame_ctx *frame_ctx; +struct vdec_vp9_slice_uncompressed_header *uh; + + uh = &vsi->frame.uh; + +mtk_vcodec_debug (instance,"ctx dirty %u idx %d\n" , + instance->dirty[uh->frame_context_idx], + uh->frame_context_idx); + +if (instance->dirty[uh->frame_context_idx]) + frame_ctx = &instance->frame_ctx[uh->frame_context_idx]; +else + frame_ctx = vdec_vp9_slice_default_frame_ctx; +memcpy (instance->prob.va, frame_ctx,sizeof (*frame_ctx)); + +return 0 ; +} + +static void vdec_vp9_slice_setup_seg_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi, +struct mtk_vcodec_mem *buf) +{ +struct vdec_vp9_slice_uncompressed_header *uh; + +/* reset segment buffer */ + uh = &vsi->frame.uh; +if (uh->frame_type ==0 || + uh->intra_only || + uh->error_resilient_mode || + uh->frame_width != instance->width || + uh->frame_height != instance->height) { +mtk_vcodec_debug (instance,"reset seg\n" ); +memset (buf->va,0 , buf->size); + } +} + +/* +* parse tiles according to `6.4 Decode tiles syntax` +* in "vp9-bitstream-specification" +* +* frame contains uncompress header, compressed header and several tiles. +* this function parses tiles' position and size, stores them to tile buffer +* for decoding. +*/ +static int vdec_vp9_slice_setup_tile_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi, +struct mtk_vcodec_mem *bs) +{ +struct vdec_vp9_slice_uncompressed_header *uh; +unsigned int rows_log2; +unsigned int cols_log2; +unsigned int rows; +unsigned int cols; +unsigned int mi_row; +unsigned int mi_col; +unsigned int offset; +unsigned int pa; +unsigned int size; +struct vdec_vp9_slice_tiles *tiles; +unsigned char *pos; +unsigned char *end; +unsigned char *va; +unsigned int *tb; +int i; +int j; + + uh = &vsi->frame.uh; + rows_log2 = uh->tile_rows_log2; + cols_log2 = uh->tile_cols_log2; + rows =1 << rows_log2; + cols =1 << cols_log2; + +if (rows >4 || cols >64 ) { +mtk_vcodec_err (instance,"tile_rows %u tile_cols %u\n" , + rows, cols); +return -EINVAL ; + } + + offset = uh->uncompressed_header_size + + uh->header_size_in_bytes; +if (bs->size <= offset) { +mtk_vcodec_err (instance,"bs size %zu tile offset %u\n" , + bs->size, offset); +return -EINVAL ; + } + + tiles = &vsi->frame.tiles; +/* setup tile buffer */ + + va = (unsigned char *)bs->va; + pos = va + offset; + end = va + bs->size; +/* truncated */ + pa = (unsigned int )bs->dma_addr + offset; + tb = instance->tile.va; +for (i =0 ; i < rows; i++) { +for (j =0 ; j < cols; j++) { +if (i == rows -1 && + j == cols -1 ) { + size = (unsigned int )(end - pos); + }else { +if (end - pos <4 ) +return -EINVAL ; + + size = (pos[0 ] <<24 ) | (pos[1 ] <<16 ) | + (pos[2 ] <<8 ) | pos[3 ]; + pos +=4 ; + pa +=4 ; + offset +=4 ; +if (end - pos < size) +return -EINVAL ; + } + tiles->size[i][j] = size; +if (tiles->mi_rows[i]) { + *tb++ = (size <<3 ) + ((offset <<3 ) &0x7f ); + *tb++ = pa & ~0xf ; + *tb++ = (pa <<3 ) &0x7f ; + mi_row = (tiles->mi_rows[i] -1 ) &0x1ff ; + mi_col = (tiles->mi_cols[j] -1 ) &0x3f ; + *tb++ = (mi_row <<6 ) + mi_col; + } + pos += size; + pa += size; + offset += size; + } + } + +return 0 ; +} + +static int vdec_vp9_slice_setup_lat (struct vdec_vp9_slice_instance *instance, +struct mtk_vcodec_mem *bs, +struct vdec_lat_buf *lat_buf, +struct vdec_vp9_slice_pfc *pfc) +{ +struct vdec_vp9_slice_vsi *vsi = &pfc->vsi; +int ret; + + ret =vdec_vp9_slice_setup_lat_from_src_buf (instance, lat_buf); +if (ret) + goto err; + + ret =vdec_vp9_slice_setup_pfc (instance, pfc); +if (ret) + goto err; + + ret =vdec_vp9_slice_alloc_working_buffer (instance, vsi); +if (ret) + goto err; + + ret =vdec_vp9_slice_setup_lat_buffer (instance, vsi, bs, lat_buf); +if (ret) + goto err; + +vdec_vp9_slice_setup_seg_buffer (instance, vsi, &instance->seg[0 ]); + +/* setup prob/tile buffers for LAT */ + + ret =vdec_vp9_slice_setup_prob_buffer (instance, vsi); +if (ret) + goto err; + + ret =vdec_vp9_slice_setup_tile_buffer (instance, vsi, bs); +if (ret) + goto err; + +return 0 ; + +err: +return ret; +} + +static +void vdec_vp9_slice_map_counts_eob_coef (unsigned int i,unsigned int j,unsigned int k, +struct vdec_vp9_slice_frame_counts *counts, +struct v4l2_vp9_frame_symbol_counts *counts_helper) +{ +u32 l, m; + +/* +* helper eo -> mtk eo +* helpre e1 -> mtk c3 +* helper c0 -> c0 +* helper c1 -> c1 +* helper c2 -> c2 +*/ +for (l =0 ; l <6 ; l++) { +for (m =0 ; m <VP9_BAND_6 (l); m++) { +if (l ==0 ) { + counts_helper->coeff[i][j][k][l][m] = + &counts->coef_probs[i][j][k].band_0[m]; + counts_helper->eob[i][j][k][l][m][0 ] = + &counts->eob_branch[i][j][k].band_0[m]; + counts_helper->eob[i][j][k][l][m][1 ] = + &counts->coef_probs[i][j][k].band_0[m][3 ]; + }else { + counts_helper->coeff[i][j][k][l][m] = + &counts->coef_probs[i][j][k].band_1_5[l -1 ][m]; + counts_helper->eob[i][j][k][l][m][0 ] = + &counts->eob_branch[i][j][k].band_1_5[l -1 ][m]; + counts_helper->eob[i][j][k][l][m][1 ] = + &counts->coef_probs[i][j][k].band_1_5[l -1 ][m][3 ]; + } + } + } +} + +static void vdec_vp9_slice_counts_map_helper (struct vdec_vp9_slice_counts_map *counts_map, +struct vdec_vp9_slice_frame_counts *counts, +struct v4l2_vp9_frame_symbol_counts *counts_helper) +{ +int i, j, k, l, m; + + counts_helper->partition = &counts->partition; + counts_helper->intra_inter = &counts->intra_inter; + counts_helper->tx32p = &counts->tx_p32x32; + counts_helper->tx16p = &counts->tx_p16x16; + counts_helper->tx8p = &counts->tx_p8x8; + counts_helper->uv_mode = &counts->uv_mode; + + counts_helper->comp = &counts->comp_inter; + counts_helper->comp_ref = &counts->comp_ref; + counts_helper->single_ref = &counts->single_ref; + counts_helper->mv_mode = &counts->inter_mode; + counts_helper->mv_joint = &counts->joint; + +for (i =0 ; i <ARRAY_SIZE (counts_map->skip); i++) +memcpy (counts_map->skip[i], counts->skip[i], +sizeof (counts_map->skip[0 ])); + counts_helper->skip = &counts_map->skip; + +for (i =0 ; i <ARRAY_SIZE (counts_map->y_mode); i++) +memcpy (counts_map->y_mode[i], counts->y_mode[i], +sizeof (counts_map->y_mode[0 ])); + counts_helper->y_mode = &counts_map->y_mode; + +for (i =0 ; i <ARRAY_SIZE (counts_map->filter); i++) +memcpy (counts_map->filter[i], counts->switchable_interp[i], +sizeof (counts_map->filter[0 ])); + counts_helper->filter = &counts_map->filter; + +for (i =0 ; i <ARRAY_SIZE (counts_map->sign); i++) +memcpy (counts_map->sign[i], counts->mvcomp[i].sign, +sizeof (counts_map->sign[0 ])); + counts_helper->sign = &counts_map->sign; + +for (i =0 ; i <ARRAY_SIZE (counts_map->classes); i++) +memcpy (counts_map->classes[i], counts->mvcomp[i].classes, +sizeof (counts_map->classes[0 ])); + counts_helper->classes = &counts_map->classes; + +for (i =0 ; i <ARRAY_SIZE (counts_map->class0); i++) +memcpy (counts_map->class0[i], counts->mvcomp[i].class0, +sizeof (counts_map->class0[0 ])); + counts_helper->class0 = &counts_map->class0; + +for (i =0 ; i <ARRAY_SIZE (counts_map->bits); i++) +for (j =0 ; j <ARRAY_SIZE (counts_map->bits[0 ]); j++) +memcpy (counts_map->bits[i][j], counts->mvcomp[i].bits[j], +sizeof (counts_map->bits[0 ][0 ])); + counts_helper->bits = &counts_map->bits; + +for (i =0 ; i <ARRAY_SIZE (counts_map->class0_fp); i++) +for (j =0 ; j <ARRAY_SIZE (counts_map->class0_fp[0 ]); j++) +memcpy (counts_map->class0_fp[i][j], counts->mvcomp[i].class0_fp[j], +sizeof (counts_map->class0_fp[0 ][0 ])); + counts_helper->class0_fp = &counts_map->class0_fp; + +for (i =0 ; i <ARRAY_SIZE (counts_map->fp); i++) +memcpy (counts_map->fp[i], counts->mvcomp[i].fp, +sizeof (counts_map->fp[0 ])); + counts_helper->fp = &counts_map->fp; + +for (i =0 ; i <ARRAY_SIZE (counts_map->class0_hp); i++) +memcpy (counts_map->class0_hp[i], counts->mvcomp[i].class0_hp, +sizeof (counts_map->class0_hp[0 ])); + counts_helper->class0_hp = &counts_map->class0_hp; + +for (i =0 ; i <ARRAY_SIZE (counts_map->hp); i++) +memcpy (counts_map->hp[i], counts->mvcomp[i].hp,sizeof (counts_map->hp[0 ])); + + counts_helper->hp = &counts_map->hp; + +for (i =0 ; i <4 ; i++) +for (j =0 ; j <2 ; j++) +for (k =0 ; k <2 ; k++) +vdec_vp9_slice_map_counts_eob_coef (i, j, k, counts, counts_helper); +} + +static void vdec_vp9_slice_map_to_coef (unsigned int i,unsigned int j,unsigned int k, +struct vdec_vp9_slice_frame_ctx *frame_ctx, +struct v4l2_vp9_frame_context *frame_ctx_helper) +{ +u32 l, m; + +for (l =0 ; l <ARRAY_SIZE (frame_ctx_helper->coef[0 ][0 ][0 ]); l++) { +for (m =0 ; m <VP9_BAND_6 (l); m++) { +memcpy (frame_ctx_helper->coef[i][j][k][l][m], + frame_ctx->coef_probs[i][j][k][l].probs[m], +sizeof (frame_ctx_helper->coef[i][j][k][l][0 ])); + } + } +} + +static void vdec_vp9_slice_map_from_coef (unsigned int i,unsigned int j,unsigned int k, +struct vdec_vp9_slice_frame_ctx *frame_ctx, +struct v4l2_vp9_frame_context *frame_ctx_helper) +{ +u32 l, m; + +for (l =0 ; l <ARRAY_SIZE (frame_ctx_helper->coef[0 ][0 ][0 ]); l++) { +for (m =0 ; m <VP9_BAND_6 (l); m++) { +memcpy (frame_ctx->coef_probs[i][j][k][l].probs[m], + frame_ctx_helper->coef[i][j][k][l][m], +sizeof (frame_ctx_helper->coef[i][j][k][l][0 ])); + } + } +} + +static +void vdec_vp9_slice_framectx_map_helper (bool frame_is_intra, +struct vdec_vp9_slice_frame_ctx *pre_frame_ctx, +struct vdec_vp9_slice_frame_ctx *frame_ctx, +struct v4l2_vp9_frame_context *frame_ctx_helper) +{ +struct v4l2_vp9_frame_mv_context *mv = &frame_ctx_helper->mv; +u32 i, j, k; + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->coef); i++) +for (j =0 ; j <ARRAY_SIZE (frame_ctx_helper->coef[0 ]); j++) +for (k =0 ; k <ARRAY_SIZE (frame_ctx_helper->coef[0 ][0 ]); k++) +vdec_vp9_slice_map_to_coef (i, j, k, pre_frame_ctx, + frame_ctx_helper); + +/* +* use previous prob when frame is not intra or +* we should use the prob updated by the compressed header parse +*/ +if (!frame_is_intra) + frame_ctx = pre_frame_ctx; + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx8); i++) +memcpy (frame_ctx_helper->tx8[i], frame_ctx->tx_p8x8[i], +sizeof (frame_ctx_helper->tx8[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx16); i++) +memcpy (frame_ctx_helper->tx16[i], frame_ctx->tx_p16x16[i], +sizeof (frame_ctx_helper->tx16[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx32); i++) +memcpy (frame_ctx_helper->tx32[i], frame_ctx->tx_p32x32[i], +sizeof (frame_ctx_helper->tx32[0 ])); + +memcpy (frame_ctx_helper->skip, frame_ctx->skip_probs,sizeof (frame_ctx_helper->skip)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->inter_mode); i++) +memcpy (frame_ctx_helper->inter_mode[i], frame_ctx->inter_mode_probs[i], +sizeof (frame_ctx_helper->inter_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->interp_filter); i++) +memcpy (frame_ctx_helper->interp_filter[i], frame_ctx->switch_interp_prob[i], +sizeof (frame_ctx_helper->interp_filter[0 ])); + +memcpy (frame_ctx_helper->is_inter, frame_ctx->intra_inter_prob, +sizeof (frame_ctx_helper->is_inter)); + +memcpy (frame_ctx_helper->comp_mode, frame_ctx->comp_inter_prob, +sizeof (frame_ctx_helper->comp_mode)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->single_ref); i++) +memcpy (frame_ctx_helper->single_ref[i], frame_ctx->single_ref_prob[i], +sizeof (frame_ctx_helper->single_ref[0 ])); + +memcpy (frame_ctx_helper->comp_ref, frame_ctx->comp_ref_prob, +sizeof (frame_ctx_helper->comp_ref)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->y_mode); i++) +memcpy (frame_ctx_helper->y_mode[i], frame_ctx->y_mode_prob[i], +sizeof (frame_ctx_helper->y_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->uv_mode); i++) +memcpy (frame_ctx_helper->uv_mode[i], frame_ctx->uv_mode_prob[i], +sizeof (frame_ctx_helper->uv_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->partition); i++) +memcpy (frame_ctx_helper->partition[i], frame_ctx->partition_prob[i], +sizeof (frame_ctx_helper->partition[0 ])); + +memcpy (mv->joint, frame_ctx->joint,sizeof (mv->joint)); + +for (i =0 ; i <ARRAY_SIZE (mv->sign); i++) + mv->sign[i] = frame_ctx->sign_classes[i].sign; + +for (i =0 ; i <ARRAY_SIZE (mv->classes); i++) +memcpy (mv->classes[i], frame_ctx->sign_classes[i].classes, +sizeof (mv->classes[i])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_bit); i++) + mv->class0_bit[i] = frame_ctx->class0_bits[i].class0[0 ]; + +for (i =0 ; i <ARRAY_SIZE (mv->bits); i++) +memcpy (mv->bits[i], frame_ctx->class0_bits[i].bits,sizeof (mv->bits[0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_fr); i++) +for (j =0 ; j <ARRAY_SIZE (mv->class0_fr[0 ]); j++) +memcpy (mv->class0_fr[i][j], frame_ctx->class0_fp_hp[i].class0_fp[j], +sizeof (mv->class0_fr[0 ][0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->fr); i++) +memcpy (mv->fr[i], frame_ctx->class0_fp_hp[i].fp,sizeof (mv->fr[0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_hp); i++) + mv->class0_hp[i] = frame_ctx->class0_fp_hp[i].class0_hp; + +for (i =0 ; i <ARRAY_SIZE (mv->hp); i++) + mv->hp[i] = frame_ctx->class0_fp_hp[i].hp; +} + +static void vdec_vp9_slice_helper_map_framectx (struct v4l2_vp9_frame_context *frame_ctx_helper, +struct vdec_vp9_slice_frame_ctx *frame_ctx) +{ +struct v4l2_vp9_frame_mv_context *mv = &frame_ctx_helper->mv; +u32 i, j, k; + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx8); i++) +memcpy (frame_ctx->tx_p8x8[i], frame_ctx_helper->tx8[i], +sizeof (frame_ctx_helper->tx8[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx16); i++) +memcpy (frame_ctx->tx_p16x16[i], frame_ctx_helper->tx16[i], +sizeof (frame_ctx_helper->tx16[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx32); i++) +memcpy (frame_ctx->tx_p32x32[i], frame_ctx_helper->tx32[i], +sizeof (frame_ctx_helper->tx32[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->coef); i++) +for (j =0 ; j <ARRAY_SIZE (frame_ctx_helper->coef[0 ]); j++) +for (k =0 ; k <ARRAY_SIZE (frame_ctx_helper->coef[0 ][0 ]); k++) +vdec_vp9_slice_map_from_coef (i, j, k, frame_ctx, + frame_ctx_helper); + +memcpy (frame_ctx->skip_probs, frame_ctx_helper->skip,sizeof (frame_ctx_helper->skip)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->inter_mode); i++) +memcpy (frame_ctx->inter_mode_probs[i], frame_ctx_helper->inter_mode[i], +sizeof (frame_ctx_helper->inter_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->interp_filter); i++) +memcpy (frame_ctx->switch_interp_prob[i], frame_ctx_helper->interp_filter[i], +sizeof (frame_ctx_helper->interp_filter[0 ])); + +memcpy (frame_ctx->intra_inter_prob, frame_ctx_helper->is_inter, +sizeof (frame_ctx_helper->is_inter)); + +memcpy (frame_ctx->comp_inter_prob, frame_ctx_helper->comp_mode, +sizeof (frame_ctx_helper->comp_mode)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->single_ref); i++) +memcpy (frame_ctx->single_ref_prob[i], frame_ctx_helper->single_ref[i], +sizeof (frame_ctx_helper->single_ref[0 ])); + +memcpy (frame_ctx->comp_ref_prob, frame_ctx_helper->comp_ref, +sizeof (frame_ctx_helper->comp_ref)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->y_mode); i++) +memcpy (frame_ctx->y_mode_prob[i], frame_ctx_helper->y_mode[i], +sizeof (frame_ctx_helper->y_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->uv_mode); i++) +memcpy (frame_ctx->uv_mode_prob[i], frame_ctx_helper->uv_mode[i], +sizeof (frame_ctx_helper->uv_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->partition); i++) +memcpy (frame_ctx->partition_prob[i], frame_ctx_helper->partition[i], +sizeof (frame_ctx_helper->partition[0 ])); + +memcpy (frame_ctx->joint, mv->joint,sizeof (mv->joint)); + +for (i =0 ; i <ARRAY_SIZE (mv->sign); i++) + frame_ctx->sign_classes[i].sign = mv->sign[i]; + +for (i =0 ; i <ARRAY_SIZE (mv->classes); i++) +memcpy (frame_ctx->sign_classes[i].classes, mv->classes[i], +sizeof (mv->classes[i])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_bit); i++) + frame_ctx->class0_bits[i].class0[0 ] = mv->class0_bit[i]; + +for (i =0 ; i <ARRAY_SIZE (mv->bits); i++) +memcpy (frame_ctx->class0_bits[i].bits, mv->bits[i],sizeof (mv->bits[0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_fr); i++) +for (j =0 ; j <ARRAY_SIZE (mv->class0_fr[0 ]); j++) +memcpy (frame_ctx->class0_fp_hp[i].class0_fp[j], mv->class0_fr[i][j], +sizeof (mv->class0_fr[0 ][0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->fr); i++) +memcpy (frame_ctx->class0_fp_hp[i].fp, mv->fr[i],sizeof (mv->fr[0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_hp); i++) + frame_ctx->class0_fp_hp[i].class0_hp = mv->class0_hp[i]; + +for (i =0 ; i <ARRAY_SIZE (mv->hp); i++) + frame_ctx->class0_fp_hp[i].hp = mv->hp[i]; +} + +static int vdec_vp9_slice_update_prob (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi) +{ +struct vdec_vp9_slice_frame_ctx *pre_frame_ctx; +struct v4l2_vp9_frame_context *pre_frame_ctx_helper; +struct vdec_vp9_slice_frame_ctx *frame_ctx; +struct vdec_vp9_slice_frame_counts *counts; +struct v4l2_vp9_frame_symbol_counts *counts_helper; +struct vdec_vp9_slice_uncompressed_header *uh; +bool frame_is_intra; +bool use_128; + + uh = &vsi->frame.uh; + pre_frame_ctx = &instance->frame_ctx[uh->frame_context_idx]; + pre_frame_ctx_helper = &instance->frame_ctx_helper; + frame_ctx = (struct vdec_vp9_slice_frame_ctx *)instance->prob.va; + counts = (struct vdec_vp9_slice_frame_counts *)instance->counts.va; + counts_helper = &instance->counts_helper; + +if (!uh->refresh_frame_context) +return 0 ; + +if (!uh->frame_parallel_decoding_mode) { +vdec_vp9_slice_counts_map_helper (&instance->counts_map, counts, counts_helper); + + frame_is_intra = !vsi->frame.uh.frame_type || vsi->frame.uh.intra_only; +/* check default prob */ +if (!instance->dirty[uh->frame_context_idx]) +vdec_vp9_slice_framectx_map_helper (frame_is_intra, + vdec_vp9_slice_default_frame_ctx, + frame_ctx, + pre_frame_ctx_helper); +else +vdec_vp9_slice_framectx_map_helper (frame_is_intra, + pre_frame_ctx, + frame_ctx, + pre_frame_ctx_helper); + + use_128 = !frame_is_intra && !vsi->frame.uh.last_frame_type; +v4l2_vp9_adapt_coef_probs (pre_frame_ctx_helper, + counts_helper, + use_128, + frame_is_intra); +if (!frame_is_intra) +v4l2_vp9_adapt_noncoef_probs (pre_frame_ctx_helper, + counts_helper, +V4L2_VP9_REFERENCE_MODE_SINGLE_REFERENCE , + vsi->frame.uh.interpolation_filter, + vsi->frame.ch.tx_mode, + vsi->frame.uh.allow_high_precision_mv ? +V4L2_VP9_FRAME_FLAG_ALLOW_HIGH_PREC_MV :0 ); +vdec_vp9_slice_helper_map_framectx (pre_frame_ctx_helper, pre_frame_ctx); + }else { +memcpy (pre_frame_ctx, frame_ctx,sizeof (*frame_ctx)); + } + + instance->dirty[uh->frame_context_idx] =1 ; + +return 0 ; +} + +static int vdec_vp9_slice_update_lat (struct vdec_vp9_slice_instance *instance, +struct vdec_lat_buf *lat_buf, +struct vdec_vp9_slice_pfc *pfc) +{ +struct vdec_vp9_slice_vsi *vsi; + + vsi = &pfc->vsi; +memcpy (&pfc->state[0 ], &vsi->state,sizeof (vsi->state)); + +mtk_vcodec_debug (instance,"Frame %u LAT CRC 0x%08x %lx %lx\n" , + pfc->seq, vsi->state.crc[0 ], + (unsigned long )vsi->trans.dma_addr, + (unsigned long )vsi->trans.dma_addr_end); + +/* buffer full, need to re-decode */ +if (vsi->state.full) { +/* buffer not enough */ +if (vsi->trans.dma_addr_end - vsi->trans.dma_addr == + vsi->ube.size) +return -ENOMEM ; +return -EAGAIN ; + } + +vdec_vp9_slice_update_prob (instance, vsi); + + instance->width = vsi->frame.uh.frame_width; + instance->height = vsi->frame.uh.frame_height; + instance->frame_type = vsi->frame.uh.frame_type; + instance->show_frame = vsi->frame.uh.show_frame; + +return 0 ; +} + +static int vdec_vp9_slice_setup_core_to_dst_buf (struct vdec_vp9_slice_instance *instance, +struct vdec_lat_buf *lat_buf) +{ +struct vb2_v4l2_buffer *dst; + + dst =v4l2_m2m_next_dst_buf (instance->ctx->m2m_ctx); +if (!dst) +return -EINVAL ; + +v4l2_m2m_buf_copy_metadata (&lat_buf->ts_info, dst, true); +return 0 ; +} + +static int vdec_vp9_slice_setup_core_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_pfc *pfc, +struct vdec_vp9_slice_vsi *vsi, +struct vdec_fb *fb, +struct vdec_lat_buf *lat_buf) +{ +struct vb2_buffer *vb; +struct vb2_queue *vq; +struct vdec_vp9_slice_reference *ref; +int plane; +int size; +int idx; +int w; +int h; +int i; + + plane = instance->ctx->q_data[MTK_Q_DATA_DST ].fmt->num_planes; + w = vsi->frame.uh.frame_width; + h = vsi->frame.uh.frame_height; + size =ALIGN (w,64 ) *ALIGN (h,64 ); + +/* frame buffer */ + vsi->fb.y.dma_addr = fb->base_y.dma_addr; +if (plane ==1 ) + vsi->fb.c.dma_addr = fb->base_y.dma_addr + size; +else + vsi->fb.c.dma_addr = fb->base_c.dma_addr; + +/* reference buffers */ + vq =v4l2_m2m_get_vq (instance->ctx->m2m_ctx, +V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ); +if (!vq) +return -EINVAL ; + +/* get current output buffer */ + vb = &v4l2_m2m_next_dst_buf (instance->ctx->m2m_ctx)->vb2_buf; +if (!vb) +return -EINVAL ; + +/* update internal buffer's width/height */ +for (i =0 ; i < vq->num_buffers; i++) { +if (vb == vq->bufs[i]) { + instance->dpb[i].width = w; + instance->dpb[i].height = h; +break ; + } + } + +/* +* get buffer's width/height from instance +* get buffer address from vb2buf +*/ +for (i =0 ; i <3 ; i++) { + ref = &vsi->frame.ref[i]; + idx =vb2_find_timestamp (vq, pfc->ref_idx[i],0 ); +if (idx <0 ) { + ref->frame_width = w; + ref->frame_height = h; +memset (&vsi->ref[i],0 ,sizeof (vsi->ref[i])); + }else { + ref->frame_width = instance->dpb[idx].width; + ref->frame_height = instance->dpb[idx].height; + vb = vq->bufs[idx]; + vsi->ref[i].y.dma_addr = +vb2_dma_contig_plane_dma_addr (vb,0 ); +if (plane ==1 ) + vsi->ref[i].c.dma_addr = + vsi->ref[i].y.dma_addr + size; +else + vsi->ref[i].c.dma_addr = +vb2_dma_contig_plane_dma_addr (vb,1 ); + } + } + +return 0 ; +} + +static int vdec_vp9_slice_setup_core (struct vdec_vp9_slice_instance *instance, +struct vdec_fb *fb, +struct vdec_lat_buf *lat_buf, +struct vdec_vp9_slice_pfc *pfc) +{ +struct vdec_vp9_slice_vsi *vsi = &pfc->vsi; +int ret; + +vdec_vp9_slice_setup_state (vsi); + + ret =vdec_vp9_slice_setup_core_to_dst_buf (instance, lat_buf); +if (ret) + goto err; + + ret =vdec_vp9_slice_setup_core_buffer (instance, pfc, vsi, fb, lat_buf); +if (ret) + goto err; + +vdec_vp9_slice_setup_seg_buffer (instance, vsi, &instance->seg[1 ]); + +return 0 ; + +err: +return ret; +} + +static int vdec_vp9_slice_update_core (struct vdec_vp9_slice_instance *instance, +struct vdec_lat_buf *lat_buf, +struct vdec_vp9_slice_pfc *pfc) +{ +struct vdec_vp9_slice_vsi *vsi; + + vsi = &pfc->vsi; +memcpy (&pfc->state[1 ], &vsi->state,sizeof (vsi->state)); + +mtk_vcodec_debug (instance,"Frame %u Y_CRC %08x %08x %08x %08x\n" , + pfc->seq, + vsi->state.crc[0 ], vsi->state.crc[1 ], + vsi->state.crc[2 ], vsi->state.crc[3 ]); +mtk_vcodec_debug (instance,"Frame %u C_CRC %08x %08x %08x %08x\n" , + pfc->seq, + vsi->state.crc[4 ], vsi->state.crc[5 ], + vsi->state.crc[6 ], vsi->state.crc[7 ]); + +return 0 ; +} + +static int vdec_vp9_slice_init (struct mtk_vcodec_ctx *ctx) +{ +struct vdec_vp9_slice_instance *instance; +struct vdec_vp9_slice_init_vsi *vsi; +int ret; + + instance =kzalloc (sizeof (*instance),GFP_KERNEL ); +if (!instance) +return -ENOMEM ; + + instance->ctx = ctx; + instance->vpu.id =SCP_IPI_VDEC_LAT ; + instance->vpu.core_id =SCP_IPI_VDEC_CORE ; + instance->vpu.ctx = ctx; + instance->vpu.codec_type = ctx->current_codec; + + ret =vpu_dec_init (&instance->vpu); +if (ret) { +mtk_vcodec_err (instance,"failed to init vpu dec, ret %d\n" , ret); + goto error_vpu_init; + } + +/* init vsi and global flags */ + + vsi = instance->vpu.vsi; +if (!vsi) { +mtk_vcodec_err (instance,"failed to get VP9 vsi\n" ); + ret = -EINVAL ; + goto error_vsi; + } + instance->init_vsi = vsi; + instance->core_vsi =mtk_vcodec_fw_map_dm_addr (ctx->dev->fw_handler, + (u32 )vsi->core_vsi); +if (!instance->core_vsi) { +mtk_vcodec_err (instance,"failed to get VP9 core vsi\n" ); + ret = -EINVAL ; + goto error_vsi; + } + + instance->irq =1 ; + + ret =vdec_vp9_slice_init_default_frame_ctx (instance); +if (ret) + goto error_default_frame_ctx; + + ctx->drv_handle = instance; + +return 0 ; + +error_default_frame_ctx: +error_vsi: +vpu_dec_deinit (&instance->vpu); +error_vpu_init: +kfree (instance); +return ret; +} + +static void vdec_vp9_slice_deinit (void *h_vdec) +{ +struct vdec_vp9_slice_instance *instance = h_vdec; + +if (!instance) +return ; + +vpu_dec_deinit (&instance->vpu); +vdec_vp9_slice_free_working_buffer (instance); +vdec_msg_queue_deinit (&instance->ctx->msg_queue, instance->ctx); +kfree (instance); +} + +static int vdec_vp9_slice_flush (void *h_vdec,struct mtk_vcodec_mem *bs, +struct vdec_fb *fb,bool *res_chg) +{ +struct vdec_vp9_slice_instance *instance = h_vdec; + +mtk_vcodec_debug (instance,"flush ...\n" ); + +vdec_msg_queue_wait_lat_buf_full (&instance->ctx->msg_queue); +return vpu_dec_reset (&instance->vpu); +} + +static void vdec_vp9_slice_get_pic_info (struct vdec_vp9_slice_instance *instance) +{ +struct mtk_vcodec_ctx *ctx = instance->ctx; +unsigned int data[3 ]; + +mtk_vcodec_debug (instance,"w %u h %u\n" , + ctx->picinfo.pic_w, ctx->picinfo.pic_h); + + data[0 ] = ctx->picinfo.pic_w; + data[1 ] = ctx->picinfo.pic_h; + data[2 ] = ctx->capture_fourcc; +vpu_dec_get_param (&instance->vpu, data,3 ,GET_PARAM_PIC_INFO ); + + ctx->picinfo.buf_w =ALIGN (ctx->picinfo.pic_w,64 ); + ctx->picinfo.buf_h =ALIGN (ctx->picinfo.pic_h,64 ); + ctx->picinfo.fb_sz[0 ] = instance->vpu.fb_sz[0 ]; + ctx->picinfo.fb_sz[1 ] = instance->vpu.fb_sz[1 ]; +} + +static void vdec_vp9_slice_get_dpb_size (struct vdec_vp9_slice_instance *instance, +unsigned int *dpb_sz) +{ +/* refer VP9 specification */ + *dpb_sz =9 ; +} + +static int vdec_vp9_slice_get_param (void *h_vdec,enum vdec_get_param_type type,void *out) +{ +struct vdec_vp9_slice_instance *instance = h_vdec; + +switch (type) { +case GET_PARAM_PIC_INFO : +vdec_vp9_slice_get_pic_info (instance); +break ; +case GET_PARAM_DPB_SIZE : +vdec_vp9_slice_get_dpb_size (instance, out); +break ; +case GET_PARAM_CROP_INFO : +mtk_vcodec_debug (instance,"No need to get vp9 crop information." ); +break ; +default : +mtk_vcodec_err (instance,"invalid get parameter type=%d\n" , + type); +return -EINVAL ; + } + +return 0 ; +} + +static int vdec_vp9_slice_lat_decode (void *h_vdec,struct mtk_vcodec_mem *bs, +struct vdec_fb *fb,bool *res_chg) +{ +struct vdec_vp9_slice_instance *instance = h_vdec; +struct vdec_lat_buf *lat_buf; +struct vdec_vp9_slice_pfc *pfc; +struct vdec_vp9_slice_vsi *vsi; +struct mtk_vcodec_ctx *ctx; +int ret; + +if (!instance || !instance->ctx) +return -EINVAL ; + ctx = instance->ctx; + +/* init msgQ for the first time */ +if (vdec_msg_queue_init (&ctx->msg_queue, ctx, + vdec_vp9_slice_core_decode, +sizeof (*pfc))) +return -ENOMEM ; + +/* bs NULL means flush decoder */ +if (!bs) +return vdec_vp9_slice_flush (h_vdec, bs, fb, res_chg); + + lat_buf =vdec_msg_queue_dqbuf (&instance->ctx->msg_queue.lat_ctx); +if (!lat_buf) { +mtk_vcodec_err (instance,"Failed to get VP9 lat buf\n" ); +return -EBUSY ; + } + pfc = (struct vdec_vp9_slice_pfc *)lat_buf->private_data; +if (!pfc) +return -EINVAL ; + vsi = &pfc->vsi; + + ret =vdec_vp9_slice_setup_lat (instance, bs, lat_buf, pfc); +if (ret) { +mtk_vcodec_err (instance,"Failed to setup VP9 lat ret %d\n" , ret); +return ret; + } +vdec_vp9_slice_vsi_to_remote (vsi, instance->vsi); + + ret =vpu_dec_start (&instance->vpu,0 ,0 ); +if (ret) { +mtk_vcodec_err (instance,"Failed to dec VP9 ret %d\n" , ret); +return ret; + } + +if (instance->irq) { + ret =mtk_vcodec_wait_for_done_ctx (ctx,MTK_INST_IRQ_RECEIVED , +WAIT_INTR_TIMEOUT_MS ,MTK_VDEC_LAT0 ); +/* update remote vsi if decode timeout */ +if (ret) { +mtk_vcodec_err (instance,"VP9 decode timeout %d pic %d\n" , ret, pfc->seq); +writel (1 , &instance->vsi->state.timeout); + } +vpu_dec_end (&instance->vpu); + } + +vdec_vp9_slice_vsi_from_remote (vsi, instance->vsi,0 ); + ret =vdec_vp9_slice_update_lat (instance, lat_buf, pfc); + +/* LAT trans full, no more UBE or decode timeout */ +if (ret) { +mtk_vcodec_err (instance,"VP9 decode error: %d\n" , ret); +return ret; + } + +mtk_vcodec_debug (instance,"lat dma 1 0x%llx 0x%llx\n" , + pfc->vsi.trans.dma_addr, pfc->vsi.trans.dma_addr_end); + +vdec_msg_queue_update_ube_wptr (&ctx->msg_queue, + vsi->trans.dma_addr_end + + ctx->msg_queue.wdma_addr.dma_addr); +vdec_msg_queue_qbuf (&ctx->dev->msg_queue_core_ctx, lat_buf); + +return 0 ; +} + +static int vdec_vp9_slice_core_decode (struct vdec_lat_buf *lat_buf) +{ +struct vdec_vp9_slice_instance *instance; +struct vdec_vp9_slice_pfc *pfc; +struct mtk_vcodec_ctx *ctx =NULL ; +struct vdec_fb *fb =NULL ; +int ret = -EINVAL ; + +if (!lat_buf) + goto err; + + pfc = lat_buf->private_data; + ctx = lat_buf->ctx; +if (!pfc || !ctx) + goto err; + + instance = ctx->drv_handle; +if (!instance) + goto err; + + fb = ctx->dev->vdec_pdata->get_cap_buffer (ctx); +if (!fb) { + ret = -EBUSY ; + goto err; + } + + ret =vdec_vp9_slice_setup_core (instance, fb, lat_buf, pfc); +if (ret) { +mtk_vcodec_err (instance,"vdec_vp9_slice_setup_core\n" ); + goto err; + } +vdec_vp9_slice_vsi_to_remote (&pfc->vsi, instance->core_vsi); + + ret =vpu_dec_core (&instance->vpu); +if (ret) { +mtk_vcodec_err (instance,"vpu_dec_core\n" ); + goto err; + } + +if (instance->irq) { + ret =mtk_vcodec_wait_for_done_ctx (ctx,MTK_INST_IRQ_RECEIVED , +WAIT_INTR_TIMEOUT_MS ,MTK_VDEC_CORE ); +/* update remote vsi if decode timeout */ +if (ret) { +mtk_vcodec_err (instance,"VP9 core timeout pic %d\n" , pfc->seq); +writel (1 , &instance->core_vsi->state.timeout); + } +vpu_dec_core_end (&instance->vpu); + } + +vdec_vp9_slice_vsi_from_remote (&pfc->vsi, instance->core_vsi,1 ); + ret =vdec_vp9_slice_update_core (instance, lat_buf, pfc); +if (ret) { +mtk_vcodec_err (instance,"vdec_vp9_slice_update_core\n" ); + goto err; + } + + pfc->vsi.trans.dma_addr_end += ctx->msg_queue.wdma_addr.dma_addr; +mtk_vcodec_debug (instance,"core dma_addr_end 0x%llx\n" , 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); + +return 0 ; + +err: +if (ctx) { +/* always update read pointer */ +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); + } +return ret; +} + +const struct vdec_common_if vdec_vp9_slice_lat_if = { + .init = vdec_vp9_slice_init, + .decode = vdec_vp9_slice_lat_decode, + .get_param = vdec_vp9_slice_get_param, + .deinit = vdec_vp9_slice_deinit, +};drivers/media/platform/mediatek/vcodec/vdec_drv_if.c +4
-0@@ -45,6 +45,10 @@ int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc) ctx->dec_if = &vdec_vp9_if; ctx->hw_id =MTK_VDEC_CORE ;break ; +case V4L2_PIX_FMT_VP9_FRAME : + ctx->dec_if = &vdec_vp9_slice_lat_if; + ctx->hw_id =MTK_VDEC_LAT0 ; +break ;default :return -EINVAL ; }drivers/media/platform/mediatek/vcodec/vdec_drv_if.h +1
-0@@ -60,6 +60,7 @@ extern const struct vdec_common_if vdec_h264_slice_multi_if;extern const struct vdec_common_if vdec_vp8_if;extern const struct vdec_common_if vdec_vp8_slice_if;extern const struct vdec_common_if vdec_vp9_if; +extern const struct vdec_common_if vdec_vp9_slice_lat_if;/** * vdec_if_init() - initialize decode driver
Re: [PATCH v8, 16/17] media: mediatek: vcodec: support stateless VP9 decoding
In reply to Yunfei DongLe jeudi 31 mars 2022 à 10:48 +0800, Yunfei Dong a écrit :
Quoted 538 lines
Add support for VP9 decoding using the stateless API,
as supported by MT8192. And the drivers is lat and core architecture.Signed-off-by George Sun <[email protected]>Signed-off-by Xiaoyong Lu <[email protected]>Signed-off-by Yunfei Dong <[email protected]>Reviewed-by AngeloGioacchino Del Regno <[email protected]>---
changed compare with v7:
Using upstream interface to update vp9 prob tables.--- .../media/platform/mediatek/vcodec/Makefile | 1 + .../vcodec/mtk_vcodec_dec_stateless.c | 26 +- .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 1 + .../vcodec/vdec/vdec_vp9_req_lat_if.c | 2072 +++++++++++++++++ .../platform/mediatek/vcodec/vdec_drv_if.c | 4 + .../platform/mediatek/vcodec/vdec_drv_if.h | 1 + 6 files changed, 2102 insertions(+), 3 deletions(-) create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.cdrivers/media/platform/mediatek/vcodec/Makefile +1
-0@@ -9,6 +9,7 @@ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \ vdec/vdec_vp8_if.o \ vdec/vdec_vp8_req_if.o \ vdec/vdec_vp9_if.o \ + vdec/vdec_vp9_req_lat_if.o \ vdec/vdec_h264_req_if.o \ vdec/vdec_h264_req_common.o \ vdec/vdec_h264_req_multi_if.o \drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c +23
-3@@ -91,13 +91,28 @@ static const struct mtk_stateless_control mtk_stateless_controls[] = { .max = V4L2_MPEG_VIDEO_VP8_PROFILE_3, }, .codec_type = V4L2_PIX_FMT_VP8_FRAME, - } + }, + { + .cfg = { + .id = V4L2_CID_STATELESS_VP9_FRAME, + }, + .codec_type = V4L2_PIX_FMT_VP9_FRAME, + }, + { + .cfg = { + .id = V4L2_CID_MPEG_VIDEO_VP9_PROFILE, + .min = V4L2_MPEG_VIDEO_VP9_PROFILE_0, + .def = V4L2_MPEG_VIDEO_VP9_PROFILE_0, + .max = V4L2_MPEG_VIDEO_VP9_PROFILE_3, + }, + .codec_type = V4L2_PIX_FMT_VP9_FRAME, + }, };#define NUM_CTRLS ARRAY_SIZE(mtk_stateless_controls) -static struct mtk_video_fmt mtk_video_formats[4 ]; -static struct mtk_codec_framesizes mtk_vdec_framesizes[2 ]; +static struct mtk_video_fmt mtk_video_formats[5 ]; +static struct mtk_codec_framesizes mtk_vdec_framesizes[3 ];static struct mtk_video_fmt default_out_format;static struct mtk_video_fmt default_cap_format;@@ -338,6 +353,7 @@ static void mtk_vcodec_add_formats(unsigned int fourcc,switch (fourcc) {case V4L2_PIX_FMT_H264_SLICE :case V4L2_PIX_FMT_VP8_FRAME : +case V4L2_PIX_FMT_VP9_FRAME : mtk_video_formats[count_formats].fourcc = fourcc; mtk_video_formats[count_formats].type =MTK_FMT_DEC ; mtk_video_formats[count_formats].num_planes =1 ;@@ -385,6 +401,10 @@ static void mtk_vcodec_get_supported_formats(struct mtk_vcodec_ctx *ctx)mtk_vcodec_add_formats (V4L2_PIX_FMT_VP8_FRAME , ctx); out_format_count++; } +if (ctx->dev->dec_capability &MTK_VDEC_FORMAT_VP9_FRAME ) { +mtk_vcodec_add_formats (V4L2_PIX_FMT_VP9_FRAME , ctx); + out_format_count++; + }if (cap_format_count) default_cap_format = mtk_video_formats[cap_format_count -1 ];drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0@@ -355,6 +355,7 @@ enum mtk_vdec_format_types {MTK_VDEC_FORMAT_MT21C =0x40 ,MTK_VDEC_FORMAT_H264_SLICE =0x100 ,MTK_VDEC_FORMAT_VP8_FRAME =0x200 , + MTK_VDEC_FORMAT_VP9_FRAME = 0x400, };/** drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c new file +433
-0@@ -0,0 +1,2072 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2021 MediaTek Inc. +* Author: George Sun <[email protected]> +*/ + +#include <linux/module.h> +#include <linux/slab.h> +#include <media/videobuf2-dma-contig.h> +#include <media/v4l2-vp9.h> + +#include "../mtk_vcodec_util.h" +#include "../mtk_vcodec_dec.h" +#include "../mtk_vcodec_intr.h" +#include "../vdec_drv_base.h" +#include "../vdec_drv_if.h" +#include "../vdec_vpu_if.h" + +/* reset_frame_context defined in VP9 spec */ +#define VP9_RESET_FRAME_CONTEXT_NONE0 0 +#define VP9_RESET_FRAME_CONTEXT_NONE1 1 +#define VP9_RESET_FRAME_CONTEXT_SPEC 2 +#define VP9_RESET_FRAME_CONTEXT_ALL 3 + +#define VP9_TILE_BUF_SIZE 4096 +#define VP9_PROB_BUF_SIZE 2560 +#define VP9_COUNTS_BUF_SIZE 16384 + +#define HDR_FLAG (x) (!!((hdr)->flags & V4L2_VP9_FRAME_FLAG_##x)) +#define LF_FLAG (x) (!!((lf)->flags & V4L2_VP9_LOOP_FILTER_FLAG_##x)) +#define SEG_FLAG (x) (!!((seg)->flags & V4L2_VP9_SEGMENTATION_FLAG_##x)) +#define VP9_BAND_6 (band) ((band) == 0 ? 3 : 6) + +/* +* struct vdec_vp9_slice_frame_ctx - vp9 prob tables footprint +*/ +struct vdec_vp9_slice_frame_ctx { +struct { +u8 probs[6 ][3 ]; +u8 padding[2 ]; + } coef_probs[4 ][2 ][2 ][6 ]; + +u8 y_mode_prob[4 ][16 ]; +u8 switch_interp_prob[4 ][16 ]; +u8 seg[32 ];/* ignore */ +u8 comp_inter_prob[16 ]; +u8 comp_ref_prob[16 ]; +u8 single_ref_prob[5 ][2 ]; +u8 single_ref_prob_padding[6 ]; + +u8 joint[3 ]; +u8 joint_padding[13 ]; +struct { +u8 sign; +u8 classes[10 ]; +u8 padding[5 ]; + } sign_classes[2 ]; +struct { +u8 class0[1 ]; +u8 bits[10 ]; +u8 padding[5 ]; + } class0_bits[2 ]; +struct { +u8 class0_fp[2 ][3 ]; +u8 fp[3 ]; +u8 class0_hp; +u8 hp; +u8 padding[5 ]; + } class0_fp_hp[2 ]; + +u8 uv_mode_prob[10 ][16 ]; +u8 uv_mode_prob_padding[2 ][16 ]; + +u8 partition_prob[16 ][4 ]; + +u8 inter_mode_probs[7 ][4 ]; +u8 skip_probs[4 ]; + +u8 tx_p8x8[2 ][4 ]; +u8 tx_p16x16[2 ][4 ]; +u8 tx_p32x32[2 ][4 ]; +u8 intra_inter_prob[8 ]; +}; + +/* +* struct vdec_vp9_slice_frame_counts - vp9 counts tables footprint +*/ +struct vdec_vp9_slice_frame_counts { +union { +struct { +u32 band_0[3 ]; +u32 padding0[1 ]; +u32 band_1_5[5 ][6 ]; +u32 padding1[2 ]; + } eob_branch[4 ][2 ][2 ]; +u32 eob_branch_space[256 *4 ]; + }; + +struct { +u32 band_0[3 ][4 ]; +u32 band_1_5[5 ][6 ][4 ]; + } coef_probs[4 ][2 ][2 ]; + +u32 intra_inter[4 ][2 ]; +u32 comp_inter[5 ][2 ]; +u32 comp_inter_padding[2 ]; +u32 comp_ref[5 ][2 ]; +u32 comp_ref_padding[2 ]; +u32 single_ref[5 ][2 ][2 ]; +u32 inter_mode[7 ][4 ]; +u32 y_mode[4 ][12 ]; +u32 uv_mode[10 ][10 ]; +u32 partition[16 ][4 ]; +u32 switchable_interp[4 ][4 ]; + +u32 tx_p8x8[2 ][2 ]; +u32 tx_p16x16[2 ][4 ]; +u32 tx_p32x32[2 ][4 ]; + +u32 skip[3 ][4 ]; + +u32 joint[4 ]; + +struct { +u32 sign[2 ]; +u32 class0[2 ]; +u32 classes[12 ]; +u32 bits[10 ][2 ]; +u32 padding[4 ]; +u32 class0_fp[2 ][4 ]; +u32 fp[4 ]; +u32 class0_hp[2 ]; +u32 hp[2 ]; + } mvcomp[2 ]; + +u32 reserved[126 ][4 ]; +}; + +/** +* struct vdec_vp9_slice_counts_map - vp9 counts tables to map +* v4l2_vp9_frame_symbol_counts +* @skip: skip counts. +* @y_mode: Y prediction mode counts. +* @filter: interpolation filter counts. +* @mv_joint: motion vector joint counts. +* @sign: motion vector sign counts. +* @classes: motion vector class counts. +* @class0: motion vector class0 bit counts. +* @bits: motion vector bits counts. +* @class0_fp: motion vector class0 fractional bit counts. +* @fp: motion vector fractional bit counts. +* @class0_hp: motion vector class0 high precision fractional bit counts. +* @hp: motion vector high precision fractional bit counts. +*/ +struct vdec_vp9_slice_counts_map { +u32 skip[3 ][2 ]; +u32 y_mode[4 ][10 ]; +u32 filter[4 ][3 ]; +u32 sign[2 ][2 ]; +u32 classes[2 ][11 ]; +u32 class0[2 ][2 ]; +u32 bits[2 ][10 ][2 ]; +u32 class0_fp[2 ][2 ][4 ]; +u32 fp[2 ][4 ]; +u32 class0_hp[2 ][2 ]; +u32 hp[2 ][2 ]; +}; + +/* +* struct vdec_vp9_slice_uncompressed_header - vp9 uncompressed header syntax +* used for decoding +*/ +struct vdec_vp9_slice_uncompressed_header { +u8 profile; +u8 last_frame_type; +u8 frame_type; + +u8 last_show_frame; +u8 show_frame; +u8 error_resilient_mode; + +u8 bit_depth; +u8 padding0[1 ]; +u16 last_frame_width; +u16 last_frame_height; +u16 frame_width; +u16 frame_height; + +u8 intra_only; +u8 reset_frame_context; +u8 ref_frame_sign_bias[4 ]; +u8 allow_high_precision_mv; +u8 interpolation_filter; + +u8 refresh_frame_context; +u8 frame_parallel_decoding_mode; +u8 frame_context_idx; + +/* loop_filter_params */ +u8 loop_filter_level; +u8 loop_filter_sharpness; +u8 loop_filter_delta_enabled; +s8 loop_filter_ref_deltas[4 ]; +s8 loop_filter_mode_deltas[2 ]; + +/* quantization_params */ +u8 base_q_idx; +s8 delta_q_y_dc; +s8 delta_q_uv_dc; +s8 delta_q_uv_ac; + +/* segmentation_params */ +u8 segmentation_enabled; +u8 segmentation_update_map; +u8 segmentation_tree_probs[7 ]; +u8 padding1[1 ]; +u8 segmentation_temporal_udpate; +u8 segmentation_pred_prob[3 ]; +u8 segmentation_update_data; +u8 segmentation_abs_or_delta_update; +u8 feature_enabled[8 ]; +s16 feature_value[8 ][4 ]; + +/* tile_info */ +u8 tile_cols_log2; +u8 tile_rows_log2; +u8 padding2[2 ]; + +u16 uncompressed_header_size; +u16 header_size_in_bytes; + +/* LAT OUT, CORE IN */ +u32 dequant[8 ][4 ]; +}; + +/* +* struct vdec_vp9_slice_compressed_header - vp9 compressed header syntax +* used for decoding. +*/ +struct vdec_vp9_slice_compressed_header { +u8 tx_mode; +u8 ref_mode; +u8 comp_fixed_ref; +u8 comp_var_ref[2 ]; +u8 padding[3 ]; +}; + +/* +* struct vdec_vp9_slice_tiles - vp9 tile syntax +*/ +struct vdec_vp9_slice_tiles { +u32 size[4 ][64 ]; +u32 mi_rows[4 ]; +u32 mi_cols[64 ]; +u8 actual_rows; +u8 padding[7 ]; +}; + +/* +* struct vdec_vp9_slice_reference - vp9 reference frame information +*/ +struct vdec_vp9_slice_reference { +u16 frame_width; +u16 frame_height; +u8 bit_depth; +u8 subsampling_x; +u8 subsampling_y; +u8 padding; +}; + +/* +* struct vdec_vp9_slice_frame - vp9 syntax used for decoding +*/ +struct vdec_vp9_slice_frame { +struct vdec_vp9_slice_uncompressed_header uh; +struct vdec_vp9_slice_compressed_header ch; +struct vdec_vp9_slice_tiles tiles; +struct vdec_vp9_slice_reference ref[3 ]; +}; + +/* +* struct vdec_vp9_slice_init_vsi - VSI used to initialize instance +*/ +struct vdec_vp9_slice_init_vsi { +unsigned int architecture; +unsigned int reserved; +u64 core_vsi; +/* default frame context's position in MicroP */ +u64 default_frame_ctx; +}; + +/* +* struct vdec_vp9_slice_mem - memory address and size +*/ +struct vdec_vp9_slice_mem { +union { +u64 buf; +dma_addr_t dma_addr; + }; +union { +size_t size; +dma_addr_t dma_addr_end; +u64 padding; + }; +}; + +/* +* struct vdec_vp9_slice_bs - input buffer for decoding +*/ +struct vdec_vp9_slice_bs { +struct vdec_vp9_slice_mem buf; +struct vdec_vp9_slice_mem frame; +}; + +/* +* struct vdec_vp9_slice_fb - frame buffer for decoding +*/ +struct vdec_vp9_slice_fb { +struct vdec_vp9_slice_mem y; +struct vdec_vp9_slice_mem c; +}; + +/* +* struct vdec_vp9_slice_state - decoding state +*/ +struct vdec_vp9_slice_state { +int err; +unsigned int full; +unsigned int timeout; +unsigned int perf; + +unsigned int crc[12 ]; +}; + +/** +* struct vdec_vp9_slice_vsi - exchange decoding information +* between Main CPU and MicroP +* +* @bs: input buffer +* @fb: output buffer +* @ref: 3 reference buffers +* @mv: mv working buffer +* @seg: segmentation working buffer +* @tile: tile buffer +* @prob: prob table buffer, used to set/update prob table +* @counts: counts table buffer, used to update prob table +* @ube: general buffer +* @trans: trans buffer position in general buffer +* @err_map: error buffer +* @row_info: row info buffer +* @frame: decoding syntax +* @state: decoding state +*/ +struct vdec_vp9_slice_vsi { +/* used in LAT stage */ +struct vdec_vp9_slice_bs bs; +/* used in Core stage */ +struct vdec_vp9_slice_fb fb; +struct vdec_vp9_slice_fb ref[3 ]; + +struct vdec_vp9_slice_mem mv[2 ]; +struct vdec_vp9_slice_mem seg[2 ]; +struct vdec_vp9_slice_mem tile; +struct vdec_vp9_slice_mem prob; +struct vdec_vp9_slice_mem counts; + +/* LAT stage's output, Core stage's input */ +struct vdec_vp9_slice_mem ube; +struct vdec_vp9_slice_mem trans; +struct vdec_vp9_slice_mem err_map; +struct vdec_vp9_slice_mem row_info; + +/* decoding parameters */ +struct vdec_vp9_slice_frame frame; + +struct vdec_vp9_slice_state state; +}; + +/** +* struct vdec_vp9_slice_pfc - per-frame context that contains a local vsi. +* pass it from lat to core +* +* @vsi: local vsi. copy to/from remote vsi before/after decoding +* @ref_idx: reference buffer index +* @seq: picture sequence +* @state: decoding state +*/ +struct vdec_vp9_slice_pfc { +struct vdec_vp9_slice_vsi vsi; + +u64 ref_idx[3 ]; + +int seq; + +/* LAT/Core CRC */ +struct vdec_vp9_slice_state state[2 ]; +}; + +/* +* enum vdec_vp9_slice_resolution_level +*/ +enum vdec_vp9_slice_resolution_level { +VP9_RES_NONE , +VP9_RES_FHD , +VP9_RES_4K , +VP9_RES_8K , +}; + +/* +* struct vdec_vp9_slice_ref - picture's width & height should kept +* for later decoding as reference picture +*/ +struct vdec_vp9_slice_ref { +unsigned int width; +unsigned int height; +}; + +/** +* struct vdec_vp9_slice_instance - represent one vp9 instance +* +* @ctx: pointer to codec's context +* @vpu: VPU instance +* @seq: global picture sequence +* @level: level of current resolution +* @width: width of last picture +* @height: height of last picture +* @frame_type: frame_type of last picture +* @irq: irq to Main CPU or MicroP +* @show_frame: show_frame of last picture +* @dpb: picture information (width/height) for reference +* @mv: mv working buffer +* @seg: segmentation working buffer +* @tile: tile buffer
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c line 443
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c new file +10
-0+* @prob: prob table buffer, used to set/update prob table +* @counts: counts table buffer, used to update prob table +* @frame_ctx: 4 frame context according to VP9 Spec +* @frame_ctx_helper: 4 frame context according to newest kernel spec +* @dirty: state of each frame context +* @init_vsi: vsi used for initialized VP9 instance +* @vsi: vsi used for decoding/flush ... +* @core_vsi: vsi used for Core stage +* @counts_map: used map to counts_helper +* &counts_helper: counts table according to newest kernel spec
Change & into @ to fix:
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:492: warning: Function parameter or member 'counts_helper' not described in 'vdec_vp9_slice_instance'
Quoted 39 lines
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c new file +39
-0+*/ +struct vdec_vp9_slice_instance { +struct mtk_vcodec_ctx *ctx; +struct vdec_vpu_inst vpu; + +int seq; + +enum vdec_vp9_slice_resolution_level level; + +/* for resolution change and get_pic_info */ +unsigned int width; +unsigned int height; + +/* for last_frame_type */ +unsigned int frame_type; +unsigned int irq; + +unsigned int show_frame; + +/* maintain vp9 reference frame state */ +struct vdec_vp9_slice_ref dpb[VB2_MAX_FRAME ]; + +/* +* normal working buffers +* mv[0]/seg[0]/tile/prob/counts is used for LAT +* mv[1]/seg[1] is used for CORE +*/ +struct mtk_vcodec_mem mv[2 ]; +struct mtk_vcodec_mem seg[2 ]; +struct mtk_vcodec_mem tile; +struct mtk_vcodec_mem prob; +struct mtk_vcodec_mem counts; + +/* 4 prob tables */ +struct vdec_vp9_slice_frame_ctx frame_ctx[4 ]; +/*4 helper tables */ +struct v4l2_vp9_frame_context frame_ctx_helper; +unsigned char dirty[4 ]; +
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c line 492
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c new file +10
-0+/* MicroP vsi */ +union { +struct vdec_vp9_slice_init_vsi *init_vsi; +struct vdec_vp9_slice_vsi *vsi; + }; +struct vdec_vp9_slice_vsi *core_vsi; + +struct vdec_vp9_slice_counts_map counts_map; +struct v4l2_vp9_frame_symbol_counts counts_helper; +};
From here ....
Quoted 34 lines
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c new file +34
-0+ +/* +* (2, (0, (1, 3))) +* max level = 2 +*/ +static const signed char vdec_vp9_slice_inter_mode_tree[6 ] = { +-2 ,2 ,0 ,4 ,-1 ,-3 +}; + +/* max level = 6 */ +static const signed char vdec_vp9_slice_intra_mode_tree[18 ] = { +0 ,2 ,-9 ,4 ,-1 ,6 ,8 ,12 ,-2 ,10 ,-4 ,-5 ,-3 ,14 ,-8 ,16 ,-6 ,-7 +}; + +/* max level = 2 */ +static const signed char vdec_vp9_slice_partition_tree[6 ] = { +0 ,2 ,-1 ,4 ,-2 ,-3 +}; + +/* max level = 1 */ +static const signed char vdec_vp9_slice_switchable_interp_tree[4 ] = { +0 ,2 ,-1 ,-2 +}; + +/* max level = 2 */ +static const signed char vdec_vp9_slice_mv_joint_tree[6 ] = { +0 ,2 ,-1 ,4 ,-2 ,-3 +}; + +/* max level = 6 */ +static const signed char vdec_vp9_slice_mv_class_tree[20 ] = { +0 ,2 ,-1 ,4 ,6 ,8 ,-2 ,-3 ,10 ,12 , +-4 ,-5 ,-6 ,14 ,16 ,18 ,-7 ,-8 ,-9 ,-10 +};
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c line 536
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c new file +10
-0+ +/* max level = 0 */ +static const signed char vdec_vp9_slice_mv_class0_tree[2 ] = { +0 ,-1 +}; + +/* max level = 2 */ +static const signed char vdec_vp9_slice_mv_fp_tree[6 ] = { +0 ,2 ,-1 ,4 ,-2 ,-3 +};
All these are unused.
Quoted 690 lines
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c new file +690
-0+ +/* +* all VP9 instances could share this default frame context. +*/ +static struct vdec_vp9_slice_frame_ctx *vdec_vp9_slice_default_frame_ctx; +static DEFINE_MUTEX (vdec_vp9_slice_frame_ctx_lock); + +static int vdec_vp9_slice_core_decode (struct vdec_lat_buf *lat_buf); + +static int vdec_vp9_slice_init_default_frame_ctx (struct vdec_vp9_slice_instance *instance) +{ +struct vdec_vp9_slice_frame_ctx *remote_frame_ctx; +struct vdec_vp9_slice_frame_ctx *frame_ctx; +struct mtk_vcodec_ctx *ctx; +struct vdec_vp9_slice_init_vsi *vsi; +int ret =0 ; + + ctx = instance->ctx; + vsi = instance->vpu.vsi; +if (!ctx || !vsi) +return -EINVAL ; + + remote_frame_ctx =mtk_vcodec_fw_map_dm_addr (ctx->dev->fw_handler, + (u32 )vsi->default_frame_ctx); +if (!remote_frame_ctx) { +mtk_vcodec_err (instance,"failed to map default frame ctx\n" ); +return -EINVAL ; + } + +mutex_lock (&vdec_vp9_slice_frame_ctx_lock); +if (vdec_vp9_slice_default_frame_ctx) + goto out; + + frame_ctx =kmalloc (sizeof (*frame_ctx),GFP_KERNEL ); +if (!frame_ctx) { + ret = -ENOMEM ; + goto out; + } + +memcpy_fromio (frame_ctx, remote_frame_ctx,sizeof (*frame_ctx)); + vdec_vp9_slice_default_frame_ctx = frame_ctx; + +out: +mutex_unlock (&vdec_vp9_slice_frame_ctx_lock); + +return ret; +} + +static int vdec_vp9_slice_alloc_working_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi) +{ +struct mtk_vcodec_ctx *ctx = instance->ctx; +enum vdec_vp9_slice_resolution_level level; +/* super blocks */ +unsigned int max_sb_w; +unsigned int max_sb_h; +unsigned int max_w; +unsigned int max_h; +unsigned int w; +unsigned int h; +size_t size; +int ret; +int i; + + w = vsi->frame.uh.frame_width; + h = vsi->frame.uh.frame_height; + +if (w >VCODEC_DEC_4K_CODED_WIDTH || + h >VCODEC_DEC_4K_CODED_HEIGHT ) { +return -EINVAL ; + }else if (w >MTK_VDEC_MAX_W || h >MTK_VDEC_MAX_H ) { +/* 4K */ + level =VP9_RES_4K ; + max_w =VCODEC_DEC_4K_CODED_WIDTH ; + max_h =VCODEC_DEC_4K_CODED_HEIGHT ; + }else { +/* FHD */ + level =VP9_RES_FHD ; + max_w =MTK_VDEC_MAX_W ; + max_h =MTK_VDEC_MAX_H ; + } + +if (level == instance->level) +return 0 ; + +mtk_vcodec_debug (instance,"resolution level changed, from %u to %u, %ux%u" , + instance->level, level, w, h); + + max_sb_w =DIV_ROUND_UP (max_w,64 ); + max_sb_h =DIV_ROUND_UP (max_h,64 ); + ret = -ENOMEM ; + +/* +* Lat-flush must wait core idle, otherwise core will +* use released buffers +*/ + + size = (max_sb_w * max_sb_h +2 ) *576 ; +for (i =0 ; i <2 ; i++) { +if (instance->mv[i].va) +mtk_vcodec_mem_free (ctx, &instance->mv[i]); + instance->mv[i].size = size; +if (mtk_vcodec_mem_alloc (ctx, &instance->mv[i])) + goto err; + } + + size = (max_sb_w * max_sb_h *32 ) +256 ; +for (i =0 ; i <2 ; i++) { +if (instance->seg[i].va) +mtk_vcodec_mem_free (ctx, &instance->seg[i]); + instance->seg[i].size = size; +if (mtk_vcodec_mem_alloc (ctx, &instance->seg[i])) + goto err; + } + +if (!instance->tile.va) { + instance->tile.size =VP9_TILE_BUF_SIZE ; +if (mtk_vcodec_mem_alloc (ctx, &instance->tile)) + goto err; + } + +if (!instance->prob.va) { + instance->prob.size =VP9_PROB_BUF_SIZE ; +if (mtk_vcodec_mem_alloc (ctx, &instance->prob)) + goto err; + } + +if (!instance->counts.va) { + instance->counts.size =VP9_COUNTS_BUF_SIZE ; +if (mtk_vcodec_mem_alloc (ctx, &instance->counts)) + goto err; + } + + instance->level = level; +return 0 ; + +err: + instance->level =VP9_RES_NONE ; +return ret; +} + +static void vdec_vp9_slice_free_working_buffer (struct vdec_vp9_slice_instance *instance) +{ +struct mtk_vcodec_ctx *ctx = instance->ctx; +int i; + +for (i =0 ; i <ARRAY_SIZE (instance->mv); i++) { +if (instance->mv[i].va) +mtk_vcodec_mem_free (ctx, &instance->mv[i]); + } +for (i =0 ; i <ARRAY_SIZE (instance->seg); i++) { +if (instance->seg[i].va) +mtk_vcodec_mem_free (ctx, &instance->seg[i]); + } +if (instance->tile.va) +mtk_vcodec_mem_free (ctx, &instance->tile); +if (instance->prob.va) +mtk_vcodec_mem_free (ctx, &instance->prob); +if (instance->counts.va) +mtk_vcodec_mem_free (ctx, &instance->counts); + + instance->level =VP9_RES_NONE ; +} + +static void vdec_vp9_slice_vsi_from_remote (struct vdec_vp9_slice_vsi *vsi, +struct vdec_vp9_slice_vsi *remote_vsi, +int skip) +{ +struct vdec_vp9_slice_frame *rf; +struct vdec_vp9_slice_frame *f; + +/* +* compressed header +* dequant +* buffer position +* decode state +*/ +if (!skip) { + rf = &remote_vsi->frame; + f = &vsi->frame; +memcpy_fromio (&f->ch, &rf->ch,sizeof (f->ch)); +memcpy_fromio (&f->uh.dequant, &rf->uh.dequant,sizeof (f->uh.dequant)); +memcpy_fromio (&vsi->trans, &remote_vsi->trans,sizeof (vsi->trans)); + } + +memcpy_fromio (&vsi->state, &remote_vsi->state,sizeof (vsi->state)); +} + +static void vdec_vp9_slice_vsi_to_remote (struct vdec_vp9_slice_vsi *vsi, +struct vdec_vp9_slice_vsi *remote_vsi) +{ +memcpy_toio (remote_vsi, vsi,sizeof (*vsi)); +} + +static int vdec_vp9_slice_tile_offset (int idx,int mi_num,int tile_log2) +{ +int sbs = (mi_num +7 ) >>3 ; +int offset = ((idx * sbs) >> tile_log2) <<3 ; + +return offset < mi_num ? offset : mi_num; +} + +static int vdec_vp9_slice_setup_lat_from_src_buf (struct vdec_vp9_slice_instance *instance, +struct vdec_lat_buf *lat_buf) +{ +struct vb2_v4l2_buffer *src; +struct vb2_v4l2_buffer *dst; + + src =v4l2_m2m_next_src_buf (instance->ctx->m2m_ctx); +if (!src) +return -EINVAL ; + + lat_buf->src_buf_req = src->vb2_buf.req_obj.req; + + dst = &lat_buf->ts_info; +v4l2_m2m_buf_copy_metadata (src, dst, true); +return 0 ; +} + +static void vdec_vp9_slice_setup_hdr (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_uncompressed_header *uh, +struct v4l2_ctrl_vp9_frame *hdr) +{ +int i; + + uh->profile = hdr->profile; + uh->last_frame_type = instance->frame_type; + uh->frame_type = !HDR_FLAG (KEY_FRAME ); + uh->last_show_frame = instance->show_frame; + uh->show_frame =HDR_FLAG (SHOW_FRAME ); + uh->error_resilient_mode =HDR_FLAG (ERROR_RESILIENT ); + uh->bit_depth = hdr->bit_depth; + uh->last_frame_width = instance->width; + uh->last_frame_height = instance->height; + uh->frame_width = hdr->frame_width_minus_1 +1 ; + uh->frame_height = hdr->frame_height_minus_1 +1 ; + uh->intra_only =HDR_FLAG (INTRA_ONLY ); +/* map v4l2 enum to values defined in VP9 spec for firmware */ +switch (hdr->reset_frame_context) { +case V4L2_VP9_RESET_FRAME_CTX_NONE : + uh->reset_frame_context =VP9_RESET_FRAME_CONTEXT_NONE0 ; +break ; +case V4L2_VP9_RESET_FRAME_CTX_SPEC : + uh->reset_frame_context =VP9_RESET_FRAME_CONTEXT_SPEC ; +break ; +case V4L2_VP9_RESET_FRAME_CTX_ALL : + uh->reset_frame_context =VP9_RESET_FRAME_CONTEXT_ALL ; +break ; +default : + uh->reset_frame_context =VP9_RESET_FRAME_CONTEXT_NONE0 ; +break ; + } +/* +* ref_frame_sign_bias specifies the intended direction +* of the motion vector in time for each reference frame. +* - INTRA_FRAME = 0, +* - LAST_FRAME = 1, +* - GOLDEN_FRAME = 2, +* - ALTREF_FRAME = 3, +* ref_frame_sign_bias[INTRA_FRAME] is always 0 +* and VDA only passes another 3 directions +*/ + uh->ref_frame_sign_bias[0 ] =0 ; +for (i =0 ; i <3 ; i++) + uh->ref_frame_sign_bias[i +1 ] = + !!(hdr->ref_frame_sign_bias & (1 << i)); + uh->allow_high_precision_mv =HDR_FLAG (ALLOW_HIGH_PREC_MV ); + uh->interpolation_filter = hdr->interpolation_filter; + uh->refresh_frame_context =HDR_FLAG (REFRESH_FRAME_CTX ); + uh->frame_parallel_decoding_mode =HDR_FLAG (PARALLEL_DEC_MODE ); + uh->frame_context_idx = hdr->frame_context_idx; + +/* tile info */ + uh->tile_cols_log2 = hdr->tile_cols_log2; + uh->tile_rows_log2 = hdr->tile_rows_log2; + + uh->uncompressed_header_size = hdr->uncompressed_header_size; + uh->header_size_in_bytes = hdr->compressed_header_size; +} + +static void vdec_vp9_slice_setup_frame_ctx (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_uncompressed_header *uh, +struct v4l2_ctrl_vp9_frame *hdr) +{ +int error_resilient_mode; +int reset_frame_context; +int key_frame; +int intra_only; +int i; + + key_frame =HDR_FLAG (KEY_FRAME ); + intra_only =HDR_FLAG (INTRA_ONLY ); + error_resilient_mode =HDR_FLAG (ERROR_RESILIENT ); + reset_frame_context = uh->reset_frame_context; + +/* +* according to "6.2 Uncompressed header syntax" in +* "VP9 Bitstream & Decoding Process Specification", +* reset @frame_context_idx when (FrameIsIntra || error_resilient_mode) +*/ +if (key_frame || intra_only || error_resilient_mode) { +/* +* @reset_frame_context specifies +* whether the frame context should be +* reset to default values: +* 0 or 1 means do not reset any frame context +* 2 resets just the context specified in the frame header +* 3 resets all contexts +*/ +if (key_frame || error_resilient_mode || + reset_frame_context ==3 ) { +/* use default table */ +for (i =0 ; i <4 ; i++) + instance->dirty[i] =0 ; + }else if (reset_frame_context ==2 ) { + instance->dirty[uh->frame_context_idx] =0 ; + } + uh->frame_context_idx =0 ; + } +} + +static void vdec_vp9_slice_setup_loop_filter (struct vdec_vp9_slice_uncompressed_header *uh, +struct v4l2_vp9_loop_filter *lf) +{ +int i; + + uh->loop_filter_level = lf->level; + uh->loop_filter_sharpness = lf->sharpness; + uh->loop_filter_delta_enabled =LF_FLAG (DELTA_ENABLED ); +for (i =0 ; i <4 ; i++) + uh->loop_filter_ref_deltas[i] = lf->ref_deltas[i]; +for (i =0 ; i <2 ; i++) + uh->loop_filter_mode_deltas[i] = lf->mode_deltas[i]; +} + +static void vdec_vp9_slice_setup_quantization (struct vdec_vp9_slice_uncompressed_header *uh, +struct v4l2_vp9_quantization *quant) +{ + uh->base_q_idx = quant->base_q_idx; + uh->delta_q_y_dc = quant->delta_q_y_dc; + uh->delta_q_uv_dc = quant->delta_q_uv_dc; + uh->delta_q_uv_ac = quant->delta_q_uv_ac; +} + +static void vdec_vp9_slice_setup_segmentation (struct vdec_vp9_slice_uncompressed_header *uh, +struct v4l2_vp9_segmentation *seg) +{ +int i; +int j; + + uh->segmentation_enabled =SEG_FLAG (ENABLED ); + uh->segmentation_update_map =SEG_FLAG (UPDATE_MAP ); +for (i =0 ; i <7 ; i++) + uh->segmentation_tree_probs[i] = seg->tree_probs[i]; + uh->segmentation_temporal_udpate =SEG_FLAG (TEMPORAL_UPDATE ); +for (i =0 ; i <3 ; i++) + uh->segmentation_pred_prob[i] = seg->pred_probs[i]; + uh->segmentation_update_data =SEG_FLAG (UPDATE_DATA ); + uh->segmentation_abs_or_delta_update =SEG_FLAG (ABS_OR_DELTA_UPDATE ); +for (i =0 ; i <8 ; i++) { + uh->feature_enabled[i] = seg->feature_enabled[i]; +for (j =0 ; j <4 ; j++) + uh->feature_value[i][j] = seg->feature_data[i][j]; + } +} + +static int vdec_vp9_slice_setup_tile (struct vdec_vp9_slice_vsi *vsi, +struct v4l2_ctrl_vp9_frame *hdr) +{ +unsigned int rows_log2; +unsigned int cols_log2; +unsigned int rows; +unsigned int cols; +unsigned int mi_rows; +unsigned int mi_cols; +struct vdec_vp9_slice_tiles *tiles; +int offset; +int start; +int end; +int i; + + rows_log2 = hdr->tile_rows_log2; + cols_log2 = hdr->tile_cols_log2; + rows =1 << rows_log2; + cols =1 << cols_log2; + tiles = &vsi->frame.tiles; + tiles->actual_rows =0 ; + +if (rows >4 || cols >64 ) +return -EINVAL ; + +/* setup mi rows/cols information */ + mi_rows = (hdr->frame_height_minus_1 +1 +7 ) >>3 ; + mi_cols = (hdr->frame_width_minus_1 +1 +7 ) >>3 ; + +for (i =0 ; i < rows; i++) { + start =vdec_vp9_slice_tile_offset (i, mi_rows, rows_log2); + end =vdec_vp9_slice_tile_offset (i +1 , mi_rows, rows_log2); + offset = end - start; + tiles->mi_rows[i] = (offset +7 ) >>3 ; +if (tiles->mi_rows[i]) + tiles->actual_rows++; + } + +for (i =0 ; i < cols; i++) { + start =vdec_vp9_slice_tile_offset (i, mi_cols, cols_log2); + end =vdec_vp9_slice_tile_offset (i +1 , mi_cols, cols_log2); + offset = end - start; + tiles->mi_cols[i] = (offset +7 ) >>3 ; + } + +return 0 ; +} + +static void vdec_vp9_slice_setup_state (struct vdec_vp9_slice_vsi *vsi) +{ +memset (&vsi->state,0 ,sizeof (vsi->state)); +} + +static void vdec_vp9_slice_setup_ref_idx (struct vdec_vp9_slice_pfc *pfc, +struct v4l2_ctrl_vp9_frame *hdr) +{ + pfc->ref_idx[0 ] = hdr->last_frame_ts; + pfc->ref_idx[1 ] = hdr->golden_frame_ts; + pfc->ref_idx[2 ] = hdr->alt_frame_ts; +} + +static int vdec_vp9_slice_setup_pfc (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_pfc *pfc) +{ +struct v4l2_ctrl_vp9_frame *hdr; +struct vdec_vp9_slice_uncompressed_header *uh; +struct v4l2_ctrl *hdr_ctrl; +struct vdec_vp9_slice_vsi *vsi; +int ret; + +/* frame header */ + hdr_ctrl =v4l2_ctrl_find (&instance->ctx->ctrl_hdl,V4L2_CID_STATELESS_VP9_FRAME ); +if (!hdr_ctrl || !hdr_ctrl->p_cur.p) +return -EINVAL ; + + hdr = hdr_ctrl->p_cur.p; + vsi = &pfc->vsi; + uh = &vsi->frame.uh; + +/* setup vsi information */ +vdec_vp9_slice_setup_hdr (instance, uh, hdr); +vdec_vp9_slice_setup_frame_ctx (instance, uh, hdr); +vdec_vp9_slice_setup_loop_filter (uh, &hdr->lf); +vdec_vp9_slice_setup_quantization (uh, &hdr->quant); +vdec_vp9_slice_setup_segmentation (uh, &hdr->seg); + ret =vdec_vp9_slice_setup_tile (vsi, hdr); +if (ret) +return ret; +vdec_vp9_slice_setup_state (vsi); + +/* core stage needs buffer index to get ref y/c ... */ +vdec_vp9_slice_setup_ref_idx (pfc, hdr); + + pfc->seq = instance->seq; + instance->seq++; + +return 0 ; +} + +static int vdec_vp9_slice_setup_lat_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi, +struct mtk_vcodec_mem *bs, +struct vdec_lat_buf *lat_buf) +{ +int i; + + vsi->bs.buf.dma_addr = bs->dma_addr; + vsi->bs.buf.size = bs->size; + vsi->bs.frame.dma_addr = bs->dma_addr; + vsi->bs.frame.size = bs->size; + +for (i =0 ; i <2 ; i++) { + vsi->mv[i].dma_addr = instance->mv[i].dma_addr; + vsi->mv[i].size = instance->mv[i].size; + } +for (i =0 ; i <2 ; i++) { + vsi->seg[i].dma_addr = instance->seg[i].dma_addr; + vsi->seg[i].size = instance->seg[i].size; + } + vsi->tile.dma_addr = instance->tile.dma_addr; + vsi->tile.size = instance->tile.size; + vsi->prob.dma_addr = instance->prob.dma_addr; + vsi->prob.size = instance->prob.size; + vsi->counts.dma_addr = instance->counts.dma_addr; + vsi->counts.size = instance->counts.size; + + vsi->ube.dma_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr; + vsi->ube.size = lat_buf->ctx->msg_queue.wdma_addr.size; + vsi->trans.dma_addr = lat_buf->ctx->msg_queue.wdma_wptr_addr; +/* used to store trans end */ + vsi->trans.dma_addr_end = lat_buf->ctx->msg_queue.wdma_rptr_addr; + vsi->err_map.dma_addr = lat_buf->wdma_err_addr.dma_addr; + vsi->err_map.size = lat_buf->wdma_err_addr.size; + + vsi->row_info.buf =0 ; + vsi->row_info.size =0 ; + +return 0 ; +} + +static int vdec_vp9_slice_setup_prob_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi) +{ +struct vdec_vp9_slice_frame_ctx *frame_ctx; +struct vdec_vp9_slice_uncompressed_header *uh; + + uh = &vsi->frame.uh; + +mtk_vcodec_debug (instance,"ctx dirty %u idx %d\n" , + instance->dirty[uh->frame_context_idx], + uh->frame_context_idx); + +if (instance->dirty[uh->frame_context_idx]) + frame_ctx = &instance->frame_ctx[uh->frame_context_idx]; +else + frame_ctx = vdec_vp9_slice_default_frame_ctx; +memcpy (instance->prob.va, frame_ctx,sizeof (*frame_ctx)); + +return 0 ; +} + +static void vdec_vp9_slice_setup_seg_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi, +struct mtk_vcodec_mem *buf) +{ +struct vdec_vp9_slice_uncompressed_header *uh; + +/* reset segment buffer */ + uh = &vsi->frame.uh; +if (uh->frame_type ==0 || + uh->intra_only || + uh->error_resilient_mode || + uh->frame_width != instance->width || + uh->frame_height != instance->height) { +mtk_vcodec_debug (instance,"reset seg\n" ); +memset (buf->va,0 , buf->size); + } +} + +/* +* parse tiles according to `6.4 Decode tiles syntax` +* in "vp9-bitstream-specification" +* +* frame contains uncompress header, compressed header and several tiles. +* this function parses tiles' position and size, stores them to tile buffer +* for decoding. +*/ +static int vdec_vp9_slice_setup_tile_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi, +struct mtk_vcodec_mem *bs) +{ +struct vdec_vp9_slice_uncompressed_header *uh; +unsigned int rows_log2; +unsigned int cols_log2; +unsigned int rows; +unsigned int cols; +unsigned int mi_row; +unsigned int mi_col; +unsigned int offset; +unsigned int pa; +unsigned int size; +struct vdec_vp9_slice_tiles *tiles; +unsigned char *pos; +unsigned char *end; +unsigned char *va; +unsigned int *tb; +int i; +int j; + + uh = &vsi->frame.uh; + rows_log2 = uh->tile_rows_log2; + cols_log2 = uh->tile_cols_log2; + rows =1 << rows_log2; + cols =1 << cols_log2; + +if (rows >4 || cols >64 ) { +mtk_vcodec_err (instance,"tile_rows %u tile_cols %u\n" , + rows, cols); +return -EINVAL ; + } + + offset = uh->uncompressed_header_size + + uh->header_size_in_bytes; +if (bs->size <= offset) { +mtk_vcodec_err (instance,"bs size %zu tile offset %u\n" , + bs->size, offset); +return -EINVAL ; + } + + tiles = &vsi->frame.tiles; +/* setup tile buffer */ + + va = (unsigned char *)bs->va; + pos = va + offset; + end = va + bs->size; +/* truncated */ + pa = (unsigned int )bs->dma_addr + offset; + tb = instance->tile.va; +for (i =0 ; i < rows; i++) { +for (j =0 ; j < cols; j++) { +if (i == rows -1 && + j == cols -1 ) { + size = (unsigned int )(end - pos); + }else { +if (end - pos <4 ) +return -EINVAL ; + + size = (pos[0 ] <<24 ) | (pos[1 ] <<16 ) | + (pos[2 ] <<8 ) | pos[3 ]; + pos +=4 ; + pa +=4 ; + offset +=4 ; +if (end - pos < size) +return -EINVAL ; + } + tiles->size[i][j] = size; +if (tiles->mi_rows[i]) { + *tb++ = (size <<3 ) + ((offset <<3 ) &0x7f ); + *tb++ = pa & ~0xf ; + *tb++ = (pa <<3 ) &0x7f ; + mi_row = (tiles->mi_rows[i] -1 ) &0x1ff ; + mi_col = (tiles->mi_cols[j] -1 ) &0x3f ; + *tb++ = (mi_row <<6 ) + mi_col; + } + pos += size; + pa += size; + offset += size; + } + } + +return 0 ; +} + +static int vdec_vp9_slice_setup_lat (struct vdec_vp9_slice_instance *instance, +struct mtk_vcodec_mem *bs, +struct vdec_lat_buf *lat_buf, +struct vdec_vp9_slice_pfc *pfc) +{ +struct vdec_vp9_slice_vsi *vsi = &pfc->vsi; +int ret; + + ret =vdec_vp9_slice_setup_lat_from_src_buf (instance, lat_buf); +if (ret) + goto err; + + ret =vdec_vp9_slice_setup_pfc (instance, pfc); +if (ret) + goto err; + + ret =vdec_vp9_slice_alloc_working_buffer (instance, vsi); +if (ret) + goto err; + + ret =vdec_vp9_slice_setup_lat_buffer (instance, vsi, bs, lat_buf); +if (ret) + goto err; + +vdec_vp9_slice_setup_seg_buffer (instance, vsi, &instance->seg[0 ]); + +/* setup prob/tile buffers for LAT */ + + ret =vdec_vp9_slice_setup_prob_buffer (instance, vsi); +if (ret) + goto err; + + ret =vdec_vp9_slice_setup_tile_buffer (instance, vsi, bs); +if (ret) + goto err; + +return 0 ; + +err: +return ret; +} + +static +void vdec_vp9_slice_map_counts_eob_coef (unsigned int i,unsigned int j,unsigned int k, +struct vdec_vp9_slice_frame_counts *counts, +struct v4l2_vp9_frame_symbol_counts *counts_helper) +{ +u32 l, m; + +/* +* helper eo -> mtk eo
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c line 1236
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c new file +10
-0+* helpre e1 -> mtk c3 +* helper c0 -> c0 +* helper c1 -> c1 +* helper c2 -> c2 +*/ +for (l =0 ; l <6 ; l++) { +for (m =0 ; m <VP9_BAND_6 (l); m++) { +if (l ==0 ) { + counts_helper->coeff[i][j][k][l][m] = + &counts->coef_probs[i][j][k].band_0[m];
The missing a cast from (u32 (*)[4]) -> (u32 (*)[3]), the cast is safe otherwise as long as the forth item is just HW padding. If its used by the HW for special purpose, consider initializing it.
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c line 1243
Quoted 7 lines
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c new file +7
-0+ counts_helper->eob[i][j][k][l][m][0 ] = + &counts->eob_branch[i][j][k].band_0[m]; + counts_helper->eob[i][j][k][l][m][1 ] = + &counts->coef_probs[i][j][k].band_0[m][3 ]; + }else { + counts_helper->coeff[i][j][k][l][m] = + &counts->coef_probs[i][j][k].band_1_5[l -1 ][m];
Same here.
Quoted 4 lines
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c new file +4
-0+ counts_helper->eob[i][j][k][l][m][0 ] = + &counts->eob_branch[i][j][k].band_1_5[l -1 ][m]; + counts_helper->eob[i][j][k][l][m][1 ] = + &counts->coef_probs[i][j][k].band_1_5[l -1 ][m][3 ];
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c line 1257
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c new file +10
-0+ } + } + } +} + +static void vdec_vp9_slice_counts_map_helper (struct vdec_vp9_slice_counts_map *counts_map, +struct vdec_vp9_slice_frame_counts *counts, +struct v4l2_vp9_frame_symbol_counts *counts_helper) +{ +int i, j, k, l, m;
l and m are unused.
Quoted 842 lines
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c new file +815
-0+ + counts_helper->partition = &counts->partition; + counts_helper->intra_inter = &counts->intra_inter; + counts_helper->tx32p = &counts->tx_p32x32; + counts_helper->tx16p = &counts->tx_p16x16; + counts_helper->tx8p = &counts->tx_p8x8; + counts_helper->uv_mode = &counts->uv_mode; + + counts_helper->comp = &counts->comp_inter; + counts_helper->comp_ref = &counts->comp_ref; + counts_helper->single_ref = &counts->single_ref; + counts_helper->mv_mode = &counts->inter_mode; + counts_helper->mv_joint = &counts->joint; + +for (i =0 ; i <ARRAY_SIZE (counts_map->skip); i++) +memcpy (counts_map->skip[i], counts->skip[i], +sizeof (counts_map->skip[0 ])); + counts_helper->skip = &counts_map->skip; + +for (i =0 ; i <ARRAY_SIZE (counts_map->y_mode); i++) +memcpy (counts_map->y_mode[i], counts->y_mode[i], +sizeof (counts_map->y_mode[0 ])); + counts_helper->y_mode = &counts_map->y_mode; + +for (i =0 ; i <ARRAY_SIZE (counts_map->filter); i++) +memcpy (counts_map->filter[i], counts->switchable_interp[i], +sizeof (counts_map->filter[0 ])); + counts_helper->filter = &counts_map->filter; + +for (i =0 ; i <ARRAY_SIZE (counts_map->sign); i++) +memcpy (counts_map->sign[i], counts->mvcomp[i].sign, +sizeof (counts_map->sign[0 ])); + counts_helper->sign = &counts_map->sign; + +for (i =0 ; i <ARRAY_SIZE (counts_map->classes); i++) +memcpy (counts_map->classes[i], counts->mvcomp[i].classes, +sizeof (counts_map->classes[0 ])); + counts_helper->classes = &counts_map->classes; + +for (i =0 ; i <ARRAY_SIZE (counts_map->class0); i++) +memcpy (counts_map->class0[i], counts->mvcomp[i].class0, +sizeof (counts_map->class0[0 ])); + counts_helper->class0 = &counts_map->class0; + +for (i =0 ; i <ARRAY_SIZE (counts_map->bits); i++) +for (j =0 ; j <ARRAY_SIZE (counts_map->bits[0 ]); j++) +memcpy (counts_map->bits[i][j], counts->mvcomp[i].bits[j], +sizeof (counts_map->bits[0 ][0 ])); + counts_helper->bits = &counts_map->bits; + +for (i =0 ; i <ARRAY_SIZE (counts_map->class0_fp); i++) +for (j =0 ; j <ARRAY_SIZE (counts_map->class0_fp[0 ]); j++) +memcpy (counts_map->class0_fp[i][j], counts->mvcomp[i].class0_fp[j], +sizeof (counts_map->class0_fp[0 ][0 ])); + counts_helper->class0_fp = &counts_map->class0_fp; + +for (i =0 ; i <ARRAY_SIZE (counts_map->fp); i++) +memcpy (counts_map->fp[i], counts->mvcomp[i].fp, +sizeof (counts_map->fp[0 ])); + counts_helper->fp = &counts_map->fp; + +for (i =0 ; i <ARRAY_SIZE (counts_map->class0_hp); i++) +memcpy (counts_map->class0_hp[i], counts->mvcomp[i].class0_hp, +sizeof (counts_map->class0_hp[0 ])); + counts_helper->class0_hp = &counts_map->class0_hp; + +for (i =0 ; i <ARRAY_SIZE (counts_map->hp); i++) +memcpy (counts_map->hp[i], counts->mvcomp[i].hp,sizeof (counts_map->hp[0 ])); + + counts_helper->hp = &counts_map->hp; + +for (i =0 ; i <4 ; i++) +for (j =0 ; j <2 ; j++) +for (k =0 ; k <2 ; k++) +vdec_vp9_slice_map_counts_eob_coef (i, j, k, counts, counts_helper); +} + +static void vdec_vp9_slice_map_to_coef (unsigned int i,unsigned int j,unsigned int k, +struct vdec_vp9_slice_frame_ctx *frame_ctx, +struct v4l2_vp9_frame_context *frame_ctx_helper) +{ +u32 l, m; + +for (l =0 ; l <ARRAY_SIZE (frame_ctx_helper->coef[0 ][0 ][0 ]); l++) { +for (m =0 ; m <VP9_BAND_6 (l); m++) { +memcpy (frame_ctx_helper->coef[i][j][k][l][m], + frame_ctx->coef_probs[i][j][k][l].probs[m], +sizeof (frame_ctx_helper->coef[i][j][k][l][0 ])); + } + } +} + +static void vdec_vp9_slice_map_from_coef (unsigned int i,unsigned int j,unsigned int k, +struct vdec_vp9_slice_frame_ctx *frame_ctx, +struct v4l2_vp9_frame_context *frame_ctx_helper) +{ +u32 l, m; + +for (l =0 ; l <ARRAY_SIZE (frame_ctx_helper->coef[0 ][0 ][0 ]); l++) { +for (m =0 ; m <VP9_BAND_6 (l); m++) { +memcpy (frame_ctx->coef_probs[i][j][k][l].probs[m], + frame_ctx_helper->coef[i][j][k][l][m], +sizeof (frame_ctx_helper->coef[i][j][k][l][0 ])); + } + } +} + +static +void vdec_vp9_slice_framectx_map_helper (bool frame_is_intra, +struct vdec_vp9_slice_frame_ctx *pre_frame_ctx, +struct vdec_vp9_slice_frame_ctx *frame_ctx, +struct v4l2_vp9_frame_context *frame_ctx_helper) +{ +struct v4l2_vp9_frame_mv_context *mv = &frame_ctx_helper->mv; +u32 i, j, k; + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->coef); i++) +for (j =0 ; j <ARRAY_SIZE (frame_ctx_helper->coef[0 ]); j++) +for (k =0 ; k <ARRAY_SIZE (frame_ctx_helper->coef[0 ][0 ]); k++) +vdec_vp9_slice_map_to_coef (i, j, k, pre_frame_ctx, + frame_ctx_helper); + +/* +* use previous prob when frame is not intra or +* we should use the prob updated by the compressed header parse +*/ +if (!frame_is_intra) + frame_ctx = pre_frame_ctx; + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx8); i++) +memcpy (frame_ctx_helper->tx8[i], frame_ctx->tx_p8x8[i], +sizeof (frame_ctx_helper->tx8[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx16); i++) +memcpy (frame_ctx_helper->tx16[i], frame_ctx->tx_p16x16[i], +sizeof (frame_ctx_helper->tx16[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx32); i++) +memcpy (frame_ctx_helper->tx32[i], frame_ctx->tx_p32x32[i], +sizeof (frame_ctx_helper->tx32[0 ])); + +memcpy (frame_ctx_helper->skip, frame_ctx->skip_probs,sizeof (frame_ctx_helper->skip)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->inter_mode); i++) +memcpy (frame_ctx_helper->inter_mode[i], frame_ctx->inter_mode_probs[i], +sizeof (frame_ctx_helper->inter_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->interp_filter); i++) +memcpy (frame_ctx_helper->interp_filter[i], frame_ctx->switch_interp_prob[i], +sizeof (frame_ctx_helper->interp_filter[0 ])); + +memcpy (frame_ctx_helper->is_inter, frame_ctx->intra_inter_prob, +sizeof (frame_ctx_helper->is_inter)); + +memcpy (frame_ctx_helper->comp_mode, frame_ctx->comp_inter_prob, +sizeof (frame_ctx_helper->comp_mode)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->single_ref); i++) +memcpy (frame_ctx_helper->single_ref[i], frame_ctx->single_ref_prob[i], +sizeof (frame_ctx_helper->single_ref[0 ])); + +memcpy (frame_ctx_helper->comp_ref, frame_ctx->comp_ref_prob, +sizeof (frame_ctx_helper->comp_ref)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->y_mode); i++) +memcpy (frame_ctx_helper->y_mode[i], frame_ctx->y_mode_prob[i], +sizeof (frame_ctx_helper->y_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->uv_mode); i++) +memcpy (frame_ctx_helper->uv_mode[i], frame_ctx->uv_mode_prob[i], +sizeof (frame_ctx_helper->uv_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->partition); i++) +memcpy (frame_ctx_helper->partition[i], frame_ctx->partition_prob[i], +sizeof (frame_ctx_helper->partition[0 ])); + +memcpy (mv->joint, frame_ctx->joint,sizeof (mv->joint)); + +for (i =0 ; i <ARRAY_SIZE (mv->sign); i++) + mv->sign[i] = frame_ctx->sign_classes[i].sign; + +for (i =0 ; i <ARRAY_SIZE (mv->classes); i++) +memcpy (mv->classes[i], frame_ctx->sign_classes[i].classes, +sizeof (mv->classes[i])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_bit); i++) + mv->class0_bit[i] = frame_ctx->class0_bits[i].class0[0 ]; + +for (i =0 ; i <ARRAY_SIZE (mv->bits); i++) +memcpy (mv->bits[i], frame_ctx->class0_bits[i].bits,sizeof (mv->bits[0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_fr); i++) +for (j =0 ; j <ARRAY_SIZE (mv->class0_fr[0 ]); j++) +memcpy (mv->class0_fr[i][j], frame_ctx->class0_fp_hp[i].class0_fp[j], +sizeof (mv->class0_fr[0 ][0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->fr); i++) +memcpy (mv->fr[i], frame_ctx->class0_fp_hp[i].fp,sizeof (mv->fr[0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_hp); i++) + mv->class0_hp[i] = frame_ctx->class0_fp_hp[i].class0_hp; + +for (i =0 ; i <ARRAY_SIZE (mv->hp); i++) + mv->hp[i] = frame_ctx->class0_fp_hp[i].hp; +} + +static void vdec_vp9_slice_helper_map_framectx (struct v4l2_vp9_frame_context *frame_ctx_helper, +struct vdec_vp9_slice_frame_ctx *frame_ctx) +{ +struct v4l2_vp9_frame_mv_context *mv = &frame_ctx_helper->mv; +u32 i, j, k; + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx8); i++) +memcpy (frame_ctx->tx_p8x8[i], frame_ctx_helper->tx8[i], +sizeof (frame_ctx_helper->tx8[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx16); i++) +memcpy (frame_ctx->tx_p16x16[i], frame_ctx_helper->tx16[i], +sizeof (frame_ctx_helper->tx16[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx32); i++) +memcpy (frame_ctx->tx_p32x32[i], frame_ctx_helper->tx32[i], +sizeof (frame_ctx_helper->tx32[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->coef); i++) +for (j =0 ; j <ARRAY_SIZE (frame_ctx_helper->coef[0 ]); j++) +for (k =0 ; k <ARRAY_SIZE (frame_ctx_helper->coef[0 ][0 ]); k++) +vdec_vp9_slice_map_from_coef (i, j, k, frame_ctx, + frame_ctx_helper); + +memcpy (frame_ctx->skip_probs, frame_ctx_helper->skip,sizeof (frame_ctx_helper->skip)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->inter_mode); i++) +memcpy (frame_ctx->inter_mode_probs[i], frame_ctx_helper->inter_mode[i], +sizeof (frame_ctx_helper->inter_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->interp_filter); i++) +memcpy (frame_ctx->switch_interp_prob[i], frame_ctx_helper->interp_filter[i], +sizeof (frame_ctx_helper->interp_filter[0 ])); + +memcpy (frame_ctx->intra_inter_prob, frame_ctx_helper->is_inter, +sizeof (frame_ctx_helper->is_inter)); + +memcpy (frame_ctx->comp_inter_prob, frame_ctx_helper->comp_mode, +sizeof (frame_ctx_helper->comp_mode)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->single_ref); i++) +memcpy (frame_ctx->single_ref_prob[i], frame_ctx_helper->single_ref[i], +sizeof (frame_ctx_helper->single_ref[0 ])); + +memcpy (frame_ctx->comp_ref_prob, frame_ctx_helper->comp_ref, +sizeof (frame_ctx_helper->comp_ref)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->y_mode); i++) +memcpy (frame_ctx->y_mode_prob[i], frame_ctx_helper->y_mode[i], +sizeof (frame_ctx_helper->y_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->uv_mode); i++) +memcpy (frame_ctx->uv_mode_prob[i], frame_ctx_helper->uv_mode[i], +sizeof (frame_ctx_helper->uv_mode[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->partition); i++) +memcpy (frame_ctx->partition_prob[i], frame_ctx_helper->partition[i], +sizeof (frame_ctx_helper->partition[0 ])); + +memcpy (frame_ctx->joint, mv->joint,sizeof (mv->joint)); + +for (i =0 ; i <ARRAY_SIZE (mv->sign); i++) + frame_ctx->sign_classes[i].sign = mv->sign[i]; + +for (i =0 ; i <ARRAY_SIZE (mv->classes); i++) +memcpy (frame_ctx->sign_classes[i].classes, mv->classes[i], +sizeof (mv->classes[i])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_bit); i++) + frame_ctx->class0_bits[i].class0[0 ] = mv->class0_bit[i]; + +for (i =0 ; i <ARRAY_SIZE (mv->bits); i++) +memcpy (frame_ctx->class0_bits[i].bits, mv->bits[i],sizeof (mv->bits[0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_fr); i++) +for (j =0 ; j <ARRAY_SIZE (mv->class0_fr[0 ]); j++) +memcpy (frame_ctx->class0_fp_hp[i].class0_fp[j], mv->class0_fr[i][j], +sizeof (mv->class0_fr[0 ][0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->fr); i++) +memcpy (frame_ctx->class0_fp_hp[i].fp, mv->fr[i],sizeof (mv->fr[0 ])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_hp); i++) + frame_ctx->class0_fp_hp[i].class0_hp = mv->class0_hp[i]; + +for (i =0 ; i <ARRAY_SIZE (mv->hp); i++) + frame_ctx->class0_fp_hp[i].hp = mv->hp[i]; +} + +static int vdec_vp9_slice_update_prob (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_vsi *vsi) +{ +struct vdec_vp9_slice_frame_ctx *pre_frame_ctx; +struct v4l2_vp9_frame_context *pre_frame_ctx_helper; +struct vdec_vp9_slice_frame_ctx *frame_ctx; +struct vdec_vp9_slice_frame_counts *counts; +struct v4l2_vp9_frame_symbol_counts *counts_helper; +struct vdec_vp9_slice_uncompressed_header *uh; +bool frame_is_intra; +bool use_128; + + uh = &vsi->frame.uh; + pre_frame_ctx = &instance->frame_ctx[uh->frame_context_idx]; + pre_frame_ctx_helper = &instance->frame_ctx_helper; + frame_ctx = (struct vdec_vp9_slice_frame_ctx *)instance->prob.va; + counts = (struct vdec_vp9_slice_frame_counts *)instance->counts.va; + counts_helper = &instance->counts_helper; + +if (!uh->refresh_frame_context) +return 0 ; + +if (!uh->frame_parallel_decoding_mode) { +vdec_vp9_slice_counts_map_helper (&instance->counts_map, counts, counts_helper); + + frame_is_intra = !vsi->frame.uh.frame_type || vsi->frame.uh.intra_only; +/* check default prob */ +if (!instance->dirty[uh->frame_context_idx]) +vdec_vp9_slice_framectx_map_helper (frame_is_intra, + vdec_vp9_slice_default_frame_ctx, + frame_ctx, + pre_frame_ctx_helper); +else +vdec_vp9_slice_framectx_map_helper (frame_is_intra, + pre_frame_ctx, + frame_ctx, + pre_frame_ctx_helper); + + use_128 = !frame_is_intra && !vsi->frame.uh.last_frame_type; +v4l2_vp9_adapt_coef_probs (pre_frame_ctx_helper, + counts_helper, + use_128, + frame_is_intra); +if (!frame_is_intra) +v4l2_vp9_adapt_noncoef_probs (pre_frame_ctx_helper, + counts_helper, +V4L2_VP9_REFERENCE_MODE_SINGLE_REFERENCE , + vsi->frame.uh.interpolation_filter, + vsi->frame.ch.tx_mode, + vsi->frame.uh.allow_high_precision_mv ? +V4L2_VP9_FRAME_FLAG_ALLOW_HIGH_PREC_MV :0 ); +vdec_vp9_slice_helper_map_framectx (pre_frame_ctx_helper, pre_frame_ctx); + }else { +memcpy (pre_frame_ctx, frame_ctx,sizeof (*frame_ctx)); + } + + instance->dirty[uh->frame_context_idx] =1 ; + +return 0 ; +} + +static int vdec_vp9_slice_update_lat (struct vdec_vp9_slice_instance *instance, +struct vdec_lat_buf *lat_buf, +struct vdec_vp9_slice_pfc *pfc) +{ +struct vdec_vp9_slice_vsi *vsi; + + vsi = &pfc->vsi; +memcpy (&pfc->state[0 ], &vsi->state,sizeof (vsi->state)); + +mtk_vcodec_debug (instance,"Frame %u LAT CRC 0x%08x %lx %lx\n" , + pfc->seq, vsi->state.crc[0 ], + (unsigned long )vsi->trans.dma_addr, + (unsigned long )vsi->trans.dma_addr_end); + +/* buffer full, need to re-decode */ +if (vsi->state.full) { +/* buffer not enough */ +if (vsi->trans.dma_addr_end - vsi->trans.dma_addr == + vsi->ube.size) +return -ENOMEM ; +return -EAGAIN ; + } + +vdec_vp9_slice_update_prob (instance, vsi); + + instance->width = vsi->frame.uh.frame_width; + instance->height = vsi->frame.uh.frame_height; + instance->frame_type = vsi->frame.uh.frame_type; + instance->show_frame = vsi->frame.uh.show_frame; + +return 0 ; +} + +static int vdec_vp9_slice_setup_core_to_dst_buf (struct vdec_vp9_slice_instance *instance, +struct vdec_lat_buf *lat_buf) +{ +struct vb2_v4l2_buffer *dst; + + dst =v4l2_m2m_next_dst_buf (instance->ctx->m2m_ctx); +if (!dst) +return -EINVAL ; + +v4l2_m2m_buf_copy_metadata (&lat_buf->ts_info, dst, true); +return 0 ; +} + +static int vdec_vp9_slice_setup_core_buffer (struct vdec_vp9_slice_instance *instance, +struct vdec_vp9_slice_pfc *pfc, +struct vdec_vp9_slice_vsi *vsi, +struct vdec_fb *fb, +struct vdec_lat_buf *lat_buf) +{ +struct vb2_buffer *vb; +struct vb2_queue *vq; +struct vdec_vp9_slice_reference *ref; +int plane; +int size; +int idx; +int w; +int h; +int i; + + plane = instance->ctx->q_data[MTK_Q_DATA_DST ].fmt->num_planes; + w = vsi->frame.uh.frame_width; + h = vsi->frame.uh.frame_height; + size =ALIGN (w,64 ) *ALIGN (h,64 ); + +/* frame buffer */ + vsi->fb.y.dma_addr = fb->base_y.dma_addr; +if (plane ==1 ) + vsi->fb.c.dma_addr = fb->base_y.dma_addr + size; +else + vsi->fb.c.dma_addr = fb->base_c.dma_addr; + +/* reference buffers */ + vq =v4l2_m2m_get_vq (instance->ctx->m2m_ctx, +V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ); +if (!vq) +return -EINVAL ; + +/* get current output buffer */ + vb = &v4l2_m2m_next_dst_buf (instance->ctx->m2m_ctx)->vb2_buf; +if (!vb) +return -EINVAL ; + +/* update internal buffer's width/height */ +for (i =0 ; i < vq->num_buffers; i++) { +if (vb == vq->bufs[i]) { + instance->dpb[i].width = w; + instance->dpb[i].height = h; +break ; + } + } + +/* +* get buffer's width/height from instance +* get buffer address from vb2buf +*/ +for (i =0 ; i <3 ; i++) { + ref = &vsi->frame.ref[i]; + idx =vb2_find_timestamp (vq, pfc->ref_idx[i],0 ); +if (idx <0 ) { + ref->frame_width = w; + ref->frame_height = h; +memset (&vsi->ref[i],0 ,sizeof (vsi->ref[i])); + }else { + ref->frame_width = instance->dpb[idx].width; + ref->frame_height = instance->dpb[idx].height; + vb = vq->bufs[idx]; + vsi->ref[i].y.dma_addr = +vb2_dma_contig_plane_dma_addr (vb,0 ); +if (plane ==1 ) + vsi->ref[i].c.dma_addr = + vsi->ref[i].y.dma_addr + size; +else + vsi->ref[i].c.dma_addr = +vb2_dma_contig_plane_dma_addr (vb,1 ); + } + } + +return 0 ; +} + +static int vdec_vp9_slice_setup_core (struct vdec_vp9_slice_instance *instance, +struct vdec_fb *fb, +struct vdec_lat_buf *lat_buf, +struct vdec_vp9_slice_pfc *pfc) +{ +struct vdec_vp9_slice_vsi *vsi = &pfc->vsi; +int ret; + +vdec_vp9_slice_setup_state (vsi); + + ret =vdec_vp9_slice_setup_core_to_dst_buf (instance, lat_buf); +if (ret) + goto err; + + ret =vdec_vp9_slice_setup_core_buffer (instance, pfc, vsi, fb, lat_buf); +if (ret) + goto err; + +vdec_vp9_slice_setup_seg_buffer (instance, vsi, &instance->seg[1 ]); + +return 0 ; + +err: +return ret; +} + +static int vdec_vp9_slice_update_core (struct vdec_vp9_slice_instance *instance, +struct vdec_lat_buf *lat_buf, +struct vdec_vp9_slice_pfc *pfc) +{ +struct vdec_vp9_slice_vsi *vsi; + + vsi = &pfc->vsi; +memcpy (&pfc->state[1 ], &vsi->state,sizeof (vsi->state)); + +mtk_vcodec_debug (instance,"Frame %u Y_CRC %08x %08x %08x %08x\n" , + pfc->seq, + vsi->state.crc[0 ], vsi->state.crc[1 ], + vsi->state.crc[2 ], vsi->state.crc[3 ]); +mtk_vcodec_debug (instance,"Frame %u C_CRC %08x %08x %08x %08x\n" , + pfc->seq, + vsi->state.crc[4 ], vsi->state.crc[5 ], + vsi->state.crc[6 ], vsi->state.crc[7 ]); + +return 0 ; +} + +static int vdec_vp9_slice_init (struct mtk_vcodec_ctx *ctx) +{ +struct vdec_vp9_slice_instance *instance; +struct vdec_vp9_slice_init_vsi *vsi; +int ret; + + instance =kzalloc (sizeof (*instance),GFP_KERNEL ); +if (!instance) +return -ENOMEM ; + + instance->ctx = ctx; + instance->vpu.id =SCP_IPI_VDEC_LAT ; + instance->vpu.core_id =SCP_IPI_VDEC_CORE ; + instance->vpu.ctx = ctx; + instance->vpu.codec_type = ctx->current_codec; + + ret =vpu_dec_init (&instance->vpu); +if (ret) { +mtk_vcodec_err (instance,"failed to init vpu dec, ret %d\n" , ret); + goto error_vpu_init; + } + +/* init vsi and global flags */ + + vsi = instance->vpu.vsi; +if (!vsi) { +mtk_vcodec_err (instance,"failed to get VP9 vsi\n" ); + ret = -EINVAL ; + goto error_vsi; + } + instance->init_vsi = vsi; + instance->core_vsi =mtk_vcodec_fw_map_dm_addr (ctx->dev->fw_handler, + (u32 )vsi->core_vsi); +if (!instance->core_vsi) { +mtk_vcodec_err (instance,"failed to get VP9 core vsi\n" ); + ret = -EINVAL ; + goto error_vsi; + } + + instance->irq =1 ; + + ret =vdec_vp9_slice_init_default_frame_ctx (instance); +if (ret) + goto error_default_frame_ctx; + + ctx->drv_handle = instance; + +return 0 ; + +error_default_frame_ctx: +error_vsi: +vpu_dec_deinit (&instance->vpu); +error_vpu_init: +kfree (instance); +return ret; +} + +static void vdec_vp9_slice_deinit (void *h_vdec) +{ +struct vdec_vp9_slice_instance *instance = h_vdec; + +if (!instance) +return ; + +vpu_dec_deinit (&instance->vpu); +vdec_vp9_slice_free_working_buffer (instance); +vdec_msg_queue_deinit (&instance->ctx->msg_queue, instance->ctx); +kfree (instance); +} + +static int vdec_vp9_slice_flush (void *h_vdec,struct mtk_vcodec_mem *bs, +struct vdec_fb *fb,bool *res_chg) +{ +struct vdec_vp9_slice_instance *instance = h_vdec; + +mtk_vcodec_debug (instance,"flush ...\n" ); + +vdec_msg_queue_wait_lat_buf_full (&instance->ctx->msg_queue); +return vpu_dec_reset (&instance->vpu); +} + +static void vdec_vp9_slice_get_pic_info (struct vdec_vp9_slice_instance *instance) +{ +struct mtk_vcodec_ctx *ctx = instance->ctx; +unsigned int data[3 ]; + +mtk_vcodec_debug (instance,"w %u h %u\n" , + ctx->picinfo.pic_w, ctx->picinfo.pic_h); + + data[0 ] = ctx->picinfo.pic_w; + data[1 ] = ctx->picinfo.pic_h; + data[2 ] = ctx->capture_fourcc; +vpu_dec_get_param (&instance->vpu, data,3 ,GET_PARAM_PIC_INFO ); + + ctx->picinfo.buf_w =ALIGN (ctx->picinfo.pic_w,64 ); + ctx->picinfo.buf_h =ALIGN (ctx->picinfo.pic_h,64 ); + ctx->picinfo.fb_sz[0 ] = instance->vpu.fb_sz[0 ]; + ctx->picinfo.fb_sz[1 ] = instance->vpu.fb_sz[1 ]; +} + +static void vdec_vp9_slice_get_dpb_size (struct vdec_vp9_slice_instance *instance, +unsigned int *dpb_sz) +{ +/* refer VP9 specification */ + *dpb_sz =9 ; +} + +static int vdec_vp9_slice_get_param (void *h_vdec,enum vdec_get_param_type type,void *out) +{ +struct vdec_vp9_slice_instance *instance = h_vdec; + +switch (type) { +case GET_PARAM_PIC_INFO : +vdec_vp9_slice_get_pic_info (instance); +break ; +case GET_PARAM_DPB_SIZE : +vdec_vp9_slice_get_dpb_size (instance, out); +break ; +case GET_PARAM_CROP_INFO : +mtk_vcodec_debug (instance,"No need to get vp9 crop information." ); +break ; +default : +mtk_vcodec_err (instance,"invalid get parameter type=%d\n" , + type); +return -EINVAL ; + } + +return 0 ; +} + +static int vdec_vp9_slice_lat_decode (void *h_vdec,struct mtk_vcodec_mem *bs, +struct vdec_fb *fb,bool *res_chg) +{ +struct vdec_vp9_slice_instance *instance = h_vdec; +struct vdec_lat_buf *lat_buf; +struct vdec_vp9_slice_pfc *pfc; +struct vdec_vp9_slice_vsi *vsi; +struct mtk_vcodec_ctx *ctx; +int ret; + +if (!instance || !instance->ctx) +return -EINVAL ; + ctx = instance->ctx; + +/* init msgQ for the first time */ +if (vdec_msg_queue_init (&ctx->msg_queue, ctx, + vdec_vp9_slice_core_decode, +sizeof (*pfc))) +return -ENOMEM ; + +/* bs NULL means flush decoder */ +if (!bs) +return vdec_vp9_slice_flush (h_vdec, bs, fb, res_chg); + + lat_buf =vdec_msg_queue_dqbuf (&instance->ctx->msg_queue.lat_ctx); +if (!lat_buf) { +mtk_vcodec_err (instance,"Failed to get VP9 lat buf\n" ); +return -EBUSY ; + } + pfc = (struct vdec_vp9_slice_pfc *)lat_buf->private_data; +if (!pfc) +return -EINVAL ; + vsi = &pfc->vsi; + + ret =vdec_vp9_slice_setup_lat (instance, bs, lat_buf, pfc); +if (ret) { +mtk_vcodec_err (instance,"Failed to setup VP9 lat ret %d\n" , ret); +return ret; + } +vdec_vp9_slice_vsi_to_remote (vsi, instance->vsi); + + ret =vpu_dec_start (&instance->vpu,0 ,0 ); +if (ret) { +mtk_vcodec_err (instance,"Failed to dec VP9 ret %d\n" , ret); +return ret; + } + +if (instance->irq) { + ret =mtk_vcodec_wait_for_done_ctx (ctx,MTK_INST_IRQ_RECEIVED , +WAIT_INTR_TIMEOUT_MS ,MTK_VDEC_LAT0 ); +/* update remote vsi if decode timeout */ +if (ret) { +mtk_vcodec_err (instance,"VP9 decode timeout %d pic %d\n" , ret, pfc->seq); +writel (1 , &instance->vsi->state.timeout); + } +vpu_dec_end (&instance->vpu); + } + +vdec_vp9_slice_vsi_from_remote (vsi, instance->vsi,0 ); + ret =vdec_vp9_slice_update_lat (instance, lat_buf, pfc); + +/* LAT trans full, no more UBE or decode timeout */ +if (ret) { +mtk_vcodec_err (instance,"VP9 decode error: %d\n" , ret); +return ret; + } + +mtk_vcodec_debug (instance,"lat dma 1 0x%llx 0x%llx\n" , + pfc->vsi.trans.dma_addr, pfc->vsi.trans.dma_addr_end); + +vdec_msg_queue_update_ube_wptr (&ctx->msg_queue, + vsi->trans.dma_addr_end + + ctx->msg_queue.wdma_addr.dma_addr); +vdec_msg_queue_qbuf (&ctx->dev->msg_queue_core_ctx, lat_buf); + +return 0 ; +} + +static int vdec_vp9_slice_core_decode (struct vdec_lat_buf *lat_buf) +{ +struct vdec_vp9_slice_instance *instance; +struct vdec_vp9_slice_pfc *pfc; +struct mtk_vcodec_ctx *ctx =NULL ; +struct vdec_fb *fb =NULL ; +int ret = -EINVAL ; + +if (!lat_buf) + goto err; + + pfc = lat_buf->private_data; + ctx = lat_buf->ctx; +if (!pfc || !ctx) + goto err; + + instance = ctx->drv_handle; +if (!instance) + goto err; + + fb = ctx->dev->vdec_pdata->get_cap_buffer (ctx); +if (!fb) { + ret = -EBUSY ; + goto err; + } + + ret =vdec_vp9_slice_setup_core (instance, fb, lat_buf, pfc); +if (ret) { +mtk_vcodec_err (instance,"vdec_vp9_slice_setup_core\n" ); + goto err; + } +vdec_vp9_slice_vsi_to_remote (&pfc->vsi, instance->core_vsi); + + ret =vpu_dec_core (&instance->vpu); +if (ret) { +mtk_vcodec_err (instance,"vpu_dec_core\n" ); + goto err; + } + +if (instance->irq) { + ret =mtk_vcodec_wait_for_done_ctx (ctx,MTK_INST_IRQ_RECEIVED , +WAIT_INTR_TIMEOUT_MS ,MTK_VDEC_CORE ); +/* update remote vsi if decode timeout */ +if (ret) { +mtk_vcodec_err (instance,"VP9 core timeout pic %d\n" , pfc->seq); +writel (1 , &instance->core_vsi->state.timeout); + } +vpu_dec_core_end (&instance->vpu); + } + +vdec_vp9_slice_vsi_from_remote (&pfc->vsi, instance->core_vsi,1 ); + ret =vdec_vp9_slice_update_core (instance, lat_buf, pfc); +if (ret) { +mtk_vcodec_err (instance,"vdec_vp9_slice_update_core\n" ); + goto err; + } + + pfc->vsi.trans.dma_addr_end += ctx->msg_queue.wdma_addr.dma_addr; +mtk_vcodec_debug (instance,"core dma_addr_end 0x%llx\n" , 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); + +return 0 ; + +err: +if (ctx) { +/* always update read pointer */ +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); + } +return ret; +} + +const struct vdec_common_if vdec_vp9_slice_lat_if = { + .init = vdec_vp9_slice_init, + .decode = vdec_vp9_slice_lat_decode, + .get_param = vdec_vp9_slice_get_param, + .deinit = vdec_vp9_slice_deinit, +};drivers/media/platform/mediatek/vcodec/vdec_drv_if.c +4
-0@@ -45,6 +45,10 @@ int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc) ctx->dec_if = &vdec_vp9_if; ctx->hw_id =MTK_VDEC_CORE ;break ; +case V4L2_PIX_FMT_VP9_FRAME : + ctx->dec_if = &vdec_vp9_slice_lat_if; + ctx->hw_id =MTK_VDEC_LAT0 ; +break ;default :return -EINVAL ; }drivers/media/platform/mediatek/vcodec/vdec_drv_if.h +1
-0@@ -60,6 +60,7 @@ extern const struct vdec_common_if vdec_h264_slice_multi_if;extern const struct vdec_common_if vdec_vp8_if;extern const struct vdec_common_if vdec_vp8_slice_if;extern const struct vdec_common_if vdec_vp9_if; +extern const struct vdec_common_if vdec_vp9_slice_lat_if;/** * vdec_if_init() - initialize decode driver
[email protected]
maintainerRe: [PATCH v8, 16/17] media: mediatek: vcodec: support stateless VP9 decoding
Hi Nicolas,
Thanks for you comments.
Very sorry I forgot to update the build error in upstream patch when fix in chrome os.
Will remove reviewed-by tag in next patch v9.
Best Regards,
Yunfei Dong
Quoted 2,487 lines · Nicolas Dufresne
Quoted 574 lines · Yunfei Dong
Add support for VP9 decoding using the stateless API, as supported by MT8192. And the drivers is lat and core architecture.
Signed-off-by George Sun <[email protected]>Signed-off-by Xiaoyong Lu <[email protected]>Signed-off-by Yunfei Dong <[email protected]>Reviewed-by AngeloGioacchino Del Regno <[email protected]>
---
changed compare with v7:
Using upstream interface to update vp9 prob tables.--- .../media/platform/mediatek/vcodec/Makefile | 1 + .../vcodec/mtk_vcodec_dec_stateless.c | 26 +- .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 1 + .../vcodec/vdec/vdec_vp9_req_lat_if.c | 2072 +++++++++++++++++ .../platform/mediatek/vcodec/vdec_drv_if.c | 4 + .../platform/mediatek/vcodec/vdec_drv_if.h | 1 + 6 files changed, 2102 insertions(+), 3 deletions(-) create mode 100644
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.cdrivers/media/platform/mediatek/vcodec/Makefile +1
-0@@ -9,6 +9,7 @@ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \ vdec/vdec_vp8_if.o \ vdec/vdec_vp8_req_if.o \ vdec/vdec_vp9_if.o \ + vdec/vdec_vp9_req_lat_if.o \ vdec/vdec_h264_req_if.o \ vdec/vdec_h264_req_common.o \ vdec/vdec_h264_req_multi_if.o \diff --git
a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.cb/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.cindex3208f834ff80..a4735e67d39e100644
---a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
+++b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.cdrivers/media/platform/mediatek/vcodec/Makefile +18
-3@@ -91,13 +91,28 @@ static const struct mtk_stateless_control mtk_stateless_controls[] = { .max = V4L2_MPEG_VIDEO_VP8_PROFILE_3, }, .codec_type = V4L2_PIX_FMT_VP8_FRAME, - } + }, + { + .cfg = { + .id = V4L2_CID_STATELESS_VP9_FRAME, + }, + .codec_type = V4L2_PIX_FMT_VP9_FRAME, + }, + { + .cfg = { + .id = V4L2_CID_MPEG_VIDEO_VP9_PROFILE, + .min = V4L2_MPEG_VIDEO_VP9_PROFILE_0, + .def = V4L2_MPEG_VIDEO_VP9_PROFILE_0, + .max = V4L2_MPEG_VIDEO_VP9_PROFILE_3, + }, + .codec_type = V4L2_PIX_FMT_VP9_FRAME, + }, }; #define NUM_CTRLS ARRAY_SIZE(mtk_stateless_controls) -static struct mtk_video_fmt mtk_video_formats[4]; -static struct mtk_codec_framesizes mtk_vdec_framesizes[2]; +static struct mtk_video_fmt mtk_video_formats[5]; +static struct mtk_codec_framesizes mtk_vdec_framesizes[3]; static struct mtk_video_fmt default_out_format;static struct
mtk_video_fmtdefault_cap_format;drivers/media/platform/mediatek/vcodec/Makefile +1
-0@@ -338,6 +353,7 @@ static void mtk_vcodec_add_formats(unsigned int fourcc, switch (fourcc) { case V4L2_PIX_FMT_H264_SLICE: case V4L2_PIX_FMT_VP8_FRAME: + case V4L2_PIX_FMT_VP9_FRAME: mtk_video_formats[count_formats].fourcc = fourcc; mtk_video_formats[count_formats].type = MTK_FMT_DEC;drivers/media/platform/mediatek/vcodec/Makefile +4
-0mtk_video_formats[count_formats].num_planes = 1;@@ -385,6 +401,10 @@ static void mtk_vcodec_get_supported_formats(struct mtk_vcodec_ctx *ctx) mtk_vcodec_add_formats(V4L2_PIX_FMT_VP8_FRAME, ctx); out_format_count++; } + if (ctx->dev->dec_capability & MTK_VDEC_FORMAT_VP9_FRAME) { + mtk_vcodec_add_formats(V4L2_PIX_FMT_VP9_FRAME, ctx); + out_format_count++; + } if (cap_format_count)
default_cap_format= mtk_video_formats[cap_format_count
- 1];
diff --gita/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.hb/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.hindex2ba1c19f07b6..a29041a0b7e0100644drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0@@ -355,6 +355,7 @@ enum mtk_vdec_format_types {MTK_VDEC_FORMAT_MT21C =0x40 ,MTK_VDEC_FORMAT_H264_SLICE =0x100 ,MTK_VDEC_FORMAT_VP8_FRAME =0x200 , + MTK_VDEC_FORMAT_VP9_FRAME = 0x400, };/** diff --git
a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.cb/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.cnew file mode 100644
index 000000000000..d63399085b9b
---/dev/null
+++b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.cdrivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +30
-0@@ -0,0 +1,2072 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2021 MediaTek Inc. +* Author: George Sun <[email protected]> +*/ + +#include <linux/module.h> +#include <linux/slab.h> +#include <media/videobuf2-dma-contig.h> +#include <media/v4l2-vp9.h> + +#include "../mtk_vcodec_util.h" +#include "../mtk_vcodec_dec.h" +#include "../mtk_vcodec_intr.h" +#include "../vdec_drv_base.h" +#include "../vdec_drv_if.h" +#include "../vdec_vpu_if.h" + +/* reset_frame_context defined in VP9 spec */ +#define VP9_RESET_FRAME_CONTEXT_NONE0 0 +#define VP9_RESET_FRAME_CONTEXT_NONE1 1 +#define VP9_RESET_FRAME_CONTEXT_SPEC 2 +#define VP9_RESET_FRAME_CONTEXT_ALL 3 + +#define VP9_TILE_BUF_SIZE 4096 +#define VP9_PROB_BUF_SIZE 2560 +#define VP9_COUNTS_BUF_SIZE 16384 + +#define HDR_FLAG (x) (!!((hdr)->flags & V4L2_VP9_FRAME_FLAG_##x)) +#define LF_FLAG (x) (!!((lf)->flags &V4L2_VP9_LOOP_FILTER_FLAG_##x))
+#defineSEG_FLAG(x)(!!((seg)->flags &
V4L2_VP9_SEGMENTATION_FLAG_##x))drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +55
-0+#define VP9_BAND_6 (band) ((band) == 0 ? 3 : 6) + +/* +* struct vdec_vp9_slice_frame_ctx - vp9 prob tables footprint +*/ +struct vdec_vp9_slice_frame_ctx { +struct { +u8 probs[6 ][3 ]; +u8 padding[2 ]; + } coef_probs[4 ][2 ][2 ][6 ]; + +u8 y_mode_prob[4 ][16 ]; +u8 switch_interp_prob[4 ][16 ]; +u8 seg[32 ];/* ignore */ +u8 comp_inter_prob[16 ]; +u8 comp_ref_prob[16 ]; +u8 single_ref_prob[5 ][2 ]; +u8 single_ref_prob_padding[6 ]; + +u8 joint[3 ]; +u8 joint_padding[13 ]; +struct { +u8 sign; +u8 classes[10 ]; +u8 padding[5 ]; + } sign_classes[2 ]; +struct { +u8 class0[1 ]; +u8 bits[10 ]; +u8 padding[5 ]; + } class0_bits[2 ]; +struct { +u8 class0_fp[2 ][3 ]; +u8 fp[3 ]; +u8 class0_hp; +u8 hp; +u8 padding[5 ]; + } class0_fp_hp[2 ]; + +u8 uv_mode_prob[10 ][16 ]; +u8 uv_mode_prob_padding[2 ][16 ]; + +u8 partition_prob[16 ][4 ]; + +u8 inter_mode_probs[7 ][4 ]; +u8 skip_probs[4 ]; + +u8 tx_p8x8[2 ][4 ]; +u8 tx_p16x16[2 ][4 ]; +u8 tx_p32x32[2 ][4 ]; +u8 intra_inter_prob[8 ]; +}; + +/* +* struct vdec_vp9_slice_frame_counts - vp9 counts tables footprint
+ */drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +65
-0+struct vdec_vp9_slice_frame_counts { +union { +struct { +u32 band_0[3 ]; +u32 padding0[1 ]; +u32 band_1_5[5 ][6 ]; +u32 padding1[2 ]; + } eob_branch[4 ][2 ][2 ]; +u32 eob_branch_space[256 *4 ]; + }; + +struct { +u32 band_0[3 ][4 ]; +u32 band_1_5[5 ][6 ][4 ]; + } coef_probs[4 ][2 ][2 ]; + +u32 intra_inter[4 ][2 ]; +u32 comp_inter[5 ][2 ]; +u32 comp_inter_padding[2 ]; +u32 comp_ref[5 ][2 ]; +u32 comp_ref_padding[2 ]; +u32 single_ref[5 ][2 ][2 ]; +u32 inter_mode[7 ][4 ]; +u32 y_mode[4 ][12 ]; +u32 uv_mode[10 ][10 ]; +u32 partition[16 ][4 ]; +u32 switchable_interp[4 ][4 ]; + +u32 tx_p8x8[2 ][2 ]; +u32 tx_p16x16[2 ][4 ]; +u32 tx_p32x32[2 ][4 ]; + +u32 skip[3 ][4 ]; + +u32 joint[4 ]; + +struct { +u32 sign[2 ]; +u32 class0[2 ]; +u32 classes[12 ]; +u32 bits[10 ][2 ]; +u32 padding[4 ]; +u32 class0_fp[2 ][4 ]; +u32 fp[4 ]; +u32 class0_hp[2 ]; +u32 hp[2 ]; + } mvcomp[2 ]; + +u32 reserved[126 ][4 ]; +}; + +/** +* struct vdec_vp9_slice_counts_map - vp9 counts tables to map +* v4l2_vp9_frame_symbol_counts +* @skip: skip counts. +* @y_mode: Y prediction mode counts. +* @filter: interpolation filter counts. +* @mv_joint: motion vector joint counts. +* @sign: motion vector sign counts. +* @classes: motion vector class counts. +* @class0: motion vector class0 bit counts. +* @bits: motion vector bits counts. +* @class0_fp: motion vector class0 fractional bit counts. +* @fp: motion vector fractional bit counts. +* @class0_hp: motion vector class0 high precision fractional bit counts.
+ * @hp: motion vector high precision fractional bit counts.
+ */drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +16
-0+struct vdec_vp9_slice_counts_map { +u32 skip[3 ][2 ]; +u32 y_mode[4 ][10 ]; +u32 filter[4 ][3 ]; +u32 sign[2 ][2 ]; +u32 classes[2 ][11 ]; +u32 class0[2 ][2 ]; +u32 bits[2 ][10 ][2 ]; +u32 class0_fp[2 ][2 ][4 ]; +u32 fp[2 ][4 ]; +u32 class0_hp[2 ][2 ]; +u32 hp[2 ][2 ]; +}; + +/* +* struct vdec_vp9_slice_uncompressed_header - vp9 uncompressed header syntax
+ * used for decoding
+ */drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +65
-0+struct vdec_vp9_slice_uncompressed_header { +u8 profile; +u8 last_frame_type; +u8 frame_type; + +u8 last_show_frame; +u8 show_frame; +u8 error_resilient_mode; + +u8 bit_depth; +u8 padding0[1 ]; +u16 last_frame_width; +u16 last_frame_height; +u16 frame_width; +u16 frame_height; + +u8 intra_only; +u8 reset_frame_context; +u8 ref_frame_sign_bias[4 ]; +u8 allow_high_precision_mv; +u8 interpolation_filter; + +u8 refresh_frame_context; +u8 frame_parallel_decoding_mode; +u8 frame_context_idx; + +/* loop_filter_params */ +u8 loop_filter_level; +u8 loop_filter_sharpness; +u8 loop_filter_delta_enabled; +s8 loop_filter_ref_deltas[4 ]; +s8 loop_filter_mode_deltas[2 ]; + +/* quantization_params */ +u8 base_q_idx; +s8 delta_q_y_dc; +s8 delta_q_uv_dc; +s8 delta_q_uv_ac; + +/* segmentation_params */ +u8 segmentation_enabled; +u8 segmentation_update_map; +u8 segmentation_tree_probs[7 ]; +u8 padding1[1 ]; +u8 segmentation_temporal_udpate; +u8 segmentation_pred_prob[3 ]; +u8 segmentation_update_data; +u8 segmentation_abs_or_delta_update; +u8 feature_enabled[8 ]; +s16 feature_value[8 ][4 ]; + +/* tile_info */ +u8 tile_cols_log2; +u8 tile_rows_log2; +u8 padding2[2 ]; + +u16 uncompressed_header_size; +u16 header_size_in_bytes; + +/* LAT OUT, CORE IN */ +u32 dequant[8 ][4 ]; +}; + +/* +* struct vdec_vp9_slice_compressed_header - vp9 compressed header syntax
+ * used for decoding.
+ */drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +21
-0+struct vdec_vp9_slice_compressed_header { +u8 tx_mode; +u8 ref_mode; +u8 comp_fixed_ref; +u8 comp_var_ref[2 ]; +u8 padding[3 ]; +}; + +/* +* struct vdec_vp9_slice_tiles - vp9 tile syntax +*/ +struct vdec_vp9_slice_tiles { +u32 size[4 ][64 ]; +u32 mi_rows[4 ]; +u32 mi_cols[64 ]; +u8 actual_rows; +u8 padding[7 ]; +}; + +/* +* struct vdec_vp9_slice_reference - vp9 reference frame information
+ */drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +21
-0+struct vdec_vp9_slice_reference { +u16 frame_width; +u16 frame_height; +u8 bit_depth; +u8 subsampling_x; +u8 subsampling_y; +u8 padding; +}; + +/* +* struct vdec_vp9_slice_frame - vp9 syntax used for decoding +*/ +struct vdec_vp9_slice_frame { +struct vdec_vp9_slice_uncompressed_header uh; +struct vdec_vp9_slice_compressed_header ch; +struct vdec_vp9_slice_tiles tiles; +struct vdec_vp9_slice_reference ref[3 ]; +}; + +/* +* struct vdec_vp9_slice_init_vsi - VSI used to initialize instance
+ */drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +97
-0+struct vdec_vp9_slice_init_vsi { +unsigned int architecture; +unsigned int reserved; +u64 core_vsi; +/* default frame context's position in MicroP */ +u64 default_frame_ctx; +}; + +/* +* struct vdec_vp9_slice_mem - memory address and size +*/ +struct vdec_vp9_slice_mem { +union { +u64 buf; +dma_addr_t dma_addr; + }; +union { +size_t size; +dma_addr_t dma_addr_end; +u64 padding; + }; +}; + +/* +* struct vdec_vp9_slice_bs - input buffer for decoding +*/ +struct vdec_vp9_slice_bs { +struct vdec_vp9_slice_mem buf; +struct vdec_vp9_slice_mem frame; +}; + +/* +* struct vdec_vp9_slice_fb - frame buffer for decoding +*/ +struct vdec_vp9_slice_fb { +struct vdec_vp9_slice_mem y; +struct vdec_vp9_slice_mem c; +}; + +/* +* struct vdec_vp9_slice_state - decoding state +*/ +struct vdec_vp9_slice_state { +int err; +unsigned int full; +unsigned int timeout; +unsigned int perf; + +unsigned int crc[12 ]; +}; + +/** +* struct vdec_vp9_slice_vsi - exchange decoding information +* between Main CPU and MicroP +* +* @bs: input buffer +* @fb: output buffer +* @ref: 3 reference buffers +* @mv: mv working buffer +* @seg: segmentation working buffer +* @tile: tile buffer +* @prob: prob table buffer, used to set/update prob table +* @counts: counts table buffer, used to update prob table +* @ube: general buffer +* @trans: trans buffer position in general buffer +* @err_map: error buffer +* @row_info: row info buffer +* @frame: decoding syntax +* @state: decoding state +*/ +struct vdec_vp9_slice_vsi { +/* used in LAT stage */ +struct vdec_vp9_slice_bs bs; +/* used in Core stage */ +struct vdec_vp9_slice_fb fb; +struct vdec_vp9_slice_fb ref[3 ]; + +struct vdec_vp9_slice_mem mv[2 ]; +struct vdec_vp9_slice_mem seg[2 ]; +struct vdec_vp9_slice_mem tile; +struct vdec_vp9_slice_mem prob; +struct vdec_vp9_slice_mem counts; + +/* LAT stage's output, Core stage's input */ +struct vdec_vp9_slice_mem ube; +struct vdec_vp9_slice_mem trans; +struct vdec_vp9_slice_mem err_map; +struct vdec_vp9_slice_mem row_info; + +/* decoding parameters */ +struct vdec_vp9_slice_frame frame; + +struct vdec_vp9_slice_state state; +}; + +/** +* struct vdec_vp9_slice_pfc - per-frame context that contains a local vsi.
+ * pass it from lat to core
+ *
+ * @vsi: local vsi. copy to/from remote vsi before/after
decoding
+ * @ref_idx: reference buffer index
+ * @seq: picture sequence
+ * @state: decoding state
+ */drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +23
-0+struct vdec_vp9_slice_pfc { +struct vdec_vp9_slice_vsi vsi; + +u64 ref_idx[3 ]; + +int seq; + +/* LAT/Core CRC */ +struct vdec_vp9_slice_state state[2 ]; +}; + +/* +* enum vdec_vp9_slice_resolution_level +*/ +enum vdec_vp9_slice_resolution_level { +VP9_RES_NONE , +VP9_RES_FHD , +VP9_RES_4K , +VP9_RES_8K , +}; + +/* +* struct vdec_vp9_slice_ref - picture's width & height should kept
+ * for later decoding as reference
picture
+ */drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +18
-0+struct vdec_vp9_slice_ref { +unsigned int width; +unsigned int height; +}; + +/** +* struct vdec_vp9_slice_instance - represent one vp9 instance +* +* @ctx: pointer to codec's context +* @vpu: VPU instance +* @seq: global picture sequence +* @level: level of current resolution +* @width: width of last picture +* @height: height of last picture +* @frame_type: frame_type of last picture +* @irq: irq to Main CPU or MicroP +* @show_frame: show_frame of last picture +* @dpb: picture information (width/height) for reference
+ * @mv: mv working buffer
+ * @seg: segmentation working buffer
+ * @tile: tile buffer
+ * @prob: prob table buffer, used to set/update prob
table
+ * @counts: counts table buffer, used to update
prob table
+ * @frame_ctx: 4 frame context according to VP9 SpecQuoted 8 lines
+ * @frame_ctx_helper: 4 frame context according to newest
kernel spec
+ * @dirty: state of each frame context
+ * @init_vsi: vsi used for initialized VP9 instance
+ * @vsi: vsi used for decoding/flush ...
+ * @core_vsi: vsi used for Core stage
+ * @counts_map: used map tocounts_helper
+ *&counts_helper: counts table according to newest kernel specChange & into @ to fix:
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c:492: warning: Function parameter or member 'counts_helper' not described in 'vdec_vp9_slice_instance'Quoted 39 lines
+ */
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +38
-0+struct vdec_vp9_slice_instance { +struct mtk_vcodec_ctx *ctx; +struct vdec_vpu_inst vpu; + +int seq; + +enum vdec_vp9_slice_resolution_level level; + +/* for resolution change and get_pic_info */ +unsigned int width; +unsigned int height; + +/* for last_frame_type */ +unsigned int frame_type; +unsigned int irq; + +unsigned int show_frame; + +/* maintain vp9 reference frame state */ +struct vdec_vp9_slice_ref dpb[VB2_MAX_FRAME ]; + +/* +* normal working buffers +* mv[0]/seg[0]/tile/prob/counts is used for LAT +* mv[1]/seg[1] is used for CORE +*/ +struct mtk_vcodec_mem mv[2 ]; +struct mtk_vcodec_mem seg[2 ]; +struct mtk_vcodec_mem tile; +struct mtk_vcodec_mem prob; +struct mtk_vcodec_mem counts; + +/* 4 prob tables */ +struct vdec_vp9_slice_frame_ctx frame_ctx[4 ]; +/*4 helper tables */ +struct v4l2_vp9_frame_context frame_ctx_helper; +unsigned char dirty[4 ]; +drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +10
-0+/* MicroP vsi */ +union { +struct vdec_vp9_slice_init_vsi *init_vsi; +struct vdec_vp9_slice_vsi *vsi; + }; +struct vdec_vp9_slice_vsi *core_vsi; + +struct vdec_vp9_slice_counts_map counts_map; +struct v4l2_vp9_frame_symbol_counts counts_helper; +};From here ....
Quoted 36 lines
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +21
-1+ +/* +* (2, (0, (1, 3))) +* max level = 2 +*/ +static const signed char vdec_vp9_slice_inter_mode_tree[6 ] = { +-2 ,2 ,0 ,4 ,-1 ,-3 +}; + +/* max level = 6 */ +static const signed char vdec_vp9_slice_intra_mode_tree[18 ] = { +0 ,2 ,-9 ,4 ,-1 ,6 ,8 ,12 ,-2 ,10 ,-4 ,-5 ,-3 ,14 ,-8 ,16 ,-6 , -7 +}; + +/* max level = 2 */ +static const signed char vdec_vp9_slice_partition_tree[6 ] = { +0 ,2 ,-1 ,4 ,-2 ,-3 +}; + +/* max level = 1 */ +static const signed char vdec_vp9_slice_switchable_interp_tree[4 ]= {
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +13
-0+ 0, 2, -1, -2 +}; + +/* max level = 2 */ +static const signed char vdec_vp9_slice_mv_joint_tree[6 ] = { +0 ,2 ,-1 ,4 ,-2 ,-3 +}; + +/* max level = 6 */ +static const signed char vdec_vp9_slice_mv_class_tree[20 ] = { +0 ,2 ,-1 ,4 ,6 ,8 ,-2 ,-3 ,10 ,12 , +-4 ,-5 ,-6 ,14 ,16 ,18 ,-7 ,-8 ,-9 ,-10 +};drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +10
-0+ +/* max level = 0 */ +static const signed char vdec_vp9_slice_mv_class0_tree[2 ] = { +0 ,-1 +}; + +/* max level = 2 */ +static const signed char vdec_vp9_slice_mv_fp_tree[6 ] = { +0 ,2 ,-1 ,4 ,-2 ,-3 +};All these are unused.
Quoted 771 lines
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +5
-0+ +/* +* all VP9 instances could share this default frame context. +*/ +static struct vdec_vp9_slice_frame_ctx
*vdec_vp9_slice_default_frame_ctx;drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+static DEFINE_MUTEX (vdec_vp9_slice_frame_ctx_lock); + +static int vdec_vp9_slice_core_decode(struct vdec_lat_buf
*lat_buf);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+ +static int vdec_vp9_slice_init_default_frame_ctx(struct
vdec_vp9_slice_instance*instance)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +13
-0+{ +struct vdec_vp9_slice_frame_ctx *remote_frame_ctx; +struct vdec_vp9_slice_frame_ctx *frame_ctx; +struct mtk_vcodec_ctx *ctx; +struct vdec_vp9_slice_init_vsi *vsi; +int ret =0 ; + + ctx = instance->ctx; + vsi = instance->vpu.vsi; +if (!ctx || !vsi) +return -EINVAL ; + + remote_frame_ctx = mtk_vcodec_fw_map_dm_addr(ctx->dev-Quoted 1 line
fw_handler,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ (u32)vsi-Quoted 1 line
default_frame_ctx);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+if (!remote_frame_ctx) { + mtk_vcodec_err(instance, "failed to map default framectx\n");
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +23
-0+return -EINVAL ; + } + +mutex_lock (&vdec_vp9_slice_frame_ctx_lock); +if (vdec_vp9_slice_default_frame_ctx) + goto out; + + frame_ctx =kmalloc (sizeof (*frame_ctx),GFP_KERNEL ); +if (!frame_ctx) { + ret = -ENOMEM ; + goto out; + } + +memcpy_fromio (frame_ctx, remote_frame_ctx,sizeof (*frame_ctx)); + vdec_vp9_slice_default_frame_ctx = frame_ctx; + +out: +mutex_unlock (&vdec_vp9_slice_frame_ctx_lock); + +return ret; +} + +static int vdec_vp9_slice_alloc_working_buffer(struct
vdec_vp9_slice_instance*instance,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ struct
vdec_vp9_slice_vsi*vsi)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +36
-0+{ +struct mtk_vcodec_ctx *ctx = instance->ctx; +enum vdec_vp9_slice_resolution_level level; +/* super blocks */ +unsigned int max_sb_w; +unsigned int max_sb_h; +unsigned int max_w; +unsigned int max_h; +unsigned int w; +unsigned int h; +size_t size; +int ret; +int i; + + w = vsi->frame.uh.frame_width; + h = vsi->frame.uh.frame_height; + +if (w >VCODEC_DEC_4K_CODED_WIDTH || + h >VCODEC_DEC_4K_CODED_HEIGHT ) { +return -EINVAL ; + }else if (w >MTK_VDEC_MAX_W || h >MTK_VDEC_MAX_H ) { +/* 4K */ + level =VP9_RES_4K ; + max_w =VCODEC_DEC_4K_CODED_WIDTH ; + max_h =VCODEC_DEC_4K_CODED_HEIGHT ; + }else { +/* FHD */ + level =VP9_RES_FHD ; + max_w =MTK_VDEC_MAX_W ; + max_h =MTK_VDEC_MAX_H ; + } + +if (level == instance->level) +return 0 ; + + mtk_vcodec_debug(instance, "resolution level changed, from %uto %u, %ux%u",
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +56
-0+ instance->level, level, w, h); + + max_sb_w =DIV_ROUND_UP (max_w,64 ); + max_sb_h =DIV_ROUND_UP (max_h,64 ); + ret = -ENOMEM ; + +/* +* Lat-flush must wait core idle, otherwise core will +* use released buffers +*/ + + size = (max_sb_w * max_sb_h +2 ) *576 ; +for (i =0 ; i <2 ; i++) { +if (instance->mv[i].va) +mtk_vcodec_mem_free (ctx, &instance->mv[i]); + instance->mv[i].size = size; +if (mtk_vcodec_mem_alloc (ctx, &instance->mv[i])) + goto err; + } + + size = (max_sb_w * max_sb_h *32 ) +256 ; +for (i =0 ; i <2 ; i++) { +if (instance->seg[i].va) +mtk_vcodec_mem_free (ctx, &instance->seg[i]); + instance->seg[i].size = size; +if (mtk_vcodec_mem_alloc (ctx, &instance->seg[i])) + goto err; + } + +if (!instance->tile.va) { + instance->tile.size =VP9_TILE_BUF_SIZE ; +if (mtk_vcodec_mem_alloc (ctx, &instance->tile)) + goto err; + } + +if (!instance->prob.va) { + instance->prob.size =VP9_PROB_BUF_SIZE ; +if (mtk_vcodec_mem_alloc (ctx, &instance->prob)) + goto err; + } + +if (!instance->counts.va) { + instance->counts.size =VP9_COUNTS_BUF_SIZE ; +if (mtk_vcodec_mem_alloc (ctx, &instance->counts)) + goto err; + } + + instance->level = level; +return 0 ; + +err: + instance->level =VP9_RES_NONE ; +return ret; +} + +static void vdec_vp9_slice_free_working_buffer(struct
vdec_vp9_slice_instance*instance)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +23
-0+{ +struct mtk_vcodec_ctx *ctx = instance->ctx; +int i; + +for (i =0 ; i <ARRAY_SIZE (instance->mv); i++) { +if (instance->mv[i].va) +mtk_vcodec_mem_free (ctx, &instance->mv[i]); + } +for (i =0 ; i <ARRAY_SIZE (instance->seg); i++) { +if (instance->seg[i].va) +mtk_vcodec_mem_free (ctx, &instance->seg[i]); + } +if (instance->tile.va) +mtk_vcodec_mem_free (ctx, &instance->tile); +if (instance->prob.va) +mtk_vcodec_mem_free (ctx, &instance->prob); +if (instance->counts.va) +mtk_vcodec_mem_free (ctx, &instance->counts); + + instance->level =VP9_RES_NONE ; +} + +static void vdec_vp9_slice_vsi_from_remote(struct
vdec_vp9_slice_vsi*vsi,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+struct vdec_vp9_slice_vsi
*remote_vsi,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +16
-0+ int skip) +{ +struct vdec_vp9_slice_frame *rf; +struct vdec_vp9_slice_frame *f; + +/* +* compressed header +* dequant +* buffer position +* decode state +*/ +if (!skip) { + rf = &remote_vsi->frame; + f = &vsi->frame; +memcpy_fromio (&f->ch, &rf->ch,sizeof (f->ch)); + memcpy_fromio(&f->uh.dequant, &rf->uh.dequant,
sizeof(f->uh.dequant));drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ memcpy_fromio(&vsi->trans, &remote_vsi->trans,
sizeof(vsi->trans));drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+ } + + memcpy_fromio(&vsi->state, &remote_vsi->state, sizeof(vsi-Quoted 1 line
state));
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+} + +static void vdec_vp9_slice_vsi_to_remote(struct vdec_vp9_slice_vsi*vsi,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+struct vdec_vp9_slice_vsi
*remote_vsi)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +5
-0+{ +memcpy_toio (remote_vsi, vsi,sizeof (*vsi)); +} + +static int vdec_vp9_slice_tile_offset(int idx, int mi_num, int
tile_log2)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +8
-0+{ +int sbs = (mi_num +7 ) >>3 ; +int offset = ((idx * sbs) >> tile_log2) <<3 ; + +return offset < mi_num ? offset : mi_num; +} + +static int vdec_vp9_slice_setup_lat_from_src_buf(struct
vdec_vp9_slice_instance*instance,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+struct vdec_lat_buf
*lat_buf)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +16
-0+{ +struct vb2_v4l2_buffer *src; +struct vb2_v4l2_buffer *dst; + + src =v4l2_m2m_next_src_buf (instance->ctx->m2m_ctx); +if (!src) +return -EINVAL ; + + lat_buf->src_buf_req = src->vb2_buf.req_obj.req; + + dst = &lat_buf->ts_info; +v4l2_m2m_buf_copy_metadata (src, dst, true); +return 0 ; +} + +static void vdec_vp9_slice_setup_hdr(struct
vdec_vp9_slice_instance*instance,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ struct
vdec_vp9_slice_uncompressed_header*uh,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +20
-0+ struct v4l2_ctrl_vp9_frame *hdr) +{ +int i; + + uh->profile = hdr->profile; + uh->last_frame_type = instance->frame_type; + uh->frame_type = !HDR_FLAG (KEY_FRAME ); + uh->last_show_frame = instance->show_frame; + uh->show_frame =HDR_FLAG (SHOW_FRAME ); + uh->error_resilient_mode =HDR_FLAG (ERROR_RESILIENT ); + uh->bit_depth = hdr->bit_depth; + uh->last_frame_width = instance->width; + uh->last_frame_height = instance->height; + uh->frame_width = hdr->frame_width_minus_1 +1 ; + uh->frame_height = hdr->frame_height_minus_1 +1 ; + uh->intra_only =HDR_FLAG (INTRA_ONLY ); +/* map v4l2 enum to values defined in VP9 spec for firmware */ +switch (hdr->reset_frame_context) { +case V4L2_VP9_RESET_FRAME_CTX_NONE : + uh->reset_frame_context =
VP9_RESET_FRAME_CONTEXT_NONE0;drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +9
-0+break ; +case V4L2_VP9_RESET_FRAME_CTX_SPEC : + uh->reset_frame_context =VP9_RESET_FRAME_CONTEXT_SPEC ; +break ; +case V4L2_VP9_RESET_FRAME_CTX_ALL : + uh->reset_frame_context =VP9_RESET_FRAME_CONTEXT_ALL ; +break ; +default : + uh->reset_frame_context =
VP9_RESET_FRAME_CONTEXT_NONE0;drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +31
-0+break ; + } +/* +* ref_frame_sign_bias specifies the intended direction +* of the motion vector in time for each reference frame. +* - INTRA_FRAME = 0, +* - LAST_FRAME = 1, +* - GOLDEN_FRAME = 2, +* - ALTREF_FRAME = 3, +* ref_frame_sign_bias[INTRA_FRAME] is always 0 +* and VDA only passes another 3 directions +*/ + uh->ref_frame_sign_bias[0 ] =0 ; +for (i =0 ; i <3 ; i++) + uh->ref_frame_sign_bias[i +1 ] = + !!(hdr->ref_frame_sign_bias & (1 << i)); + uh->allow_high_precision_mv =HDR_FLAG (ALLOW_HIGH_PREC_MV ); + uh->interpolation_filter = hdr->interpolation_filter; + uh->refresh_frame_context =HDR_FLAG (REFRESH_FRAME_CTX ); + uh->frame_parallel_decoding_mode =HDR_FLAG (PARALLEL_DEC_MODE ); + uh->frame_context_idx = hdr->frame_context_idx; + +/* tile info */ + uh->tile_cols_log2 = hdr->tile_cols_log2; + uh->tile_rows_log2 = hdr->tile_rows_log2; + + uh->uncompressed_header_size = hdr->uncompressed_header_size; + uh->header_size_in_bytes = hdr->compressed_header_size; +} + +static void vdec_vp9_slice_setup_frame_ctx(struct
vdec_vp9_slice_instance*instance,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ struct
vdec_vp9_slice_uncompressed_header*uh,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+struct v4l2_ctrl_vp9_frame *hdr)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +16
-0+{ +int error_resilient_mode; +int reset_frame_context; +int key_frame; +int intra_only; +int i; + + key_frame =HDR_FLAG (KEY_FRAME ); + intra_only =HDR_FLAG (INTRA_ONLY ); + error_resilient_mode =HDR_FLAG (ERROR_RESILIENT ); + reset_frame_context = uh->reset_frame_context; + +/* +* according to "6.2 Uncompressed header syntax" in +* "VP9 Bitstream & Decoding Process Specification", +* reset @frame_context_idx when (FrameIsIntra ||
error_resilient_mode)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +8
-0+*/ +if (key_frame || intra_only || error_resilient_mode) { +/* +* @reset_frame_context specifies +* whether the frame context should be +* reset to default values: +* 0 or 1 means do not reset any frame context +* 2 resets just the context specified in the frame header
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +15
-0+* 3 resets all contexts +*/ +if (key_frame || error_resilient_mode || + reset_frame_context ==3 ) { +/* use default table */ +for (i =0 ; i <4 ; i++) + instance->dirty[i] =0 ; + }else if (reset_frame_context ==2 ) { + instance->dirty[uh->frame_context_idx] =0 ; + } + uh->frame_context_idx =0 ; + } +} + +static void vdec_vp9_slice_setup_loop_filter(struct
vdec_vp9_slice_uncompressed_header*uh,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ struct
v4l2_vp9_loop_filter*lf)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +13
-0+{ +int i; + + uh->loop_filter_level = lf->level; + uh->loop_filter_sharpness = lf->sharpness; + uh->loop_filter_delta_enabled =LF_FLAG (DELTA_ENABLED ); +for (i =0 ; i <4 ; i++) + uh->loop_filter_ref_deltas[i] = lf->ref_deltas[i]; +for (i =0 ; i <2 ; i++) + uh->loop_filter_mode_deltas[i] = lf->mode_deltas[i]; +} + +static void vdec_vp9_slice_setup_quantization(struct
vdec_vp9_slice_uncompressed_header*uh,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ struct
v4l2_vp9_quantization*quant)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +8
-0+{ + uh->base_q_idx = quant->base_q_idx; + uh->delta_q_y_dc = quant->delta_q_y_dc; + uh->delta_q_uv_dc = quant->delta_q_uv_dc; + uh->delta_q_uv_ac = quant->delta_q_uv_ac; +} + +static void vdec_vp9_slice_setup_segmentation(struct
vdec_vp9_slice_uncompressed_header*uh,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ struct
v4l2_vp9_segmentation*seg)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +13
-0+{ +int i; +int j; + + uh->segmentation_enabled =SEG_FLAG (ENABLED ); + uh->segmentation_update_map =SEG_FLAG (UPDATE_MAP ); +for (i =0 ; i <7 ; i++) + uh->segmentation_tree_probs[i] = seg->tree_probs[i]; + uh->segmentation_temporal_udpate =SEG_FLAG (TEMPORAL_UPDATE ); +for (i =0 ; i <3 ; i++) + uh->segmentation_pred_prob[i] = seg->pred_probs[i]; + uh->segmentation_update_data =SEG_FLAG (UPDATE_DATA ); + uh->segmentation_abs_or_delta_update =
SEG_FLAG(ABS_OR_DELTA_UPDATE);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+for (i =0 ; i <8 ; i++) { + uh->feature_enabled[i] = seg->feature_enabled[i]; +for (j =0 ; j <4 ; j++) + uh->feature_value[i][j] = seg-Quoted 1 line
feature_data[i][j];
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ } +} + +static int vdec_vp9_slice_setup_tile(struct vdec_vp9_slice_vsi*vsi,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +30
-0+ struct v4l2_ctrl_vp9_frame *hdr) +{ +unsigned int rows_log2; +unsigned int cols_log2; +unsigned int rows; +unsigned int cols; +unsigned int mi_rows; +unsigned int mi_cols; +struct vdec_vp9_slice_tiles *tiles; +int offset; +int start; +int end; +int i; + + rows_log2 = hdr->tile_rows_log2; + cols_log2 = hdr->tile_cols_log2; + rows =1 << rows_log2; + cols =1 << cols_log2; + tiles = &vsi->frame.tiles; + tiles->actual_rows =0 ; + +if (rows >4 || cols >64 ) +return -EINVAL ; + +/* setup mi rows/cols information */ + mi_rows = (hdr->frame_height_minus_1 +1 +7 ) >>3 ; + mi_cols = (hdr->frame_width_minus_1 +1 +7 ) >>3 ; + +for (i =0 ; i < rows; i++) { + start = vdec_vp9_slice_tile_offset(i, mi_rows,
rows_log2);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ end = vdec_vp9_slice_tile_offset(i + 1, mi_rows,
rows_log2);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +8
-0+ offset = end - start; + tiles->mi_rows[i] = (offset +7 ) >>3 ; +if (tiles->mi_rows[i]) + tiles->actual_rows++; + } + +for (i =0 ; i < cols; i++) { + start = vdec_vp9_slice_tile_offset(i, mi_cols,
cols_log2);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ end = vdec_vp9_slice_tile_offset(i + 1, mi_cols,
cols_log2);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +8
-0+ offset = end - start; + tiles->mi_cols[i] = (offset +7 ) >>3 ; + } + +return 0 ; +} + +static void vdec_vp9_slice_setup_state(struct vdec_vp9_slice_vsi*vsi)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +5
-0+{ +memset (&vsi->state,0 ,sizeof (vsi->state)); +} + +static void vdec_vp9_slice_setup_ref_idx(struct vdec_vp9_slice_pfc*pfc,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+struct v4l2_ctrl_vp9_frame *hdr)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +7
-0+{ + pfc->ref_idx[0 ] = hdr->last_frame_ts; + pfc->ref_idx[1 ] = hdr->golden_frame_ts; + pfc->ref_idx[2 ] = hdr->alt_frame_ts; +} + +static int vdec_vp9_slice_setup_pfc(struct vdec_vp9_slice_instance*instance,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +10
-0+ struct vdec_vp9_slice_pfc *pfc) +{ +struct v4l2_ctrl_vp9_frame *hdr; +struct vdec_vp9_slice_uncompressed_header *uh; +struct v4l2_ctrl *hdr_ctrl; +struct vdec_vp9_slice_vsi *vsi; +int ret; + +/* frame header */ + hdr_ctrl = v4l2_ctrl_find(&instance->ctx->ctrl_hdl,
V4L2_CID_STATELESS_VP9_FRAME);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +28
-0+if (!hdr_ctrl || !hdr_ctrl->p_cur.p) +return -EINVAL ; + + hdr = hdr_ctrl->p_cur.p; + vsi = &pfc->vsi; + uh = &vsi->frame.uh; + +/* setup vsi information */ +vdec_vp9_slice_setup_hdr (instance, uh, hdr); +vdec_vp9_slice_setup_frame_ctx (instance, uh, hdr); +vdec_vp9_slice_setup_loop_filter (uh, &hdr->lf); +vdec_vp9_slice_setup_quantization (uh, &hdr->quant); +vdec_vp9_slice_setup_segmentation (uh, &hdr->seg); + ret =vdec_vp9_slice_setup_tile (vsi, hdr); +if (ret) +return ret; +vdec_vp9_slice_setup_state (vsi); + +/* core stage needs buffer index to get ref y/c ... */ +vdec_vp9_slice_setup_ref_idx (pfc, hdr); + + pfc->seq = instance->seq; + instance->seq++; + +return 0 ; +} + +static int vdec_vp9_slice_setup_lat_buffer(struct
vdec_vp9_slice_instance*instance,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+struct vdec_vp9_slice_vsi *vsi,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+struct mtk_vcodec_mem *bs, + struct vdec_lat_buf
*lat_buf)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +28
-0+{ +int i; + + vsi->bs.buf.dma_addr = bs->dma_addr; + vsi->bs.buf.size = bs->size; + vsi->bs.frame.dma_addr = bs->dma_addr; + vsi->bs.frame.size = bs->size; + +for (i =0 ; i <2 ; i++) { + vsi->mv[i].dma_addr = instance->mv[i].dma_addr; + vsi->mv[i].size = instance->mv[i].size; + } +for (i =0 ; i <2 ; i++) { + vsi->seg[i].dma_addr = instance->seg[i].dma_addr; + vsi->seg[i].size = instance->seg[i].size; + } + vsi->tile.dma_addr = instance->tile.dma_addr; + vsi->tile.size = instance->tile.size; + vsi->prob.dma_addr = instance->prob.dma_addr; + vsi->prob.size = instance->prob.size; + vsi->counts.dma_addr = instance->counts.dma_addr; + vsi->counts.size = instance->counts.size; + + vsi->ube.dma_addr = lat_buf->ctx->msg_queue.wdma_addr.dma_addr; + vsi->ube.size = lat_buf->ctx->msg_queue.wdma_addr.size; + vsi->trans.dma_addr = lat_buf->ctx->msg_queue.wdma_wptr_addr; +/* used to store trans end */ + vsi->trans.dma_addr_end = lat_buf->ctx-Quoted 1 line
msg_queue.wdma_rptr_addr;
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +10
-0+ vsi->err_map.dma_addr = lat_buf->wdma_err_addr.dma_addr; + vsi->err_map.size = lat_buf->wdma_err_addr.size; + + vsi->row_info.buf =0 ; + vsi->row_info.size =0 ; + +return 0 ; +} + +static int vdec_vp9_slice_setup_prob_buffer(struct
vdec_vp9_slice_instance*instance,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+struct vdec_vp9_slice_vsi *vsi)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +12
-0+{ +struct vdec_vp9_slice_frame_ctx *frame_ctx; +struct vdec_vp9_slice_uncompressed_header *uh; + + uh = &vsi->frame.uh; + +mtk_vcodec_debug (instance,"ctx dirty %u idx %d\n" , + instance->dirty[uh->frame_context_idx], + uh->frame_context_idx); + +if (instance->dirty[uh->frame_context_idx]) + frame_ctx = &instance->frame_ctx[uh-Quoted 1 line
frame_context_idx];drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +8
-0+else + frame_ctx = vdec_vp9_slice_default_frame_ctx; +memcpy (instance->prob.va, frame_ctx,sizeof (*frame_ctx)); + +return 0 ; +} + +static void vdec_vp9_slice_setup_seg_buffer(struct
vdec_vp9_slice_instance*instance,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+struct vdec_vp9_slice_vsi *vsi,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +21
-0+ struct mtk_vcodec_mem *buf) +{ +struct vdec_vp9_slice_uncompressed_header *uh; + +/* reset segment buffer */ + uh = &vsi->frame.uh; +if (uh->frame_type ==0 || + uh->intra_only || + uh->error_resilient_mode || + uh->frame_width != instance->width || + uh->frame_height != instance->height) { +mtk_vcodec_debug (instance,"reset seg\n" ); +memset (buf->va,0 , buf->size); + } +} + +/* +* parse tiles according to `6.4 Decode tiles syntax` +* in "vp9-bitstream-specification" +* +* frame contains uncompress header, compressed header and several tiles.
+ * this function parses tiles' position and size, stores them to tile buffer
+ * for decoding.
+ */
+static int vdec_vp9_slice_setup_tile_buffer(structvdec_vp9_slice_instance*instance,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+struct vdec_vp9_slice_vsi *vsi,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +36
-0+ struct mtk_vcodec_mem *bs) +{ +struct vdec_vp9_slice_uncompressed_header *uh; +unsigned int rows_log2; +unsigned int cols_log2; +unsigned int rows; +unsigned int cols; +unsigned int mi_row; +unsigned int mi_col; +unsigned int offset; +unsigned int pa; +unsigned int size; +struct vdec_vp9_slice_tiles *tiles; +unsigned char *pos; +unsigned char *end; +unsigned char *va; +unsigned int *tb; +int i; +int j; + + uh = &vsi->frame.uh; + rows_log2 = uh->tile_rows_log2; + cols_log2 = uh->tile_cols_log2; + rows =1 << rows_log2; + cols =1 << cols_log2; + +if (rows >4 || cols >64 ) { +mtk_vcodec_err (instance,"tile_rows %u tile_cols %u\n" , + rows, cols); +return -EINVAL ; + } + + offset = uh->uncompressed_header_size + + uh->header_size_in_bytes; +if (bs->size <= offset) { + mtk_vcodec_err(instance, "bs size %zu tile offset%u\n",
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +23
-0+ bs->size, offset); +return -EINVAL ; + } + + tiles = &vsi->frame.tiles; +/* setup tile buffer */ + + va = (unsigned char *)bs->va; + pos = va + offset; + end = va + bs->size; +/* truncated */ + pa = (unsigned int )bs->dma_addr + offset; + tb = instance->tile.va; +for (i =0 ; i < rows; i++) { +for (j =0 ; j < cols; j++) { +if (i == rows -1 && + j == cols -1 ) { + size = (unsigned int )(end - pos); + }else { +if (end - pos <4 ) +return -EINVAL ; + + size = (pos[0 ] <<24 ) | (pos[1 ] <<16 )|
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +10
-0+ (pos[2 ] <<8 ) | pos[3 ]; + pos +=4 ; + pa +=4 ; + offset +=4 ; +if (end - pos < size) +return -EINVAL ; + } + tiles->size[i][j] = size; +if (tiles->mi_rows[i]) { + *tb++ = (size << 3) + ((offset << 3) &
0x7f);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+ *tb++ = pa & ~0xf ; + *tb++ = (pa <<3 ) &0x7f ; + mi_row = (tiles->mi_rows[i] - 1) &
0x1ff;drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ mi_col = (tiles->mi_cols[j] - 1) &
0x3f;drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +12
-0+ *tb++ = (mi_row <<6 ) + mi_col; + } + pos += size; + pa += size; + offset += size; + } + } + +return 0 ; +} + +static int vdec_vp9_slice_setup_lat(struct vdec_vp9_slice_instance*instance,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +20
-0+struct mtk_vcodec_mem *bs, + struct vdec_lat_buf *lat_buf, + struct vdec_vp9_slice_pfc *pfc) +{ + struct vdec_vp9_slice_vsi *vsi = &pfc->vsi; +int ret; + + ret =vdec_vp9_slice_setup_lat_from_src_buf (instance, lat_buf); +if (ret) + goto err; + + ret =vdec_vp9_slice_setup_pfc (instance, pfc); +if (ret) + goto err; + + ret =vdec_vp9_slice_alloc_working_buffer (instance, vsi); +if (ret) + goto err; + + ret = vdec_vp9_slice_setup_lat_buffer(instance, vsi, bs,
lat_buf);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+if (ret) + goto err; + + vdec_vp9_slice_setup_seg_buffer(instance, vsi, &instance-Quoted 1 line
seg[0]);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +19
-0+ +/* setup prob/tile buffers for LAT */ + + ret =vdec_vp9_slice_setup_prob_buffer (instance, vsi); +if (ret) + goto err; + + ret =vdec_vp9_slice_setup_tile_buffer (instance, vsi, bs); +if (ret) + goto err; + +return 0 ; + +err: +return ret; +} + +static +void vdec_vp9_slice_map_counts_eob_coef(unsigned int i, unsignedint j, unsigned int k,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ struct
vdec_vp9_slice_frame_counts*counts,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ struct
v4l2_vp9_frame_symbol_counts*counts_helper)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +15
-0+{ +u32 l, m; + +/* +* helper eo -> mtk eo +* helpre e1 -> mtk c3 +* helper c0 -> c0 +* helper c1 -> c1 +* helper c2 -> c2 +*/ +for (l =0 ; l <6 ; l++) { +for (m =0 ; m <VP9_BAND_6 (l); m++) { +if (l ==0 ) { + counts_helper->coeff[i][j][k][l][m] = + &counts-Quoted 1 line
Quoted 1 line
coef_probs[i][j][k].band_0[m];
The missing a cast from (u32 (*)[4]) -> (u32 (*)[3]), the cast is safe otherwise
as long as the forth item is just HW padding. If its used by the HW for special
purpose, consider initializing it.Quoted 10 lines
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+ counts_helper->eob[i][j][k][l][m][0 ] = + &counts-Quoted 1 line
eob_branch[i][j][k].band_0[m];
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+ counts_helper->eob[i][j][k][l][m][1 ] = + &counts-Quoted 1 line
coef_probs[i][j][k].band_0[m][3];
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+ }else { + counts_helper->coeff[i][j][k][l][m] = + &counts-Quoted 1 line
coef_probs[i][j][k].band_1_5[l - 1][m];
Same here.
Quoted 17 lines
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+ counts_helper->eob[i][j][k][l][m][0 ] = + &counts-Quoted 1 line
eob_branch[i][j][k].band_1_5[l - 1][m];
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+ counts_helper->eob[i][j][k][l][m][1 ] = + &counts-Quoted 1 line
coef_probs[i][j][k].band_1_5[l - 1][m][3];
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +6
-0+ } + } + } +} + +static void vdec_vp9_slice_counts_map_helper(struct
vdec_vp9_slice_counts_map*counts_map,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ struct
vdec_vp9_slice_frame_counts*counts,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ struct
v4l2_vp9_frame_symbol_counts*counts_helper)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h
Quoted 2 lines
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+{ +int i, j, k, l, m;l and m are unused.
Quoted 980 lines
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +26
-0+ + counts_helper->partition = &counts->partition; + counts_helper->intra_inter = &counts->intra_inter; + counts_helper->tx32p = &counts->tx_p32x32; + counts_helper->tx16p = &counts->tx_p16x16; + counts_helper->tx8p = &counts->tx_p8x8; + counts_helper->uv_mode = &counts->uv_mode; + + counts_helper->comp = &counts->comp_inter; + counts_helper->comp_ref = &counts->comp_ref; + counts_helper->single_ref = &counts->single_ref; + counts_helper->mv_mode = &counts->inter_mode; + counts_helper->mv_joint = &counts->joint; + +for (i =0 ; i <ARRAY_SIZE (counts_map->skip); i++) +memcpy (counts_map->skip[i], counts->skip[i], +sizeof (counts_map->skip[0 ])); + counts_helper->skip = &counts_map->skip; + +for (i =0 ; i <ARRAY_SIZE (counts_map->y_mode); i++) +memcpy (counts_map->y_mode[i], counts->y_mode[i], +sizeof (counts_map->y_mode[0 ])); + counts_helper->y_mode = &counts_map->y_mode; + +for (i =0 ; i <ARRAY_SIZE (counts_map->filter); i++) + memcpy(counts_map->filter[i], counts-Quoted 1 line
switchable_interp[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +10
-0+ sizeof(counts_map->filter[0])); + counts_helper->filter = &counts_map->filter; + +for (i =0 ; i <ARRAY_SIZE (counts_map->sign); i++) +memcpy (counts_map->sign[i], counts->mvcomp[i].sign, +sizeof (counts_map->sign[0 ])); + counts_helper->sign = &counts_map->sign; + +for (i =0 ; i <ARRAY_SIZE (counts_map->classes); i++) + memcpy(counts_map->classes[i], counts-Quoted 1 line
mvcomp[i].classes,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +11
-0+ sizeof(counts_map->classes[0])); + counts_helper->classes = &counts_map->classes; + +for (i =0 ; i <ARRAY_SIZE (counts_map->class0); i++) +memcpy (counts_map->class0[i], counts->mvcomp[i].class0, +sizeof (counts_map->class0[0 ])); + counts_helper->class0 = &counts_map->class0; + +for (i =0 ; i <ARRAY_SIZE (counts_map->bits); i++) +for (j =0 ; j <ARRAY_SIZE (counts_map->bits[0 ]); j++) + memcpy(counts_map->bits[i][j], counts-Quoted 1 line
mvcomp[i].bits[j],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +5
-0+ sizeof(counts_map->bits[0][0])); + counts_helper->bits = &counts_map->bits; + + for (i = 0; i < ARRAY_SIZE(counts_map->class0_fp); i++) + for (j = 0; j < ARRAY_SIZE(counts_map->class0_fp[0]);j++)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ memcpy(counts_map->class0_fp[i][j], counts-Quoted 1 line
mvcomp[i].class0_fp[j],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +10
-0+ sizeof(counts_map->class0_fp[0][0])); + counts_helper->class0_fp = &counts_map->class0_fp; + +for (i =0 ; i <ARRAY_SIZE (counts_map->fp); i++) +memcpy (counts_map->fp[i], counts->mvcomp[i].fp, +sizeof (counts_map->fp[0 ])); + counts_helper->fp = &counts_map->fp; + +for (i =0 ; i <ARRAY_SIZE (counts_map->class0_hp); i++) + memcpy(counts_map->class0_hp[i], counts-Quoted 1 line
mvcomp[i].class0_hp,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +5
-0+ sizeof(counts_map->class0_hp[0])); + counts_helper->class0_hp = &counts_map->class0_hp; + +for (i =0 ; i <ARRAY_SIZE (counts_map->hp); i++) + memcpy(counts_map->hp[i], counts->mvcomp[i].hp,
sizeof(counts_map->hp[0]));drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +7
-0+ + counts_helper->hp = &counts_map->hp; + +for (i =0 ; i <4 ; i++) +for (j =0 ; j <2 ; j++) +for (k =0 ; k <2 ; k++) + vdec_vp9_slice_map_counts_eob_coef(i,j, k, counts,
counts_helper);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+} + +static void vdec_vp9_slice_map_to_coef(unsigned int i, unsignedint j, unsigned int k,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+struct vdec_vp9_slice_frame_ctx
*frame_ctx,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+struct v4l2_vp9_frame_context
*frame_ctx_helper)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+{ +u32 l, m; + + for (l = 0; l < ARRAY_SIZE(frame_ctx_helper->coef[0][0][0]);l++) {
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+for (m =0 ; m <VP9_BAND_6 (l); m++) { + memcpy(frame_ctx_helper->coef[i][j][k][l][m], + frame_ctx-Quoted 1 line
coef_probs[i][j][k][l].probs[m],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ sizeof(frame_ctx_helper-Quoted 1 line
coef[i][j][k][l][0]));
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +5
-0+ } + } +} + +static void vdec_vp9_slice_map_from_coef(unsigned int i, unsignedint j, unsigned int k,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ struct
vdec_vp9_slice_frame_ctx*frame_ctx,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+struct v4l2_vp9_frame_context
*frame_ctx_helper)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+{ +u32 l, m; + + for (l = 0; l < ARRAY_SIZE(frame_ctx_helper->coef[0][0][0]);l++) {
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+for (m =0 ; m <VP9_BAND_6 (l); m++) { + memcpy(frame_ctx-Quoted 1 line
coef_probs[i][j][k][l].probs[m],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+ frame_ctx_helper->coef[i][j][k][l][m], + sizeof(frame_ctx_helper-Quoted 1 line
coef[i][j][k][l][0]));
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +7
-0+ } + } +} + +static +void vdec_vp9_slice_framectx_map_helper (bool frame_is_intra, + struct vdec_vp9_slice_frame_ctx
*pre_frame_ctx,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+struct vdec_vp9_slice_frame_ctx
*frame_ctx,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+struct v4l2_vp9_frame_context
*frame_ctx_helper)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +6
-0+{ +struct v4l2_vp9_frame_mv_context *mv = &frame_ctx_helper->mv; +u32 i, j, k; + + for (i = 0; i < ARRAY_SIZE(frame_ctx_helper->coef); i++) + for (j = 0; j < ARRAY_SIZE(frame_ctx_helper->coef[0]);j++)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ for (k = 0; k < ARRAY_SIZE(frame_ctx_helper-Quoted 1 line
coef[0][0]); k++)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ vdec_vp9_slice_map_to_coef(i, j, k,
pre_frame_ctx,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ frame_ctx_helper);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ +/* +* use previous prob when frame is not intra or +* we should use the prob updated by the compressed header parse
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +10
-0+*/ +if (!frame_is_intra) + frame_ctx = pre_frame_ctx; + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx8); i++) +memcpy (frame_ctx_helper->tx8[i], frame_ctx->tx_p8x8[i], +sizeof (frame_ctx_helper->tx8[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx16); i++) + memcpy(frame_ctx_helper->tx16[i], frame_ctx-Quoted 1 line
tx_p16x16[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ sizeof(frame_ctx_helper->tx16[0])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx32); i++) + memcpy(frame_ctx_helper->tx32[i], frame_ctx-Quoted 1 line
tx_p32x32[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+ sizeof(frame_ctx_helper->tx32[0])); + + memcpy(frame_ctx_helper->skip, frame_ctx->skip_probs,
sizeof(frame_ctx_helper->skip));drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+ +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->inter_mode); i++) + memcpy(frame_ctx_helper->inter_mode[i], frame_ctx-Quoted 1 line
inter_mode_probs[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+ sizeof(frame_ctx_helper->inter_mode[0])); + + for (i = 0; i < ARRAY_SIZE(frame_ctx_helper->interp_filter);i++)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ memcpy(frame_ctx_helper->interp_filter[i], frame_ctx-Quoted 1 line
switch_interp_prob[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +10
-0+ sizeof(frame_ctx_helper->interp_filter[0])); + +memcpy (frame_ctx_helper->is_inter, frame_ctx->intra_inter_prob, +sizeof (frame_ctx_helper->is_inter)); + +memcpy (frame_ctx_helper->comp_mode, frame_ctx->comp_inter_prob, +sizeof (frame_ctx_helper->comp_mode)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->single_ref); i++) + memcpy(frame_ctx_helper->single_ref[i], frame_ctx-Quoted 1 line
single_ref_prob[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +7
-0+ sizeof(frame_ctx_helper->single_ref[0])); + +memcpy (frame_ctx_helper->comp_ref, frame_ctx->comp_ref_prob, +sizeof (frame_ctx_helper->comp_ref)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->y_mode); i++) + memcpy(frame_ctx_helper->y_mode[i], frame_ctx-Quoted 1 line
y_mode_prob[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ sizeof(frame_ctx_helper->y_mode[0])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->uv_mode); i++) + memcpy(frame_ctx_helper->uv_mode[i], frame_ctx-Quoted 1 line
uv_mode_prob[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ sizeof(frame_ctx_helper->uv_mode[0])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->partition); i++) + memcpy(frame_ctx_helper->partition[i], frame_ctx-Quoted 1 line
partition_prob[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +9
-0+ sizeof(frame_ctx_helper->partition[0])); + +memcpy (mv->joint, frame_ctx->joint,sizeof (mv->joint)); + +for (i =0 ; i <ARRAY_SIZE (mv->sign); i++) + mv->sign[i] = frame_ctx->sign_classes[i].sign; + +for (i =0 ; i <ARRAY_SIZE (mv->classes); i++) + memcpy(mv->classes[i], frame_ctx-Quoted 1 line
sign_classes[i].classes,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ sizeof(mv->classes[i])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_bit); i++) + mv->class0_bit[i] = frame_ctx-Quoted 1 line
class0_bits[i].class0[0];
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+ +for (i =0 ; i <ARRAY_SIZE (mv->bits); i++) + memcpy(mv->bits[i], frame_ctx->class0_bits[i].bits,
sizeof(mv->bits[0]));drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ +for (i =0 ; i <ARRAY_SIZE (mv->class0_fr); i++) +for (j =0 ; j <ARRAY_SIZE (mv->class0_fr[0 ]); j++) + memcpy(mv->class0_fr[i][j], frame_ctx-Quoted 1 line
class0_fp_hp[i].class0_fp[j],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ sizeof(mv->class0_fr[0][0])); + +for (i =0 ; i <ARRAY_SIZE (mv->fr); i++) + memcpy(mv->fr[i], frame_ctx->class0_fp_hp[i].fp,
sizeof(mv->fr[0]));drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+ +for (i =0 ; i <ARRAY_SIZE (mv->class0_hp); i++) + mv->class0_hp[i] = frame_ctx-Quoted 1 line
class0_fp_hp[i].class0_hp;
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +6
-0+ +for (i =0 ; i <ARRAY_SIZE (mv->hp); i++) + mv->hp[i] = frame_ctx->class0_fp_hp[i].hp; +} + +static void vdec_vp9_slice_helper_map_framectx(struct
v4l2_vp9_frame_context*frame_ctx_helper,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ struct
vdec_vp9_slice_frame_ctx*frame_ctx)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +10
-0+{ +struct v4l2_vp9_frame_mv_context *mv = &frame_ctx_helper->mv; +u32 i, j, k; + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx8); i++) +memcpy (frame_ctx->tx_p8x8[i], frame_ctx_helper->tx8[i], +sizeof (frame_ctx_helper->tx8[0 ])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx16); i++) + memcpy(frame_ctx->tx_p16x16[i], frame_ctx_helper-Quoted 1 line
tx16[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ sizeof(frame_ctx_helper->tx16[0])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->tx32); i++) + memcpy(frame_ctx->tx_p32x32[i], frame_ctx_helper-Quoted 1 line
tx32[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ sizeof(frame_ctx_helper->tx32[0])); + + for (i = 0; i < ARRAY_SIZE(frame_ctx_helper->coef); i++) + for (j = 0; j < ARRAY_SIZE(frame_ctx_helper->coef[0]);j++)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ for (k = 0; k < ARRAY_SIZE(frame_ctx_helper-Quoted 1 line
coef[0][0]); k++)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ vdec_vp9_slice_map_from_coef(i, j, k,
frame_ctx,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ frame_ctx_helper);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+ + memcpy(frame_ctx->skip_probs, frame_ctx_helper->skip,
sizeof(frame_ctx_helper->skip));drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+ +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->inter_mode); i++) + memcpy(frame_ctx->inter_mode_probs[i],frame_ctx_helper->inter_mode[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+ sizeof(frame_ctx_helper->inter_mode[0])); + + for (i = 0; i < ARRAY_SIZE(frame_ctx_helper->interp_filter);i++)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ memcpy(frame_ctx->switch_interp_prob[i],frame_ctx_helper->interp_filter[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +10
-0+ sizeof(frame_ctx_helper->interp_filter[0])); + +memcpy (frame_ctx->intra_inter_prob, frame_ctx_helper->is_inter, +sizeof (frame_ctx_helper->is_inter)); + +memcpy (frame_ctx->comp_inter_prob, frame_ctx_helper->comp_mode, +sizeof (frame_ctx_helper->comp_mode)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->single_ref); i++) + memcpy(frame_ctx->single_ref_prob[i], frame_ctx_helper-Quoted 1 line
single_ref[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +7
-0+ sizeof(frame_ctx_helper->single_ref[0])); + +memcpy (frame_ctx->comp_ref_prob, frame_ctx_helper->comp_ref, +sizeof (frame_ctx_helper->comp_ref)); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->y_mode); i++) + memcpy(frame_ctx->y_mode_prob[i], frame_ctx_helper-Quoted 1 line
y_mode[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ sizeof(frame_ctx_helper->y_mode[0])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->uv_mode); i++) + memcpy(frame_ctx->uv_mode_prob[i], frame_ctx_helper-Quoted 1 line
uv_mode[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ sizeof(frame_ctx_helper->uv_mode[0])); + +for (i =0 ; i <ARRAY_SIZE (frame_ctx_helper->partition); i++) + memcpy(frame_ctx->partition_prob[i], frame_ctx_helper-Quoted 1 line
partition[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +9
-0+ sizeof(frame_ctx_helper->partition[0])); + +memcpy (frame_ctx->joint, mv->joint,sizeof (mv->joint)); + +for (i =0 ; i <ARRAY_SIZE (mv->sign); i++) + frame_ctx->sign_classes[i].sign = mv->sign[i]; + +for (i =0 ; i <ARRAY_SIZE (mv->classes); i++) + memcpy(frame_ctx->sign_classes[i].classes, mv-Quoted 1 line
classes[i],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ sizeof(mv->classes[i])); + +for (i =0 ; i <ARRAY_SIZE (mv->class0_bit); i++) + frame_ctx->class0_bits[i].class0[0] = mv-Quoted 1 line
class0_bit[i];
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+ +for (i =0 ; i <ARRAY_SIZE (mv->bits); i++) + memcpy(frame_ctx->class0_bits[i].bits, mv->bits[i],
sizeof(mv->bits[0]));drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ +for (i =0 ; i <ARRAY_SIZE (mv->class0_fr); i++) +for (j =0 ; j <ARRAY_SIZE (mv->class0_fr[0 ]); j++) + memcpy(frame_ctx->class0_fp_hp[i].class0_fp[j],mv->class0_fr[i][j],
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ sizeof(mv->class0_fr[0][0])); + +for (i =0 ; i <ARRAY_SIZE (mv->fr); i++) + memcpy(frame_ctx->class0_fp_hp[i].fp, mv->fr[i],
sizeof(mv->fr[0]));drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+ +for (i =0 ; i <ARRAY_SIZE (mv->class0_hp); i++) + frame_ctx->class0_fp_hp[i].class0_hp = mv-Quoted 1 line
class0_hp[i];
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +6
-0+ +for (i =0 ; i <ARRAY_SIZE (mv->hp); i++) + frame_ctx->class0_fp_hp[i].hp = mv->hp[i]; +} + +static int vdec_vp9_slice_update_prob(struct
vdec_vp9_slice_instance*instance,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +15
-0+ struct vdec_vp9_slice_vsi *vsi) +{ +struct vdec_vp9_slice_frame_ctx *pre_frame_ctx; +struct v4l2_vp9_frame_context *pre_frame_ctx_helper; +struct vdec_vp9_slice_frame_ctx *frame_ctx; +struct vdec_vp9_slice_frame_counts *counts; +struct v4l2_vp9_frame_symbol_counts *counts_helper; +struct vdec_vp9_slice_uncompressed_header *uh; +bool frame_is_intra; +bool use_128; + + uh = &vsi->frame.uh; + pre_frame_ctx = &instance->frame_ctx[uh->frame_context_idx]; + pre_frame_ctx_helper = &instance->frame_ctx_helper; + frame_ctx = (struct vdec_vp9_slice_frame_ctx *)instance-Quoted 1 line
prob.va;
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ counts = (struct vdec_vp9_slice_frame_counts *)instance-Quoted 1 line
counts.va;
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +7
-0+ counts_helper = &instance->counts_helper; + +if (!uh->refresh_frame_context) +return 0 ; + +if (!uh->frame_parallel_decoding_mode) { + vdec_vp9_slice_counts_map_helper(&instance->counts_map,counts,
counts_helper);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+ + frame_is_intra = !vsi->frame.uh.frame_type || vsi-Quoted 1 line
frame.uh.intra_only;
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+/* check default prob */ +if (!instance->dirty[uh->frame_context_idx]) + vdec_vp9_slice_framectx_map_helper(frame_is_intra,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ vdec_vp9_sli
ce_default_frame_ctx,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+ frame_ctx, + pre_frame_ct
x_helper);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+else + vdec_vp9_slice_framectx_map_helper(frame_is_intra,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ pre_frame_ctx,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+ frame_ctx, + pre_frame_ct
x_helper);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+ + use_128 = !frame_is_intra && !vsi-Quoted 1 line
frame.uh.last_frame_type;
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +6
-0+v4l2_vp9_adapt_coef_probs (pre_frame_ctx_helper, + counts_helper, + use_128, + frame_is_intra); +if (!frame_is_intra) + v4l2_vp9_adapt_noncoef_probs(pre_frame_ctx_helper,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+ counts_helper, +V4L2_VP9_REFERENCE
_MODE_SINGLE_REFERENCE,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ vsi-Quoted 1 line
frame.uh.interpolation_filter,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ vsi-Quoted 1 line
frame.ch.tx_mode,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ vsi-Quoted 1 line
frame.uh.allow_high_precision_mv ?
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+V4L2_VP9_FRAME_FLA
G_ALLOW_HIGH_PREC_MV: 0);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ vdec_vp9_slice_helper_map_framectx(pre_frame_ctx_helper,
pre_frame_ctx);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +10
-0+ }else { +memcpy (pre_frame_ctx, frame_ctx,sizeof (*frame_ctx)); + } + + instance->dirty[uh->frame_context_idx] =1 ; + +return 0 ; +} + +static int vdec_vp9_slice_update_lat(struct
vdec_vp9_slice_instance*instance,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +33
-0+struct vdec_lat_buf *lat_buf, + struct vdec_vp9_slice_pfc *pfc) +{ + struct vdec_vp9_slice_vsi *vsi; + + vsi = &pfc->vsi; +memcpy (&pfc->state[0 ], &vsi->state,sizeof (vsi->state)); + +mtk_vcodec_debug (instance,"Frame %u LAT CRC 0x%08x %lx %lx\n" , + pfc->seq, vsi->state.crc[0 ], + (unsigned long )vsi->trans.dma_addr, + (unsigned long )vsi->trans.dma_addr_end); + +/* buffer full, need to re-decode */ +if (vsi->state.full) { +/* buffer not enough */ +if (vsi->trans.dma_addr_end - vsi->trans.dma_addr == + vsi->ube.size) +return -ENOMEM ; +return -EAGAIN ; + } + +vdec_vp9_slice_update_prob (instance, vsi); + + instance->width = vsi->frame.uh.frame_width; + instance->height = vsi->frame.uh.frame_height; + instance->frame_type = vsi->frame.uh.frame_type; + instance->show_frame = vsi->frame.uh.show_frame; + +return 0 ; +} + +static int vdec_vp9_slice_setup_core_to_dst_buf(struct
vdec_vp9_slice_instance*instance,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+struct vdec_lat_buf
*lat_buf)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +12
-0+{ +struct vb2_v4l2_buffer *dst; + + dst =v4l2_m2m_next_dst_buf (instance->ctx->m2m_ctx); +if (!dst) +return -EINVAL ; + +v4l2_m2m_buf_copy_metadata (&lat_buf->ts_info, dst, true); +return 0 ; +} + +static int vdec_vp9_slice_setup_core_buffer(struct
vdec_vp9_slice_instance*instance,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+struct vdec_vp9_slice_pfc *pfc,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+struct vdec_vp9_slice_vsi *vsi,
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+struct vdec_fb *fb, + struct vdec_lat_buf
*lat_buf)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +66
-0+{ +struct vb2_buffer *vb; +struct vb2_queue *vq; +struct vdec_vp9_slice_reference *ref; +int plane; +int size; +int idx; +int w; +int h; +int i; + + plane = instance->ctx->q_data[MTK_Q_DATA_DST ].fmt->num_planes; + w = vsi->frame.uh.frame_width; + h = vsi->frame.uh.frame_height; + size =ALIGN (w,64 ) *ALIGN (h,64 ); + +/* frame buffer */ + vsi->fb.y.dma_addr = fb->base_y.dma_addr; +if (plane ==1 ) + vsi->fb.c.dma_addr = fb->base_y.dma_addr + size; +else + vsi->fb.c.dma_addr = fb->base_c.dma_addr; + +/* reference buffers */ + vq =v4l2_m2m_get_vq (instance->ctx->m2m_ctx, +V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ); +if (!vq) +return -EINVAL ; + +/* get current output buffer */ + vb = &v4l2_m2m_next_dst_buf (instance->ctx->m2m_ctx)->vb2_buf; +if (!vb) +return -EINVAL ; + +/* update internal buffer's width/height */ +for (i =0 ; i < vq->num_buffers; i++) { +if (vb == vq->bufs[i]) { + instance->dpb[i].width = w; + instance->dpb[i].height = h; +break ; + } + } + +/* +* get buffer's width/height from instance +* get buffer address from vb2buf +*/ +for (i =0 ; i <3 ; i++) { + ref = &vsi->frame.ref[i]; + idx =vb2_find_timestamp (vq, pfc->ref_idx[i],0 ); +if (idx <0 ) { + ref->frame_width = w; + ref->frame_height = h; +memset (&vsi->ref[i],0 ,sizeof (vsi->ref[i])); + }else { + ref->frame_width = instance->dpb[idx].width; + ref->frame_height = instance->dpb[idx].height; + vb = vq->bufs[idx]; + vsi->ref[i].y.dma_addr = +vb2_dma_contig_plane_dma_addr (vb,0 ); +if (plane ==1 ) + vsi->ref[i].c.dma_addr = + vsi->ref[i].y.dma_addr + size; +else + vsi->ref[i].c.dma_addr = + vb2_dma_contig_plane_dma_addr(vb, 1);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +7
-0+ } + } + +return 0 ; +} + +static int vdec_vp9_slice_setup_core(struct
vdec_vp9_slice_instance*instance,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +14
-0+struct vdec_fb *fb, + struct vdec_lat_buf *lat_buf, + struct vdec_vp9_slice_pfc *pfc) +{ + struct vdec_vp9_slice_vsi *vsi = &pfc->vsi; +int ret; + +vdec_vp9_slice_setup_state (vsi); + + ret =vdec_vp9_slice_setup_core_to_dst_buf (instance, lat_buf); +if (ret) + goto err; + + ret = vdec_vp9_slice_setup_core_buffer(instance, pfc, vsi, fb,
lat_buf);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+if (ret) + goto err; + + vdec_vp9_slice_setup_seg_buffer(instance, vsi, &instance-Quoted 1 line
seg[1]);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +8
-0+ +return 0 ; + +err: +return ret; +} + +static int vdec_vp9_slice_update_core(struct
vdec_vp9_slice_instance*instance,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +9
-0+struct vdec_lat_buf *lat_buf, + struct vdec_vp9_slice_pfc *pfc) +{ + struct vdec_vp9_slice_vsi *vsi; + + vsi = &pfc->vsi; +memcpy (&pfc->state[1 ], &vsi->state,sizeof (vsi->state)); + + mtk_vcodec_debug(instance, "Frame %u Y_CRC %08x %08x %08x%08x\n",
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ pfc->seq, + vsi->state.crc[0 ], vsi->state.crc[1 ], + vsi->state.crc[2], vsi->state.crc[3]); + mtk_vcodec_debug(instance, "Frame %u C_CRC %08x %08x %08x%08x\n",
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +26
-0+ pfc->seq, + vsi->state.crc[4 ], vsi->state.crc[5 ], + vsi->state.crc[6], vsi->state.crc[7]); + +return 0 ; +} + +static int vdec_vp9_slice_init (struct mtk_vcodec_ctx *ctx) +{ +struct vdec_vp9_slice_instance *instance; +struct vdec_vp9_slice_init_vsi *vsi; +int ret; + + instance =kzalloc (sizeof (*instance),GFP_KERNEL ); +if (!instance) +return -ENOMEM ; + + instance->ctx = ctx; + instance->vpu.id =SCP_IPI_VDEC_LAT ; + instance->vpu.core_id =SCP_IPI_VDEC_CORE ; + instance->vpu.ctx = ctx; + instance->vpu.codec_type = ctx->current_codec; + + ret =vpu_dec_init (&instance->vpu); +if (ret) { + mtk_vcodec_err(instance, "failed to init vpu dec, ret%d\n", ret);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +13
-0+ goto error_vpu_init; + } + +/* init vsi and global flags */ + + vsi = instance->vpu.vsi; +if (!vsi) { +mtk_vcodec_err (instance,"failed to get VP9 vsi\n" ); + ret = -EINVAL ; + goto error_vsi; + } + instance->init_vsi = vsi; + instance->core_vsi = mtk_vcodec_fw_map_dm_addr(ctx->dev-Quoted 1 line
fw_handler,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ (u32)vsi-Quoted 1 line
core_vsi);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+if (!instance->core_vsi) { + mtk_vcodec_err(instance, "failed to get VP9 corevsi\n");
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +32
-0+ ret = -EINVAL ; + goto error_vsi; + } + + instance->irq =1 ; + + ret =vdec_vp9_slice_init_default_frame_ctx (instance); +if (ret) + goto error_default_frame_ctx; + + ctx->drv_handle = instance; + +return 0 ; + +error_default_frame_ctx: +error_vsi: +vpu_dec_deinit (&instance->vpu); +error_vpu_init: +kfree (instance); +return ret; +} + +static void vdec_vp9_slice_deinit (void *h_vdec) +{ +struct vdec_vp9_slice_instance *instance = h_vdec; + +if (!instance) +return ; + +vpu_dec_deinit (&instance->vpu); +vdec_vp9_slice_free_working_buffer (instance); + vdec_msg_queue_deinit(&instance->ctx->msg_queue, instance-Quoted 1 line
ctx);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+kfree (instance); +} + +static int vdec_vp9_slice_flush(void *h_vdec, struct
mtk_vcodec_mem*bs,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +11
-0+ struct vdec_fb *fb, bool *res_chg) +{ + struct vdec_vp9_slice_instance *instance = h_vdec; + +mtk_vcodec_debug (instance,"flush ...\n" ); + +vdec_msg_queue_wait_lat_buf_full (&instance->ctx->msg_queue); +return vpu_dec_reset (&instance->vpu); +} + +static void vdec_vp9_slice_get_pic_info(struct
vdec_vp9_slice_instance*instance)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +19
-0+{ +struct mtk_vcodec_ctx *ctx = instance->ctx; +unsigned int data[3 ]; + +mtk_vcodec_debug (instance,"w %u h %u\n" , + ctx->picinfo.pic_w, ctx->picinfo.pic_h); + + data[0 ] = ctx->picinfo.pic_w; + data[1 ] = ctx->picinfo.pic_h; + data[2 ] = ctx->capture_fourcc; +vpu_dec_get_param (&instance->vpu, data,3 ,GET_PARAM_PIC_INFO ); + + ctx->picinfo.buf_w =ALIGN (ctx->picinfo.pic_w,64 ); + ctx->picinfo.buf_h =ALIGN (ctx->picinfo.pic_h,64 ); + ctx->picinfo.fb_sz[0 ] = instance->vpu.fb_sz[0 ]; + ctx->picinfo.fb_sz[1 ] = instance->vpu.fb_sz[1 ]; +} + +static void vdec_vp9_slice_get_dpb_size(struct
vdec_vp9_slice_instance*instance,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +7
-0+ unsigned int *dpb_sz) +{ +/* refer VP9 specification */ + *dpb_sz =9 ; +} + +static int vdec_vp9_slice_get_param(void *h_vdec, enum
vdec_get_param_typetype, void *out)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +12
-0+{ +struct vdec_vp9_slice_instance *instance = h_vdec; + +switch (type) { +case GET_PARAM_PIC_INFO : +vdec_vp9_slice_get_pic_info (instance); +break ; +case GET_PARAM_DPB_SIZE : +vdec_vp9_slice_get_dpb_size (instance, out); +break ; +case GET_PARAM_CROP_INFO : + mtk_vcodec_debug(instance, "No need to get vp9 cropinformation.");
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+break ; +default : + mtk_vcodec_err(instance, "invalid get parametertype=%d\n",
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +8
-0+ type); +return -EINVAL ; + } + +return 0 ; +} + +static int vdec_vp9_slice_lat_decode(void *h_vdec, struct
mtk_vcodec_mem*bs,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +24
-0+ struct vdec_fb *fb, bool *res_chg) +{ + struct vdec_vp9_slice_instance *instance = h_vdec; +struct vdec_lat_buf *lat_buf; +struct vdec_vp9_slice_pfc *pfc; +struct vdec_vp9_slice_vsi *vsi; +struct mtk_vcodec_ctx *ctx; +int ret; + +if (!instance || !instance->ctx) +return -EINVAL ; + ctx = instance->ctx; + +/* init msgQ for the first time */ +if (vdec_msg_queue_init (&ctx->msg_queue, ctx, + vdec_vp9_slice_core_decode, +sizeof (*pfc))) +return -ENOMEM ; + +/* bs NULL means flush decoder */ +if (!bs) +return vdec_vp9_slice_flush (h_vdec, bs, fb, res_chg); + + lat_buf = vdec_msg_queue_dqbuf(&instance->ctx-Quoted 1 line
msg_queue.lat_ctx);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +2
-0+if (!lat_buf) { + mtk_vcodec_err(instance, "Failed to get VP9 latbuf\n");
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +10
-0+return -EBUSY ; + } + pfc = (struct vdec_vp9_slice_pfc *)lat_buf->private_data; +if (!pfc) +return -EINVAL ; + vsi = &pfc->vsi; + + ret =vdec_vp9_slice_setup_lat (instance, bs, lat_buf, pfc); +if (ret) { + mtk_vcodec_err(instance, "Failed to setup VP9 lat ret%d\n", ret);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +7
-0+return ret; + } +vdec_vp9_slice_vsi_to_remote (vsi, instance->vsi); + + ret =vpu_dec_start (&instance->vpu,0 ,0 ); +if (ret) { + mtk_vcodec_err(instance, "Failed to dec VP9 ret %d\n",ret);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +5
-0+return ret; + } + +if (instance->irq) { + ret = mtk_vcodec_wait_for_done_ctx(ctx, MTK_INST_IR
Q_RECEIVED,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+WAIT_INTR_TIMEOUT_MS ,
MTK_VDEC_LAT0);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+/* update remote vsi if decode timeout */ +if (ret) { + mtk_vcodec_err(instance, "VP9 decode timeout %dpic %d\n", ret,
pfc->seq);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +11
-0+writel (1 , &instance->vsi->state.timeout); + } +vpu_dec_end (&instance->vpu); + } + +vdec_vp9_slice_vsi_from_remote (vsi, instance->vsi,0 ); + ret =vdec_vp9_slice_update_lat (instance, lat_buf, pfc); + +/* LAT trans full, no more UBE or decode timeout */ +if (ret) { + mtk_vcodec_err(instance, "VP9 decode error: %d\n",ret);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +5
-0+return ret; + } + + mtk_vcodec_debug(instance, "lat dma 1 0x%llx 0x%llx\n", + pfc->vsi.trans.dma_addr, pfc-Quoted 1 line
vsi.trans.dma_addr_end);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ + vdec_msg_queue_update_ube_wptr(&ctx->msg_queue, + vsi->trans.dma_addr_end + + ctx-Quoted 1 line
msg_queue.wdma_addr.dma_addr);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +6
-0+vdec_msg_queue_qbuf (&ctx->dev->msg_queue_core_ctx, lat_buf); + +return 0 ; +} + +static int vdec_vp9_slice_core_decode(struct vdec_lat_buf
*lat_buf)drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +28
-0+{ +struct vdec_vp9_slice_instance *instance; +struct vdec_vp9_slice_pfc *pfc; +struct mtk_vcodec_ctx *ctx =NULL ; +struct vdec_fb *fb =NULL ; +int ret = -EINVAL ; + +if (!lat_buf) + goto err; + + pfc = lat_buf->private_data; + ctx = lat_buf->ctx; +if (!pfc || !ctx) + goto err; + + instance = ctx->drv_handle; +if (!instance) + goto err; + + fb = ctx->dev->vdec_pdata->get_cap_buffer (ctx); +if (!fb) { + ret = -EBUSY ; + goto err; + } + + ret =vdec_vp9_slice_setup_core (instance, fb, lat_buf, pfc); +if (ret) { + mtk_vcodec_err(instance,"vdec_vp9_slice_setup_core\n");
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +12
-0+ goto err; + } +vdec_vp9_slice_vsi_to_remote (&pfc->vsi, instance->core_vsi); + + ret =vpu_dec_core (&instance->vpu); +if (ret) { +mtk_vcodec_err (instance,"vpu_dec_core\n" ); + goto err; + } + +if (instance->irq) { + ret = mtk_vcodec_wait_for_done_ctx(ctx,
MTK_INST_IRQ_RECEIVED,drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+WAIT_INTR_TIMEOUT_MS ,
MTK_VDEC_CORE);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+/* update remote vsi if decode timeout */ +if (ret) { + mtk_vcodec_err(instance, "VP9 core timeout pic%d\n",
pfc->seq);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +6
-0+writel (1 , &instance->core_vsi->state.timeout); + } +vpu_dec_core_end (&instance->vpu); + } + + vdec_vp9_slice_vsi_from_remote(&pfc->vsi, instance->core_vsi,1);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+ ret =vdec_vp9_slice_update_core (instance, lat_buf, pfc); +if (ret) { + mtk_vcodec_err(instance,"vdec_vp9_slice_update_core\n");
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +4
-0+ goto err; + } + + pfc->vsi.trans.dma_addr_end += ctx-Quoted 1 line
msg_queue.wdma_addr.dma_addr;
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ mtk_vcodec_debug(instance, "core dma_addr_end 0x%llx\n", pfc-Quoted 1 line
vsi.trans.dma_addr_end);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ vdec_msg_queue_update_ube_rptr(&ctx->msg_queue, pfc-Quoted 1 line
vsi.trans.dma_addr_end);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1
-0+ ctx->dev->vdec_pdata->cap_to_disp(ctx, 0, lat_buf-Quoted 1 line
src_buf_req);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +7
-0+ +return 0 ; + +err: +if (ctx) { +/* always update read pointer */ + vdec_msg_queue_update_ube_rptr(&ctx->msg_queue, pfc-Quoted 1 line
vsi.trans.dma_addr_end);
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +3
-0+ +if (fb) + ctx->dev->vdec_pdata->cap_to_disp(ctx, 1,
lat_buf->src_buf_req);drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +10
-0+ } +return ret; +} + +const struct vdec_common_if vdec_vp9_slice_lat_if = { + .init = vdec_vp9_slice_init, + .decode = vdec_vp9_slice_lat_decode, + .get_param = vdec_vp9_slice_get_param, + .deinit = vdec_vp9_slice_deinit, +};drivers/media/platform/mediatek/vcodec/vdec_drv_if.c +4
-0@@ -45,6 +45,10 @@ int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc) ctx->dec_if = &vdec_vp9_if; ctx->hw_id =MTK_VDEC_CORE ;break ; +case V4L2_PIX_FMT_VP9_FRAME : + ctx->dec_if = &vdec_vp9_slice_lat_if; + ctx->hw_id =MTK_VDEC_LAT0 ; +break ;default :return -EINVAL ;drivers/media/platform/mediatek/vcodec/vdec_drv_if.c +0
-0}drivers/media/platform/mediatek/vcodec/vdec_drv_if.h +1
-0@@ -60,6 +60,7 @@ extern const struct vdec_common_if vdec_h264_slice_multi_if;extern const struct vdec_common_if vdec_vp8_if;extern const struct vdec_common_if vdec_vp8_slice_if;extern const struct vdec_common_if vdec_vp9_if; +extern const struct vdec_common_if vdec_vp9_slice_lat_if;/** *
vdec_if_init()- initialize decode driver
Yunfei Dong
maintainerPATCH v8 17/17 media: mediatek: vcodec: prevent kernel crash when rmmod mtk-vcodec-dec.ko
In reply to Yunfei DongIf the driver support subdev mode, the parameter "dev->pm.dev" will be NULL in mtk_vcodec_dec_remove. Kernel will crash when try to rmmod mtk-vcodec-dec.ko.
[ 4380.702726] pc : do_raw_spin_trylock+0x4/0x80 [ 4380.707075] lr : _raw_spin_lock_irq+0x90/0x14c [ 4380.711509] sp : ffff80000819bc10 [ 4380.714811] x29: ffff80000819bc10 x28: ffff3600c03e4000 x27: 0000000000000000 [ 4380.721934] x26: 0000000000000000 x25: 0000000000000000 x24: 0000000000000000 [ 4380.729057] x23: ffff3600c0f34930 x22: ffffd5e923549000 x21: 0000000000000220 [ 4380.736179] x20: 0000000000000208 x19: ffffd5e9213e8ebc x18: 0000000000000020 [ 4380.743298] x17: 0000002000000000 x16: ffffd5e9213e8e90 x15: 696c346f65646976 [ 4380.750420] x14: 0000000000000000 x13: 0000000000000001 x12: 0000000000000040 [ 4380.757542] x11: 0000000000000000 x10: 0000000000000000 x9 : 0000000000000000 [ 4380.764664] x8 : 0000000000000000 x7 : ffff3600c7273ae8 x6 : ffffd5e9213e8ebc [ 4380.771786] x5 : 0000000000000000 x4 : 0000000000000001 x3 : 0000000000000000 [ 4380.778908] x2 : 0000000000000000 x1 : ffff3600c03e4000 x0 : 0000000000000208 [ 4380.786031] Call trace: [ 4380.788465] do_raw_spin_trylock+0x4/0x80 [ 4380.792462] __pm_runtime_disable+0x2c/0x1b0 [ 4380.796723] mtk_vcodec_dec_remove+0x5c/0xa0 [mtk_vcodec_dec] [ 4380.802466] platform_remove+0x2c/0x60 [ 4380.806204] __device_release_driver+0x194/0x250 [ 4380.810810] driver_detach+0xc8/0x15c [ 4380.814462] bus_remove_driver+0x5c/0xb0 [ 4380.818375] driver_unregister+0x34/0x64 [ 4380.822288] platform_driver_unregister+0x18/0x24 [ 4380.826979] mtk_vcodec_dec_driver_exit+0x1c/0x888 [mtk_vcodec_dec] [ 4380.833240] __arm64_sys_delete_module+0x190/0x224 [ 4380.838020] invoke_syscall+0x48/0x114 [ 4380.841760] el0_svc_common.constprop.0+0x60/0x11c [ 4380.846540] do_el0_svc+0x28/0x90 [ 4380.849844] el0_svc+0x4c/0x100 [ 4380.852975] el0t_64_sync_handler+0xec/0xf0 [ 4380.857148] el0t_64_sync+0x190/0x194 [ 4380.860801] Code: 94431515 17ffffca d503201f d503245f (b9400004)
--- drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c +2 -1
@@ -482,7 +482,8 @@ static int mtk_vcodec_dec_remove(struct platform_device *pdev)video_unregister_device (dev->vfd_dec);v4l2_device_unregister (&dev->v4l2_dev); -pm_runtime_disable (dev->pm.dev); +if (!dev->vdec_pdata->is_subdev_supported) +pm_runtime_disable (dev->pm.dev);mtk_vcodec_fw_release (dev->fw_handler);return 0 ; }
Signature · 1 line
2.18.0
Hi Yunfei,
thanks for the update, I should be testing this really soon.
Le jeudi 31 mars 2022 à 10:47 +0800, Yunfei Dong a écrit :
Quoted 2 lines
This series adds support for mt8192 h264/vp8/vp9 decoder drivers. Firstly, refactor power/clock/interrupt interfaces for mt8192 is lat and core architecture.
Similarly to MT8173 and MT8183, a shared* firmware is needed for this CODEC to work (scp.img). I looked into linux-firmware[1] it has not been added for mt8192 yet. As your patches are getting close to be ready, it would be important to look into this so the patchset does not get blocked due to that.
best regards,
Nicolas
[1] https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/mediatek
* Shared at least between MDP3 and MTK VCODEC from my knowledge
Quoted 110 lines
Secondly, add new functions to get frame buffer size and resolution according to decoder capability from scp side. Then add callback function to get/put capture buffer in order to enable lat and core decoder in parallel, need to adjust GStreamer at the same time.
Then add to support MT21C compressed mode and fix v4l2-compliance fail.
Next, extract H264 request api driver to let mt8183 and mt8192 use the same code, and adds mt8192 frame based h264 driver for stateless decoder.
Lastly, add vp8 and vp9 stateless decoder drivers.
Patches 1 refactor power/clock/interrupt interface.
Patches 2~4 get frame buffer size and resolution according to decoder capability. Patches 5 set capture queue bytesused.
Patches 6 adjust GStreamer.
Patch 7~11 add to support MT21C compressed mode and fix v4l2-compliance fail. patch 12 record capture queue format type.
Patch 13~14 extract h264 driver and add mt8192 frame based driver for h264 decoder. Patch 15~16 add vp8 and vp9 stateless decoder drivers.
Patch 17 prevent kernel crash when rmmod mtk-vcodec-dec.ko
---
changes compared with v6:
- adjust GStreamer, separate src buffer done withv4l2_ctrl_request_completefor patch 6.
- removev4l2_m2m_set_dst_buffered.
- add new patch to set each plane bytesused in buf prepare for patch 5.
- using upstream interface to update vp9 prob tables for patch 16.
- fix maintainer comments.
- test the driver with chrome VD and GStreamer(H264/VP9/VP8/AV1).
changes compared with v6:
- rebase to the latest media stage and fix conficts
- fix memcpy tomemcpy_fromioormemcpy_toio
- fix h264 crash when test field bitstream
changes compared with v5:
- fix vp9 comments for patch 15
- fix vp8 comments for patch 14.
- fix comments for patch 12.
- fix build errors.
changes compared with v4:
- fix checkpatch.pl fail.
- fix kernel-doc fail.
- rebase to the latest media codec driver.
changes compared with v3:
- remove enummtk_chipfor patch 2.
- add vp8 stateless decoder drivers for patch 14.
- add vp9 stateless decoder drivers for patch 15.
changes compared with v2:
- add new patch 11 to record capture queue format type.
- separate patch 4 according to tzung-bi's suggestion.
- re-write commit message for patch 5 according to tzung-bi's suggestion. changes compared with v1:
- rewrite commit message for patch 12.
- rewrite cover-letter message.
---
Yunfei Dong (17):
media: mediatek: vcodec: Add vdec enable/disable hardware helpers
media: mediatek: vcodec: Using firmware type to separate different
firmware architecture
media: mediatek: vcodec: get capture queue buffer size from scp
media: mediatek: vcodec: Read max resolution fromdec_capability
media: mediatek: vcodec: set each plane bytesused in buf prepare
media: mediatek: vcodec: Refactor get and put capture buffer flow
media: mediatek: vcodec: Refactor supported vdec formats and
framesizes
media: mediatek: vcodec: Getting supported decoder format types
media: mediatek: vcodec: Add format to support MT21C
media: mediatek: vcodec: disable vp8 4K capability
media: mediatek: vcodec: Fix v4l2-compliance fail
media: mediatek: vcodec: record capture queue format type
media: mediatek: vcodec: Extract H264 common code
media: mediatek: vcodec: support stateless H.264 decoding for mt8192
media: mediatek: vcodec: support stateless VP8 decoding
media: mediatek: vcodec: support stateless VP9 decoding
media: mediatek: vcodec: prevent kernel crash when rmmod
mtk-vcodec-dec.ko.../media/platform/mediatek/vcodec/Makefile | 4 + .../platform/mediatek/vcodec/mtk_vcodec_dec.c | 62 +- .../mediatek/vcodec/mtk_vcodec_dec_drv.c | 8 +- .../mediatek/vcodec/mtk_vcodec_dec_pm.c | 166 +- .../mediatek/vcodec/mtk_vcodec_dec_pm.h | 6 +- .../mediatek/vcodec/mtk_vcodec_dec_stateful.c | 19 +- .../vcodec/mtk_vcodec_dec_stateless.c | 257 +- .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 41 +- .../mediatek/vcodec/mtk_vcodec_enc_drv.c | 5 - .../platform/mediatek/vcodec/mtk_vcodec_fw.c | 6 + .../platform/mediatek/vcodec/mtk_vcodec_fw.h | 1 + .../vcodec/vdec/vdec_h264_req_common.c | 310 +++ .../vcodec/vdec/vdec_h264_req_common.h | 272 +++ .../mediatek/vcodec/vdec/vdec_h264_req_if.c | 438 +--- .../vcodec/vdec/vdec_h264_req_multi_if.c | 619 +++++ .../mediatek/vcodec/vdec/vdec_vp8_req_if.c | 437 ++++ .../vcodec/vdec/vdec_vp9_req_lat_if.c | 2072 +++++++++++++++++ .../platform/mediatek/vcodec/vdec_drv_if.c | 37 +- .../platform/mediatek/vcodec/vdec_drv_if.h | 3 + .../platform/mediatek/vcodec/vdec_ipi_msg.h | 36 + .../platform/mediatek/vcodec/vdec_msg_queue.c | 2 + .../platform/mediatek/vcodec/vdec_msg_queue.h | 2 + .../platform/mediatek/vcodec/vdec_vpu_if.c | 53 +- .../platform/mediatek/vcodec/vdec_vpu_if.h | 15 + .../platform/mediatek/vcodec/venc_vpu_if.c | 2 +- include/linux/remoteproc/mtk_scp.h | 2 + 26 files changed, 4274 insertions(+), 601 deletions(-) create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.h create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
[email protected]
maintainerHi Nicolas,
Quoted 18 lines · Nicolas Dufresne
Hi Yunfei,
thanks for the update, I should be testing this really soon.
Quoted 4 lines · Yunfei Dong
This series adds support for mt8192 h264/vp8/vp9 decoder drivers. Firstly, refactor
power/clock/interrupt interfaces for mt8192 is lat and core architecture.Similarly to MT8173 and MT8183, a shared* firmware is needed for this CODEC to
work (scp.img). I looked into linux-firmware[1] it has not been added for mt8192
yet. As your patches are getting close to be ready, it would be important to
look into this so the patchset does not get blocked due to that.
Quoted 7 lines
best regards,
Nicolas[1]
https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/mediatek
* Shared at least between MDP3 and MTK VCODEC from my knowledge
Thanks for your remind.
I have already sent mt8192 scp.img to github.
Waiting for to be merged.
Best Regards,
Yunfei Dong
Quoted 133 lines
Quoted 131 lines
Secondly, add new functions to get frame buffer size and resolution according
to decoder capability from scp side. Then add callback function to get/put
capture buffer in order to enable lat and core decoder in parallel, need to
adjust GStreamer at the same time.Then add to support MT21C compressed mode and fix v4l2-compliance fail.
Next, extract H264 request api driver to let mt8183 and mt8192 use the same
code, and adds mt8192 frame based h264 driver for stateless decoder.Lastly, add vp8 and vp9 stateless decoder drivers.
Patches 1 refactor power/clock/interrupt interface. Patches 2~4 get frame buffer size and resolution according to decoder capability.
Patches 5 set capture queue bytesused.
Patches 6 adjust GStreamer.
Patch 7~11 add to support MT21C compressed mode and fix v4l2- compliance fail.
patch 12 record capture queue format type.
Patch 13~14 extract h264 driver and add mt8192 frame based driver for h264 decoder.
Patch 15~16 add vp8 and vp9 stateless decoder drivers. Patch 17 prevent kernel crash when rmmod mtk-vcodec-dec.ko
---
changes compared with v6:
- adjust GStreamer, separate src buffer done withv4l2_ctrl_request_completefor patch 6.
- removev4l2_m2m_set_dst_buffered.
- add new patch to set each plane bytesused in buf prepare for patch 5.
- using upstream interface to update vp9 prob tables for patch 16.
- fix maintainer comments.
- test the driver with chrome VD and GStreamer(H264/VP9/VP8/AV1). changes compared with v6:
- rebase to the latest media stage and fix conficts
- fix memcpy tomemcpy_fromioormemcpy_toio
- fix h264 crash when test field bitstream
changes compared with v5:
- fix vp9 comments for patch 15
- fix vp8 comments for patch 14.
- fix comments for patch 12.
- fix build errors.
changes compared with v4:
- fix checkpatch.pl fail.
- fix kernel-doc fail.
- rebase to the latest media codec driver.
changes compared with v3:
- remove enummtk_chipfor patch 2.
- add vp8 stateless decoder drivers for patch 14.
- add vp9 stateless decoder drivers for patch 15. changes compared with v2:
- add new patch 11 to record capture queue format type.
- separate patch 4 according to tzung-bi's suggestion.
- re-write commit message for patch 5 according to tzung-bi's suggestion.
changes compared with v1:
- rewrite commit message for patch 12.
- rewrite cover-letter message.
---
Yunfei Dong (17):
media: mediatek: vcodec: Add vdec enable/disable hardware helpers
media: mediatek: vcodec: Using firmware type to separate
different
firmware architecture
media: mediatek: vcodec: get capture queue buffer size from scp
media: mediatek: vcodec: Read max resolution fromdec_capability
media: mediatek: vcodec: set each plane bytesused in buf prepare
media: mediatek: vcodec: Refactor get and put capture buffer flow
media: mediatek: vcodec: Refactor supported vdec formats and
framesizes
media: mediatek: vcodec: Getting supported decoder format types
media: mediatek: vcodec: Add format to support MT21C
media: mediatek: vcodec: disable vp8 4K capability
media: mediatek: vcodec: Fix v4l2-compliance fail
media: mediatek: vcodec: record capture queue format type
media: mediatek: vcodec: Extract H264 common code
media: mediatek: vcodec: support stateless H.264 decoding for
mt8192
media: mediatek: vcodec: support stateless VP8 decoding
media: mediatek: vcodec: support stateless VP9 decoding
media: mediatek: vcodec: prevent kernel crash when rmmod
mtk-vcodec-dec.ko.../media/platform/mediatek/vcodec/Makefile | 4 + .../platform/mediatek/vcodec/mtk_vcodec_dec.c | 62 +- .../mediatek/vcodec/mtk_vcodec_dec_drv.c | 8 +- .../mediatek/vcodec/mtk_vcodec_dec_pm.c | 166 +- .../mediatek/vcodec/mtk_vcodec_dec_pm.h | 6 +- .../mediatek/vcodec/mtk_vcodec_dec_stateful.c | 19 +- .../vcodec/mtk_vcodec_dec_stateless.c | 257 +- .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 41 +- .../mediatek/vcodec/mtk_vcodec_enc_drv.c | 5 - .../platform/mediatek/vcodec/mtk_vcodec_fw.c | 6 + .../platform/mediatek/vcodec/mtk_vcodec_fw.h | 1 + .../vcodec/vdec/vdec_h264_req_common.c | 310 +++ .../vcodec/vdec/vdec_h264_req_common.h | 272 +++ .../mediatek/vcodec/vdec/vdec_h264_req_if.c | 438 +--- .../vcodec/vdec/vdec_h264_req_multi_if.c | 619 +++++ .../mediatek/vcodec/vdec/vdec_vp8_req_if.c | 437 ++++ .../vcodec/vdec/vdec_vp9_req_lat_if.c | 2072 +++++++++++++++++ .../platform/mediatek/vcodec/vdec_drv_if.c | 37 +- .../platform/mediatek/vcodec/vdec_drv_if.h | 3 + .../platform/mediatek/vcodec/vdec_ipi_msg.h | 36 + .../platform/mediatek/vcodec/vdec_msg_queue.c | 2 + .../platform/mediatek/vcodec/vdec_msg_queue.h | 2 + .../platform/mediatek/vcodec/vdec_vpu_if.c | 53 +- .../platform/mediatek/vcodec/vdec_vpu_if.h | 15 + .../platform/mediatek/vcodec/venc_vpu_if.c | 2 +- include/linux/remoteproc/mtk_scp.h | 2 + 26 files changed, 4274 insertions(+), 601 deletions(-) create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.h create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if. c create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c create mode 100644
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
Le lundi 11 avril 2022 à 11:41 +0800, [email protected] a écrit :
Quoted 29 lines
Hi Nicolas,
Quoted 18 lines · Nicolas Dufresne
Hi Yunfei,
thanks for the update, I should be testing this really soon.
Quoted 4 lines · Yunfei Dong
This series adds support for mt8192 h264/vp8/vp9 decoder drivers. Firstly, refactor
power/clock/interrupt interfaces for mt8192 is lat and core architecture.Similarly to MT8173 and MT8183, a shared* firmware is needed for this CODEC to
work (scp.img). I looked into linux-firmware[1] it has not been added for mt8192
yet. As your patches are getting close to be ready, it would be important to
look into this so the patchset does not get blocked due to that.Quoted 7 lines
best regards,
Nicolas[1]
https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/mediatek
* Shared at least between MDP3 and MTK VCODEC from my knowledge
Quoted 7 lines
Thanks for your remind.
I have already sent mt8192 scp.img to github.
Waiting for to be merged.
On boards I have, the firmware is loaded from /lib/firmware/scp.img, but with this submission it will be in lib/firmware/mediatek/mt8192/scp.img . I haven't found anything around:
drivers/remoteproc/mtk_scp.c:812: char *fw_name = "scp.img";
That would use the platform path. This seems like a problem to me, the upstreaming of the firmware isn't being aligned with the were the firmware is picked by the upstream driver. Correct me if I got this wrong, but I'd really like to clarify this.
Nicolas
Quoted 138 lines
Best Regards,
Yunfei DongQuoted 133 lines
Quoted 131 lines
Secondly, add new functions to get frame buffer size and resolution according
to decoder capability from scp side. Then add callback function to get/put
capture buffer in order to enable lat and core decoder in parallel, need to
adjust GStreamer at the same time.Then add to support MT21C compressed mode and fix v4l2-compliance fail.
Next, extract H264 request api driver to let mt8183 and mt8192 use the same
code, and adds mt8192 frame based h264 driver for stateless decoder.Lastly, add vp8 and vp9 stateless decoder drivers.
Patches 1 refactor power/clock/interrupt interface. Patches 2~4 get frame buffer size and resolution according to decoder capability.
Patches 5 set capture queue bytesused.
Patches 6 adjust GStreamer.
Patch 7~11 add to support MT21C compressed mode and fix v4l2- compliance fail.
patch 12 record capture queue format type.
Patch 13~14 extract h264 driver and add mt8192 frame based driver for h264 decoder.
Patch 15~16 add vp8 and vp9 stateless decoder drivers. Patch 17 prevent kernel crash when rmmod mtk-vcodec-dec.ko
---
changes compared with v6:
- adjust GStreamer, separate src buffer done withv4l2_ctrl_request_completefor patch 6.
- removev4l2_m2m_set_dst_buffered.
- add new patch to set each plane bytesused in buf prepare for patch 5.
- using upstream interface to update vp9 prob tables for patch 16.
- fix maintainer comments.
- test the driver with chrome VD and GStreamer(H264/VP9/VP8/AV1). changes compared with v6:
- rebase to the latest media stage and fix conficts
- fix memcpy tomemcpy_fromioormemcpy_toio
- fix h264 crash when test field bitstream
changes compared with v5:
- fix vp9 comments for patch 15
- fix vp8 comments for patch 14.
- fix comments for patch 12.
- fix build errors.
changes compared with v4:
- fix checkpatch.pl fail.
- fix kernel-doc fail.
- rebase to the latest media codec driver.
changes compared with v3:
- remove enummtk_chipfor patch 2.
- add vp8 stateless decoder drivers for patch 14.
- add vp9 stateless decoder drivers for patch 15. changes compared with v2:
- add new patch 11 to record capture queue format type.
- separate patch 4 according to tzung-bi's suggestion.
- re-write commit message for patch 5 according to tzung-bi's suggestion.
changes compared with v1:
- rewrite commit message for patch 12.
- rewrite cover-letter message.
---
Yunfei Dong (17):
media: mediatek: vcodec: Add vdec enable/disable hardware helpers
media: mediatek: vcodec: Using firmware type to separate
different
firmware architecture
media: mediatek: vcodec: get capture queue buffer size from scp
media: mediatek: vcodec: Read max resolution fromdec_capability
media: mediatek: vcodec: set each plane bytesused in buf prepare
media: mediatek: vcodec: Refactor get and put capture buffer flow
media: mediatek: vcodec: Refactor supported vdec formats and
framesizes
media: mediatek: vcodec: Getting supported decoder format types
media: mediatek: vcodec: Add format to support MT21C
media: mediatek: vcodec: disable vp8 4K capability
media: mediatek: vcodec: Fix v4l2-compliance fail
media: mediatek: vcodec: record capture queue format type
media: mediatek: vcodec: Extract H264 common code
media: mediatek: vcodec: support stateless H.264 decoding for
mt8192
media: mediatek: vcodec: support stateless VP8 decoding
media: mediatek: vcodec: support stateless VP9 decoding
media: mediatek: vcodec: prevent kernel crash when rmmod
mtk-vcodec-dec.ko.../media/platform/mediatek/vcodec/Makefile | 4 + .../platform/mediatek/vcodec/mtk_vcodec_dec.c | 62 +- .../mediatek/vcodec/mtk_vcodec_dec_drv.c | 8 +- .../mediatek/vcodec/mtk_vcodec_dec_pm.c | 166 +- .../mediatek/vcodec/mtk_vcodec_dec_pm.h | 6 +- .../mediatek/vcodec/mtk_vcodec_dec_stateful.c | 19 +- .../vcodec/mtk_vcodec_dec_stateless.c | 257 +- .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 41 +- .../mediatek/vcodec/mtk_vcodec_enc_drv.c | 5 - .../platform/mediatek/vcodec/mtk_vcodec_fw.c | 6 + .../platform/mediatek/vcodec/mtk_vcodec_fw.h | 1 + .../vcodec/vdec/vdec_h264_req_common.c | 310 +++ .../vcodec/vdec/vdec_h264_req_common.h | 272 +++ .../mediatek/vcodec/vdec/vdec_h264_req_if.c | 438 +--- .../vcodec/vdec/vdec_h264_req_multi_if.c | 619 +++++ .../mediatek/vcodec/vdec/vdec_vp8_req_if.c | 437 ++++ .../vcodec/vdec/vdec_vp9_req_lat_if.c | 2072 +++++++++++++++++ .../platform/mediatek/vcodec/vdec_drv_if.c | 37 +- .../platform/mediatek/vcodec/vdec_drv_if.h | 3 + .../platform/mediatek/vcodec/vdec_ipi_msg.h | 36 + .../platform/mediatek/vcodec/vdec_msg_queue.c | 2 + .../platform/mediatek/vcodec/vdec_msg_queue.h | 2 + .../platform/mediatek/vcodec/vdec_vpu_if.c | 53 +- .../platform/mediatek/vcodec/vdec_vpu_if.h | 15 + .../platform/mediatek/vcodec/venc_vpu_if.c | 2 +- include/linux/remoteproc/mtk_scp.h | 2 + 26 files changed, 4274 insertions(+), 601 deletions(-) create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.h create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if. c create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c create mode 100644
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
Hi Nicolas,
Quoted 31 lines · Nicolas Dufresne
Le lundi 11 avril 2022 à 11:41 +0800, [email protected] a écrit :
Quoted 29 lines
Hi Nicolas,
Quoted 26 lines · Nicolas Dufresne
Hi Yunfei,
thanks for the update, I should be testing this really soon.
Quoted 5 lines · Yunfei Dong
This series adds support for mt8192 h264/vp8/vp9 decoder drivers.
Firstly, refactor
power/clock/interrupt interfaces for mt8192 is lat and core architecture.Similarly to MT8173 and MT8183, a shared* firmware is needed for this
CODEC to
work (scp.img). I looked into linux-firmware[1] it has not been added
for mt8192
yet. As your patches are getting close to be ready, it would be important to
look into this so the patchset does not get blocked due to that.best regards,
Nicolas[1]
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
* Shared at least between MDP3 and MTK VCODEC from my knowledge
Thanks for your remind.
I have already sent mt8192 scp.img to github.
Quoted 20 lines
Quoted 3 lines
Waiting for to be merged.
On boards I have, the firmware is loaded from
/lib/firmware/scp.img, but with
this submission it will be inlib/firmware/mediatek/mt8192/scp.img. I haven't
found anything around:
drivers/remoteproc/mtk_scp.c:812: char*fw_name= "scp.img";That would use the platform path. This seems like a problem to me, the
upstreaming of the firmware isn't being aligned with the were the firmware is
picked by the upstream driver. Correct me if I got this wrong, but I'd really
like to clarify this.
Quoted 2 lines
Nicolas
I am not sure why it's accepted the fw path of scp is /lib/firmware/scp.img in mt8173/8183 but we upload scp.ing in /lib/firmware/mediatek/mt8173(mt8183)/scp.img to
https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/mediatek
Currently, the scp driver will load firmware in /lib/firmware/scp.img. that means there is only one firmware for a specific platform. I think we can send a PATCH to make firmware name of scp being more flexible.
Maybe get firmware name from dts. e.g.,
&scp {
status = "okay";
firmware-name = "mediatek/mt81xx/scp.img";
};Do you think it feasible?
If you have any concerns, please let us know.
Thanks,
Allen
Quoted 147 lines
Quoted 147 lines
Best Regards,
Yunfei DongQuoted 143 lines
Quoted 143 lines
Secondly, add new functions to get frame buffer size and resolution
according
to decoder capability from scp side. Then add callback function to
get/put
capture buffer in order to enable lat and core decoder in parallel,
need to
adjust GStreamer at the same time.Then add to support MT21C compressed mode and fix v4l2- compliance
fail.Next, extract H264 request api driver to let mt8183 and mt8192 use
the same
code, and adds mt8192 frame based h264 driver for stateless decoder.Lastly, add vp8 and vp9 stateless decoder drivers.
Patches 1 refactor power/clock/interrupt interface. Patches 2~4 get frame buffer size and resolution according to decoder capability.
Patches 5 set capture queue bytesused.
Patches 6 adjust GStreamer.
Patch 7~11 add to support MT21C compressed mode and fix v4l2- compliance fail.
patch 12 record capture queue format type.
Patch 13~14 extract h264 driver and add mt8192 frame based driver
for h264 decoder.
Patch 15~16 add vp8 and vp9 stateless decoder drivers. Patch 17 prevent kernel crash when rmmod mtk-vcodec-dec.ko
---
changes compared with v6:
- adjust GStreamer, separate src buffer done withv4l2_ctrl_request_completefor patch 6.
- removev4l2_m2m_set_dst_buffered.
- add new patch to set each plane bytesused in buf prepare for patch 5.
- using upstream interface to update vp9 prob tables for patch 16.
- fix maintainer comments.
- test the driver with chrome VD and GStreamer(H264/VP9/VP8/AV1).
changes compared with v6:
- rebase to the latest media stage and fix conficts
- fix memcpy tomemcpy_fromioormemcpy_toio
- fix h264 crash when test field bitstream
changes compared with v5:
- fix vp9 comments for patch 15
- fix vp8 comments for patch 14.
- fix comments for patch 12.
- fix build errors.
changes compared with v4:
- fix checkpatch.pl fail.
- fix kernel-doc fail.
- rebase to the latest media codec driver.
changes compared with v3:
- remove enummtk_chipfor patch 2.
- add vp8 stateless decoder drivers for patch 14.
- add vp9 stateless decoder drivers for patch 15. changes compared with v2:
- add new patch 11 to record capture queue format type.
- separate patch 4 according to tzung-bi's suggestion.
- re-write commit message for patch 5 according to tzung-bi's suggestion.
changes compared with v1:
- rewrite commit message for patch 12.
- rewrite cover-letter message.
---
Yunfei Dong (17):
media: mediatek: vcodec: Add vdec enable/disable hardware
helpers
media: mediatek: vcodec: Using firmware type to separate
different
firmware architecture
media: mediatek: vcodec: get capture queue buffer size from
scp
media: mediatek: vcodec: Read max resolution fromdec_capability
media: mediatek: vcodec: set each plane bytesused in buf
prepare
media: mediatek: vcodec: Refactor get and put capture buffer
flow
media: mediatek: vcodec: Refactor supported vdec formats and
framesizes
media: mediatek: vcodec: Getting supported decoder format
types
media: mediatek: vcodec: Add format to support MT21C
media: mediatek: vcodec: disable vp8 4K capability
media: mediatek: vcodec: Fix v4l2-compliance fail
media: mediatek: vcodec: record capture queue format type
media: mediatek: vcodec: Extract H264 common code
media: mediatek: vcodec: support stateless H.264 decoding for
mt8192
media: mediatek: vcodec: support stateless VP8 decoding
media: mediatek: vcodec: support stateless VP9 decoding
media: mediatek: vcodec: prevent kernel crash when rmmod
mtk-vcodec-dec.ko.../media/platform/mediatek/vcodec/Makefile | 4 + .../platform/mediatek/vcodec/mtk_vcodec_dec.c | 62 +- .../mediatek/vcodec/mtk_vcodec_dec_drv.c | 8 +- .../mediatek/vcodec/mtk_vcodec_dec_pm.c | 166 +- .../mediatek/vcodec/mtk_vcodec_dec_pm.h | 6 +- .../mediatek/vcodec/mtk_vcodec_dec_stateful.c | 19 +- .../vcodec/mtk_vcodec_dec_stateless.c | 257 +- .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 41 +- .../mediatek/vcodec/mtk_vcodec_enc_drv.c | 5 - .../platform/mediatek/vcodec/mtk_vcodec_fw.c | 6 + .../platform/mediatek/vcodec/mtk_vcodec_fw.h | 1 + .../vcodec/vdec/vdec_h264_req_common.c | 310 +++ .../vcodec/vdec/vdec_h264_req_common.h | 272 +++ .../mediatek/vcodec/vdec/vdec_h264_req_if.c | 438 +--- .../vcodec/vdec/vdec_h264_req_multi_if.c | 619 +++++ .../mediatek/vcodec/vdec/vdec_vp8_req_if.c | 437 ++++ .../vcodec/vdec/vdec_vp9_req_lat_if.c | 2072 +++++++++++++++++ .../platform/mediatek/vcodec/vdec_drv_if.c | 37 +- .../platform/mediatek/vcodec/vdec_drv_if.h | 3 + .../platform/mediatek/vcodec/vdec_ipi_msg.h | 36 + .../platform/mediatek/vcodec/vdec_msg_queue.c | 2 + .../platform/mediatek/vcodec/vdec_msg_queue.h | 2 + .../platform/mediatek/vcodec/vdec_vpu_if.c | 53 +- .../platform/mediatek/vcodec/vdec_vpu_if.h | 15 + .../platform/mediatek/vcodec/venc_vpu_if.c | 2 +- include/linux/remoteproc/mtk_scp.h | 2 + 26 files changed, 4274 insertions(+), 601 deletions(-) create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_commo n.c create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_commo n.h create mode 100644
drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.
c
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c create mode 100644
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
AngeloGioacchino Del Regno
maintainerIl 13/04/22 09:03, allen-kh.cheng ha scritto:
Quoted 85 lines
Hi Nicolas,
Quoted 31 lines · Nicolas Dufresne
Le lundi 11 avril 2022 à 11:41 +0800, [email protected] a écrit :
Quoted 29 lines
Hi Nicolas,
Quoted 26 lines · Nicolas Dufresne
Hi Yunfei,
thanks for the update, I should be testing this really soon.
Quoted 5 lines · Yunfei Dong
This series adds support for mt8192 h264/vp8/vp9 decoder drivers.
Firstly, refactor
power/clock/interrupt interfaces for mt8192 is lat and core architecture.Similarly to MT8173 and MT8183, a shared* firmware is needed for this
CODEC to
work (scp.img). I looked into linux-firmware[1] it has not been added
for mt8192
yet. As your patches are getting close to be ready, it would be important to
look into this so the patchset does not get blocked due to that.best regards,
Nicolas[1]
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
* Shared at least between MDP3 and MTK VCODEC from my knowledge
Thanks for your remind.
I have already sent mt8192 scp.img to github.
Quoted 20 lines
Quoted 3 lines
Waiting for to be merged.
On boards I have, the firmware is loaded from
/lib/firmware/scp.img, but with
this submission it will be inlib/firmware/mediatek/mt8192/scp.img. I haven't
found anything around:drivers/remoteproc/mtk_scp.c:812: char *fw_name = "scp.img";That would use the platform path. This seems like a problem to me, the
upstreaming of the firmware isn't being aligned with the were the firmware is
picked by the upstream driver. Correct me if I got this wrong, but I'd really
like to clarify this.Quoted 2 lines
Nicolas
I am not sure why it's accepted the fw path of scp is
/lib/firmware/scp.imgin mt8173/8183 but we upload scp.ing in /lib/firmware/mediatek/mt8173(mt8183)/scp.img tohttps://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/mediatek
Currently, the scp driver will load firmware in
/lib/firmware/scp.img. that means there is only one firmware for a specific platform. I think we can send a PATCH to make firmware name of scp being more flexible.Maybe get firmware name from dts. e.g.,
&scp { status = "okay"; firmware-name = "mediatek/mt81xx/scp.img"; };
Quoted 6 lines
Do you think it feasible?
If you have any concerns, please let us know.Thanks,
Allen
Hello Allen,
what you proposed is exactly what has been done for other platforms because of both per-device firmware differences (different signatures) and per-SoC (different firmware entirely), found on TI K3, iMX DSP, Qualcomm MSS/DSP remoteproc and others.
Of course this is an accepted way to resolve this situation: please go on!
Cheers,
Angelo
Le mercredi 13 avril 2022 à 09:57 +0200, AngeloGioacchino Del Regno a écrit :
Quoted 93 lines
Il 13/04/22 09:03, allen-kh.cheng ha scritto:
Quoted 85 lines
Hi Nicolas,
Quoted 31 lines · Nicolas Dufresne
Le lundi 11 avril 2022 à 11:41 +0800, [email protected] a écrit :
Quoted 29 lines
Hi Nicolas,
Quoted 26 lines · Nicolas Dufresne
Hi Yunfei,
thanks for the update, I should be testing this really soon.
Quoted 5 lines · Yunfei Dong
This series adds support for mt8192 h264/vp8/vp9 decoder drivers.
Firstly, refactor
power/clock/interrupt interfaces for mt8192 is lat and core architecture.Similarly to MT8173 and MT8183, a shared* firmware is needed for this
CODEC to
work (scp.img). I looked into linux-firmware[1] it has not been added
for mt8192
yet. As your patches are getting close to be ready, it would be important to
look into this so the patchset does not get blocked due to that.best regards,
Nicolas[1]
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
* Shared at least between MDP3 and MTK VCODEC from my knowledge
Thanks for your remind.
I have already sent mt8192 scp.img to github.
Quoted 20 lines
Quoted 3 lines
Waiting for to be merged.
On boards I have, the firmware is loaded from
/lib/firmware/scp.img, but with
this submission it will be inlib/firmware/mediatek/mt8192/scp.img. I haven't
found anything around:drivers/remoteproc/mtk_scp.c:812: char *fw_name = "scp.img";That would use the platform path. This seems like a problem to me, the
upstreaming of the firmware isn't being aligned with the were the firmware is
picked by the upstream driver. Correct me if I got this wrong, but I'd really
like to clarify this.Quoted 2 lines
Nicolas
I am not sure why it's accepted the fw path of scp is
/lib/firmware/scp.imgin mt8173/8183 but we upload scp.ing in /lib/firmware/mediatek/mt8173(mt8183)/scp.img tohttps://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/mediatek
Currently, the scp driver will load firmware in
/lib/firmware/scp.img. that means there is only one firmware for a specific platform. I think we can send a PATCH to make firmware name of scp being more flexible.Maybe get firmware name from dts. e.g.,
&scp { status = "okay"; firmware-name = "mediatek/mt81xx/scp.img"; };Quoted 6 lines
Do you think it feasible?
If you have any concerns, please let us know.Thanks,
Allen
Quoted 8 lines
Hello Allen,
what you proposed is exactly what has been done for other platforms because of both per-device firmware differences (different signatures) and per-SoC (different firmware entirely), found on TI K3, iMX DSP, Qualcomm MSS/DSP remoteproc and others.
Of course this is an accepted way to resolve this situation: please go on!
Looks good to me! (don't forget to keep a fallback to /lib/firmware/scp.img to maintain backward compatibility).
Quoted 4 lines
Cheers,
Angelo
Hi,
Quoted 46 lines · Nicolas Dufresne
Le mercredi 13 avril 2022 à 09:57 +0200, AngeloGioacchino Del Regno a écrit :
Quoted 44 lines
Il 13/04/22 09:03, allen-kh.cheng ha scritto:
Quoted 43 lines
Hi Nicolas,
Quoted 38 lines · Nicolas Dufresne
Le lundi 11 avril 2022 à 11:41 +0800, [email protected] a
écrit :Quoted 35 lines
Hi Nicolas,
Quoted 32 lines · Nicolas Dufresne
Hi Yunfei,
thanks for the update, I should be testing this really soon.
Quoted 6 lines · Yunfei Dong
This series adds support for mt8192 h264/vp8/vp9 decoder drivers.
Firstly, refactor
power/clock/interrupt interfaces for mt8192 is lat and core
architecture.Similarly to MT8173 and MT8183, a shared* firmware is needed for
this
CODEC to
work (scp.img). I looked into linux-firmware[1] it has not been
added
for mt8192
yet. As your patches are getting close to be ready, it would be
important to
look into this so the patchset does not get blocked due to that.best regards,
Nicolas[1]
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
* Shared at least between MDP3 and MTK VCODEC from my knowledge
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Thanks for your remind.
I have already sent mt8192 scp.img to github.
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 3 lines
Waiting for to be merged.
On boards I have, the firmware is loaded from
/lib/firmware/scp.img,
but with
this submission it will be inlib/firmware/mediatek/mt8192/scp.img.
I haven't
found anything around:
drivers/remoteproc/mtk_scp.c:812: char*fw_name=
"scp.img";That would use the platform path. This seems like a problem to me,
the
upstreaming of the firmware isn't being aligned with the were the
firmware is
picked by the upstream driver. Correct me if I got this wrong, but
I'd really
like to clarify this.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Nicolas
I am not sure why it's accepted the fw path of scp is
/lib/firmware/scp.imgin mt8173/8183 but we upload scp.ing in /lib/firmware/mediatek/mt8173(mt8183)/scp.img to
Quoted 32 lines
Quoted 32 lines
Quoted 15 lines
Currently, the scp driver will load firmware in
/lib/firmware/scp.img.
that means there is only one firmware for a specific platform. I think we can send a PATCH to make firmware name of scp being more
flexible.Maybe get firmware name from dts. e.g.,
&scp { status = "okay"; firmware-name = "mediatek/mt81xx/scp.img"; };Quoted 6 lines
Do you think it feasible?
If you have any concerns, please let us know.Thanks,
AllenHello Allen,
what you proposed is exactly what has been done for other platforms because of
both per-device firmware differences (different signatures) and per-SoC (different
firmware entirely), found on TI K3, iMX DSP, Qualcomm MSS/DSP remoteproc and
others.
Quoted 7 lines
Quoted 2 lines
Of course this is an accepted way to resolve this situation: please go on!
Looks good to me! (don't forget to keep a fallback to
/lib/firmware/scp.imgto
maintain backward compatibility).
No problem. I have sent an upstream PATCH for scp firmware path.
patchwork.kernel.org/project/linux-mediatek/list/?series=632268
thanks for your comments,
Allen
Quoted 6 lines
Quoted 4 lines
Cheers,
Angelo
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek