media: mtk-vcodec: support for M8192 decoder
Yunfei Dong
maintainerv11 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 v10:
- fix sparse and smatch check fail for patch 13/14/16
- fix 32bit build fail for patch 14
changes compared with v9:
- fix kernel robot build fail for patch 16
changes compared with v8:
- fix vp9 build error
- fix kernel-doc fail
changes compared with v7:
- 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/Kconfig | 1 + .../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 | 274 +++ .../mediatek/vcodec/vdec/vdec_h264_req_if.c | 438 +--- .../vcodec/vdec/vdec_h264_req_multi_if.c | 629 +++++ .../mediatek/vcodec/vdec/vdec_vp8_req_if.c | 437 ++++ .../vcodec/vdec/vdec_vp9_req_lat_if.c | 2031 +++++++++++++++++ .../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 + 27 files changed, 4246 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 v11 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 v11 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 v11 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 v11 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 v11 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 v11 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.
--- .../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 || ret) { +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 v11 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 v11 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 v11 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 v11 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 v11 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 v11 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 v11 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 | 274 +++++++++++ .../mediatek/vcodec/vdec/vdec_h264_req_if.c | 427 ++---------------- 4 files changed, 629 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 +274 -0
274 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
Re: [PATCH v11, 13/17] media: mediatek: vcodec: Extract H264 common code
Hi Yunfei,
Quoted 42 lines · Yunfei Dong
Mt8192 can use some of common code with mt8183. Moves them to a new file in order to reuse.
Signed-off-by Yunfei Dong <[email protected]>Reviewed-by Nicolas Dufresne <[email protected]>--- .../media/platform/mediatek/vcodec/Makefile | 1 + .../vcodec/vdec/vdec_h264_req_common.c | 310 +++++++++++++ .../vcodec/vdec/vdec_h264_req_common.h | 274 +++++++++++ .../mediatek/vcodec/vdec/vdec_h264_req_if.c | 427 ++---------------- 4 files changed, 629 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.hdrivers/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 +10
-0@@ -0,0 +1,310 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2022 MediaTek Inc. +* Author: Yunfei Dong <[email protected]> +*/ + +#include "vdec_h264_req_common.h" + +/* get used parameters for sps/pps */ +#define GET_MTK_VDEC_FLAG (cond, flag) \
drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c line 20
Quoted 10 lines
drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c new file +10
-0+ { dst_param->cond = ((src_param->flags & flag) ? (1 ) : (0 )); } +#define GET_MTK_VDEC_PARAM (param) \ + { dst_param->param = src_param->param; } + +/* +* The firmware expects unused reflist entries to have the value 0x20. +*/ +void mtk_vdec_h264_fixup_ref_list (u8 *ref_list,size_t num_valid) +{ +memset_io ((void __iomem *)&ref_list[num_valid],0x20 ,32 - num_valid);
No, don't cast! That defeats the whole purpose of __iomem.
Here the ref_list pointer itself should be an __iomem pointer, and that should be done for all the functions that receive pointers to io memory.
Typically at the top level you have pointers to memory mapped hardware devices, and such pointers are marked with __iomem. So whenever you pass such pointers on to other functions those must all be marked with __iomem so the compiler can verify that the right functions are called for memory like that. By casting you just paper over the real problem.
One other reason might be that this isn't actually io memory at all but just regular memory. In that case it shouldn't be __iomem at all. I can't tell if that's the case or not.
In rare cases you have no choice to make a cast, but then a comments needs to explain why you need to do that.
Regards,
Hans
Quoted 1,076 lines
drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c new file +290
-0+} + +void *mtk_vdec_h264_get_ctrl_ptr (struct mtk_vcodec_ctx *ctx,int id) +{ +struct v4l2_ctrl *ctrl =v4l2_ctrl_find (&ctx->ctrl_hdl, id); + +if (!ctrl) +return ERR_PTR (-EINVAL ); + +return ctrl->p_cur.p; +} + +void mtk_vdec_h264_fill_dpb_info (struct mtk_vcodec_ctx *ctx, +struct slice_api_h264_decode_param *decode_params, +struct mtk_h264_dpb_info *h264_dpb_info) +{ +const struct slice_h264_dpb_entry *dpb; +struct vb2_queue *vq; +struct vb2_buffer *vb; +struct vb2_v4l2_buffer *vb2_v4l2; +int index, vb2_index; + + vq =v4l2_m2m_get_vq (ctx->m2m_ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ); + +for (index =0 ; index <V4L2_H264_NUM_DPB_ENTRIES ; index++) { + dpb = &decode_params->dpb[index]; +if (!(dpb->flags &V4L2_H264_DPB_ENTRY_FLAG_ACTIVE )) { + h264_dpb_info[index].reference_flag =0 ; +continue ; + } + + vb2_index =vb2_find_timestamp (vq, dpb->reference_ts,0 ); +if (vb2_index <0 ) { +dev_err (&ctx->dev->plat_dev->dev, +"Reference invalid: dpb_index(%d) reference_ts(%lld)" , + index, dpb->reference_ts); +continue ; + } + +/* 1 for short term reference, 2 for long term reference */ +if (!(dpb->flags &V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM )) + h264_dpb_info[index].reference_flag =1 ; +else + h264_dpb_info[index].reference_flag =2 ; + + vb = vq->bufs[vb2_index]; + vb2_v4l2 = container_of(vb, struct vb2_v4l2_buffer, vb2_buf); + h264_dpb_info[index].field = vb2_v4l2->field; + + h264_dpb_info[index].y_dma_addr = +vb2_dma_contig_plane_dma_addr (vb,0 ); +if (ctx->q_data[MTK_Q_DATA_DST ].fmt->num_planes ==2 ) + h264_dpb_info[index].c_dma_addr = +vb2_dma_contig_plane_dma_addr (vb,1 ); +else + h264_dpb_info[index].c_dma_addr = + h264_dpb_info[index].y_dma_addr + + ctx->picinfo.fb_sz[0 ]; + } +} + +void mtk_vdec_h264_copy_sps_params (struct mtk_h264_sps_param *dst_param, +const struct v4l2_ctrl_h264_sps *src_param) +{ +GET_MTK_VDEC_PARAM (chroma_format_idc); +GET_MTK_VDEC_PARAM (bit_depth_luma_minus8); +GET_MTK_VDEC_PARAM (bit_depth_chroma_minus8); +GET_MTK_VDEC_PARAM (log2_max_frame_num_minus4); +GET_MTK_VDEC_PARAM (pic_order_cnt_type); +GET_MTK_VDEC_PARAM (log2_max_pic_order_cnt_lsb_minus4); +GET_MTK_VDEC_PARAM (max_num_ref_frames); +GET_MTK_VDEC_PARAM (pic_width_in_mbs_minus1); +GET_MTK_VDEC_PARAM (pic_height_in_map_units_minus1); + +GET_MTK_VDEC_FLAG (separate_colour_plane_flag, +V4L2_H264_SPS_FLAG_SEPARATE_COLOUR_PLANE ); +GET_MTK_VDEC_FLAG (qpprime_y_zero_transform_bypass_flag, +V4L2_H264_SPS_FLAG_QPPRIME_Y_ZERO_TRANSFORM_BYPASS ); +GET_MTK_VDEC_FLAG (delta_pic_order_always_zero_flag, +V4L2_H264_SPS_FLAG_DELTA_PIC_ORDER_ALWAYS_ZERO ); +GET_MTK_VDEC_FLAG (frame_mbs_only_flag, +V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY ); +GET_MTK_VDEC_FLAG (mb_adaptive_frame_field_flag, +V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD ); +GET_MTK_VDEC_FLAG (direct_8x8_inference_flag, +V4L2_H264_SPS_FLAG_DIRECT_8X8_INFERENCE ); +} + +void mtk_vdec_h264_copy_pps_params (struct mtk_h264_pps_param *dst_param, +const struct v4l2_ctrl_h264_pps *src_param) +{ +GET_MTK_VDEC_PARAM (num_ref_idx_l0_default_active_minus1); +GET_MTK_VDEC_PARAM (num_ref_idx_l1_default_active_minus1); +GET_MTK_VDEC_PARAM (weighted_bipred_idc); +GET_MTK_VDEC_PARAM (pic_init_qp_minus26); +GET_MTK_VDEC_PARAM (chroma_qp_index_offset); +GET_MTK_VDEC_PARAM (second_chroma_qp_index_offset); + +GET_MTK_VDEC_FLAG (entropy_coding_mode_flag, +V4L2_H264_PPS_FLAG_ENTROPY_CODING_MODE ); +GET_MTK_VDEC_FLAG (pic_order_present_flag, +V4L2_H264_PPS_FLAG_BOTTOM_FIELD_PIC_ORDER_IN_FRAME_PRESENT ); +GET_MTK_VDEC_FLAG (weighted_pred_flag, +V4L2_H264_PPS_FLAG_WEIGHTED_PRED ); +GET_MTK_VDEC_FLAG (deblocking_filter_control_present_flag, +V4L2_H264_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT ); +GET_MTK_VDEC_FLAG (constrained_intra_pred_flag, +V4L2_H264_PPS_FLAG_CONSTRAINED_INTRA_PRED ); +GET_MTK_VDEC_FLAG (redundant_pic_cnt_present_flag, +V4L2_H264_PPS_FLAG_REDUNDANT_PIC_CNT_PRESENT ); +GET_MTK_VDEC_FLAG (transform_8x8_mode_flag, +V4L2_H264_PPS_FLAG_TRANSFORM_8X8_MODE ); +GET_MTK_VDEC_FLAG (scaling_matrix_present_flag, +V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT ); +} + +void mtk_vdec_h264_copy_slice_hd_params (struct mtk_h264_slice_hd_param *dst_param, +const struct v4l2_ctrl_h264_slice_params *src_param, +const struct v4l2_ctrl_h264_decode_params *dec_param) +{ +int temp; + +GET_MTK_VDEC_PARAM (first_mb_in_slice); +GET_MTK_VDEC_PARAM (slice_type); +GET_MTK_VDEC_PARAM (cabac_init_idc); +GET_MTK_VDEC_PARAM (slice_qp_delta); +GET_MTK_VDEC_PARAM (disable_deblocking_filter_idc); +GET_MTK_VDEC_PARAM (slice_alpha_c0_offset_div2); +GET_MTK_VDEC_PARAM (slice_beta_offset_div2); +GET_MTK_VDEC_PARAM (num_ref_idx_l0_active_minus1); +GET_MTK_VDEC_PARAM (num_ref_idx_l1_active_minus1); + + dst_param->frame_num = dec_param->frame_num; + dst_param->pic_order_cnt_lsb = dec_param->pic_order_cnt_lsb; + + dst_param->delta_pic_order_cnt_bottom = + dec_param->delta_pic_order_cnt_bottom; + dst_param->delta_pic_order_cnt0 = + dec_param->delta_pic_order_cnt0; + dst_param->delta_pic_order_cnt1 = + dec_param->delta_pic_order_cnt1; + + temp = dec_param->flags &V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC ; + dst_param->field_pic_flag = temp ?1 :0 ; + + temp = dec_param->flags &V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD ; + dst_param->bottom_field_flag = temp ?1 :0 ; + +GET_MTK_VDEC_FLAG (direct_spatial_mv_pred_flag, +V4L2_H264_SLICE_FLAG_DIRECT_SPATIAL_MV_PRED ); +} + +void mtk_vdec_h264_copy_scaling_matrix (struct slice_api_h264_scaling_matrix *dst_matrix, +const struct v4l2_ctrl_h264_scaling_matrix *src_matrix) +{ +memcpy_toio ((void __iomem *)dst_matrix->scaling_list_4x4, src_matrix->scaling_list_4x4, +sizeof (dst_matrix->scaling_list_4x4)); + +memcpy_toio ((void __iomem *)dst_matrix->scaling_list_8x8, src_matrix->scaling_list_8x8, +sizeof (dst_matrix->scaling_list_8x8)); +} + +void +mtk_vdec_h264_copy_decode_params (struct slice_api_h264_decode_param *dst_params, +const struct v4l2_ctrl_h264_decode_params *src_params, +const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES ]) +{ +struct slice_h264_dpb_entry *dst_entry; +const struct v4l2_h264_dpb_entry *src_entry; +int i; + +for (i =0 ; i <ARRAY_SIZE (dst_params->dpb); i++) { + dst_entry = &dst_params->dpb[i]; + src_entry = &dpb[i]; + + dst_entry->reference_ts = src_entry->reference_ts; + dst_entry->frame_num = src_entry->frame_num; + dst_entry->pic_num = src_entry->pic_num; + dst_entry->top_field_order_cnt = src_entry->top_field_order_cnt; + dst_entry->bottom_field_order_cnt = + src_entry->bottom_field_order_cnt; + dst_entry->flags = src_entry->flags; + } + +/* num_slices is a leftover from the old H.264 support and is ignored +* by the firmware. +*/ + dst_params->num_slices =0 ; + dst_params->nal_ref_idc = src_params->nal_ref_idc; + dst_params->top_field_order_cnt = src_params->top_field_order_cnt; + dst_params->bottom_field_order_cnt = src_params->bottom_field_order_cnt; + dst_params->flags = src_params->flags; +} + +static bool mtk_vdec_h264_dpb_entry_match (const struct v4l2_h264_dpb_entry *a, +const struct v4l2_h264_dpb_entry *b) +{ +return a->top_field_order_cnt == b->top_field_order_cnt && + a->bottom_field_order_cnt == b->bottom_field_order_cnt; +} + +/* +* Move DPB entries of dec_param that refer to a frame already existing in dpb +* into the already existing slot in dpb, and move other entries into new slots. +* +* This function is an adaptation of the similarly-named function in +* hantro_h264.c. +*/ +void mtk_vdec_h264_update_dpb (const struct v4l2_ctrl_h264_decode_params *dec_param, +struct v4l2_h264_dpb_entry *dpb) +{ + DECLARE_BITMAP(new, ARRAY_SIZE(dec_param->dpb)) = { 0, }; + DECLARE_BITMAP(in_use, ARRAY_SIZE(dec_param->dpb)) = { 0, }; + DECLARE_BITMAP(used, ARRAY_SIZE(dec_param->dpb)) = { 0, }; +unsigned int i, j; + +/* Disable all entries by default, and mark the ones in use. */ +for (i =0 ; i <ARRAY_SIZE (dec_param->dpb); i++) { +if (dpb[i].flags &V4L2_H264_DPB_ENTRY_FLAG_ACTIVE ) +set_bit (i, in_use); + dpb[i].flags &= ~V4L2_H264_DPB_ENTRY_FLAG_ACTIVE ; + } + +/* Try to match new DPB entries with existing ones by their POCs. */ +for (i =0 ; i <ARRAY_SIZE (dec_param->dpb); i++) { +const struct v4l2_h264_dpb_entry *ndpb = &dec_param->dpb[i]; + +if (!(ndpb->flags &V4L2_H264_DPB_ENTRY_FLAG_ACTIVE )) +continue ; + +/* +* To cut off some comparisons, iterate only on target DPB +* entries were already used. +*/ +for_each_set_bit (j, in_use,ARRAY_SIZE (dec_param->dpb)) { +struct v4l2_h264_dpb_entry *cdpb; + + cdpb = &dpb[j]; +if (!mtk_vdec_h264_dpb_entry_match (cdpb, ndpb)) +continue ; + + *cdpb = *ndpb; +set_bit (j, used); +/* Don't reiterate on this one. */ +clear_bit (j, in_use); +break ; + } + +if (j ==ARRAY_SIZE (dec_param->dpb)) +set_bit (i, new); + } + +/* For entries that could not be matched, use remaining free slots. */ +for_each_set_bit (i, new,ARRAY_SIZE (dec_param->dpb)) { +const struct v4l2_h264_dpb_entry *ndpb = &dec_param->dpb[i]; +struct v4l2_h264_dpb_entry *cdpb; + +/* +* Both arrays are of the same sizes, so there is no way +* we can end up with no space in target array, unless +* something is buggy. +*/ + j =find_first_zero_bit (used,ARRAY_SIZE (dec_param->dpb)); +if (WARN_ON (j >=ARRAY_SIZE (dec_param->dpb))) +return ; + + cdpb = &dpb[j]; + *cdpb = *ndpb; +set_bit (j, used); + } +} + +unsigned int mtk_vdec_h264_get_mv_buf_size (unsigned int width,unsigned int height) +{ +int unit_size = (width /MB_UNIT_LEN ) * (height /MB_UNIT_LEN ) +8 ; + +return HW_MB_STORE_SZ * unit_size; +} + +int mtk_vdec_h264_find_start_code (unsigned char *data,unsigned int data_sz) +{ +if (data_sz >3 && data[0 ] ==0 && data[1 ] ==0 && data[2 ] ==1 ) +return 3 ; + +if (data_sz >4 && data[0 ] ==0 && data[1 ] ==0 && data[2 ] ==0 && + data[3 ] ==1 ) +return 4 ; + +return -1 ; +}drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.h new file +274
-0@@ -0,0 +1,274 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2022 MediaTek Inc. +* Author: Yunfei Dong <[email protected]> +*/ + +#ifndef _VDEC_H264_REQ_COMMON_H_ +#define _VDEC_H264_REQ_COMMON_H_ + +#include <linux/module.h> +#include <linux/slab.h> +#include <media/v4l2-h264.h> +#include <media/v4l2-mem2mem.h> +#include <media/videobuf2-dma-contig.h> + +#include "../mtk_vcodec_drv.h" + +#define NAL_NON_IDR_SLICE 0x01 +#define NAL_IDR_SLICE 0x05 +#define NAL_TYPE (value) ((value) & 0x1F) + +#define BUF_PREDICTION_SZ (64 * 4096) +#define MB_UNIT_LEN 16 + +/* motion vector size (bytes) for every macro block */ +#define HW_MB_STORE_SZ 64 + +#define H264_MAX_MV_NUM 32 + +/** +* struct mtk_h264_dpb_info - h264 dpb information +* +* @y_dma_addr: Y bitstream physical address +* @c_dma_addr: CbCr bitstream physical address +* @reference_flag: reference picture flag (short/long term reference picture) +* @field: field picture flag +*/ +struct mtk_h264_dpb_info { +dma_addr_t y_dma_addr; +dma_addr_t c_dma_addr; +int reference_flag; +int field; +}; + +/* +* struct mtk_h264_sps_param - parameters for sps +*/ +struct mtk_h264_sps_param { +unsigned char chroma_format_idc; +unsigned char bit_depth_luma_minus8; +unsigned char bit_depth_chroma_minus8; +unsigned char log2_max_frame_num_minus4; +unsigned char pic_order_cnt_type; +unsigned char log2_max_pic_order_cnt_lsb_minus4; +unsigned char max_num_ref_frames; +unsigned char separate_colour_plane_flag; +unsigned short pic_width_in_mbs_minus1; +unsigned short pic_height_in_map_units_minus1; +unsigned int max_frame_nums; +unsigned char qpprime_y_zero_transform_bypass_flag; +unsigned char delta_pic_order_always_zero_flag; +unsigned char frame_mbs_only_flag; +unsigned char mb_adaptive_frame_field_flag; +unsigned char direct_8x8_inference_flag; +unsigned char reserved[3 ]; +}; + +/* +* struct mtk_h264_pps_param - parameters for pps +*/ +struct mtk_h264_pps_param { +unsigned char num_ref_idx_l0_default_active_minus1; +unsigned char num_ref_idx_l1_default_active_minus1; +unsigned char weighted_bipred_idc; +char pic_init_qp_minus26; +char chroma_qp_index_offset; +char second_chroma_qp_index_offset; +unsigned char entropy_coding_mode_flag; +unsigned char pic_order_present_flag; +unsigned char deblocking_filter_control_present_flag; +unsigned char constrained_intra_pred_flag; +unsigned char weighted_pred_flag; +unsigned char redundant_pic_cnt_present_flag; +unsigned char transform_8x8_mode_flag; +unsigned char scaling_matrix_present_flag; +unsigned char reserved[2 ]; +}; + +/* +* struct mtk_h264_slice_hd_param - parameters for slice header +*/ +struct mtk_h264_slice_hd_param { +unsigned int first_mb_in_slice; +unsigned int field_pic_flag; +unsigned int slice_type; +unsigned int frame_num; +int pic_order_cnt_lsb; +int delta_pic_order_cnt_bottom; +unsigned int bottom_field_flag; +unsigned int direct_spatial_mv_pred_flag; +int delta_pic_order_cnt0; +int delta_pic_order_cnt1; +unsigned int cabac_init_idc; +int slice_qp_delta; +unsigned int disable_deblocking_filter_idc; +int slice_alpha_c0_offset_div2; +int slice_beta_offset_div2; +unsigned int num_ref_idx_l0_active_minus1; +unsigned int num_ref_idx_l1_active_minus1; +unsigned int reserved; +}; + +/* +* struct slice_api_h264_scaling_matrix - parameters for scaling list +*/ +struct slice_api_h264_scaling_matrix { +unsigned char scaling_list_4x4[6 ][16 ]; +unsigned char scaling_list_8x8[6 ][64 ]; +}; + +/* +* struct slice_h264_dpb_entry - each dpb information +*/ +struct slice_h264_dpb_entry { +unsigned long long reference_ts; +unsigned short frame_num; +unsigned short pic_num; +/* Note that field is indicated by v4l2_buffer.field */ +int top_field_order_cnt; +int bottom_field_order_cnt; +unsigned int flags; +}; + +/* +* struct slice_api_h264_decode_param - parameters for decode. +*/ +struct slice_api_h264_decode_param { +struct slice_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES ]; +unsigned short num_slices; +unsigned short nal_ref_idc; +unsigned char ref_pic_list_p0[32 ]; +unsigned char ref_pic_list_b0[32 ]; +unsigned char ref_pic_list_b1[32 ]; +int top_field_order_cnt; +int bottom_field_order_cnt; +unsigned int flags; +}; + +/** +* struct h264_fb - h264 decode frame buffer information +* +* @vdec_fb_va: virtual address of struct vdec_fb +* @y_fb_dma: dma address of Y frame buffer (luma) +* @c_fb_dma: dma address of C frame buffer (chroma) +* @poc: picture order count of frame buffer +* @reserved: for 8 bytes alignment +*/ +struct h264_fb { +u64 vdec_fb_va; +u64 y_fb_dma; +u64 c_fb_dma; +s32 poc; +u32 reserved; +}; + +/** +* mtk_vdec_h264_fixup_ref_list - fixup unused reference to 0x20. +* +* @ref_list: reference picture list +* @num_valid: used reference number +*/ +void mtk_vdec_h264_fixup_ref_list (u8 *ref_list,size_t num_valid); + +/** +* mtk_vdec_h264_get_ctrl_ptr - get each CID contrl address. +* +* @ctx: v4l2 ctx +* @id: CID control ID +* +* Return: returns CID ctrl address. +*/ +void *mtk_vdec_h264_get_ctrl_ptr (struct mtk_vcodec_ctx *ctx,int id); + +/** +* mtk_vdec_h264_fill_dpb_info - get each CID contrl address. +* +* @ctx: v4l2 ctx +* @decode_params: slice decode params +* @h264_dpb_info: dpb buffer information +*/ +void mtk_vdec_h264_fill_dpb_info (struct mtk_vcodec_ctx *ctx, +struct slice_api_h264_decode_param *decode_params, +struct mtk_h264_dpb_info *h264_dpb_info); + +/** +* mtk_vdec_h264_copy_sps_params - get sps params. +* +* @dst_param: sps params for hw decoder +* @src_param: sps params from user driver +*/ +void mtk_vdec_h264_copy_sps_params (struct mtk_h264_sps_param *dst_param, +const struct v4l2_ctrl_h264_sps *src_param); + +/** +* mtk_vdec_h264_copy_pps_params - get pps params. +* +* @dst_param: pps params for hw decoder +* @src_param: pps params from user driver +*/ +void mtk_vdec_h264_copy_pps_params (struct mtk_h264_pps_param *dst_param, +const struct v4l2_ctrl_h264_pps *src_param); + +/** +* mtk_vdec_h264_copy_slice_hd_params - get slice header params. +* +* @dst_param: slice params for hw decoder +* @src_param: slice params from user driver +* @dec_param: decode params from user driver +*/ +void mtk_vdec_h264_copy_slice_hd_params (struct mtk_h264_slice_hd_param *dst_param, +const struct v4l2_ctrl_h264_slice_params *src_param, +const struct v4l2_ctrl_h264_decode_params *dec_param); + +/** +* mtk_vdec_h264_copy_scaling_matrix - get each CID contrl address. +* +* @dst_matrix: scaling list params for hw decoder +* @src_matrix: scaling list params from user driver +*/ +void mtk_vdec_h264_copy_scaling_matrix (struct slice_api_h264_scaling_matrix *dst_matrix, +const struct v4l2_ctrl_h264_scaling_matrix *src_matrix); + +/** +* mtk_vdec_h264_copy_decode_params - get decode params. +* +* @dst_params: dst params for hw decoder +* @src_params: decode params from user driver +* @dpb: dpb information +*/ +void +mtk_vdec_h264_copy_decode_params (struct slice_api_h264_decode_param *dst_params, +const struct v4l2_ctrl_h264_decode_params *src_params, +const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES ]); + +/** +* mtk_vdec_h264_update_dpb - updata dpb list. +* +* @dec_param: v4l2 control decode params +* @dpb: dpb entry informaton +*/ +void mtk_vdec_h264_update_dpb (const struct v4l2_ctrl_h264_decode_params *dec_param, +struct v4l2_h264_dpb_entry *dpb); + +/** +* mtk_vdec_h264_find_start_code - find h264 start code using sofeware. +* +* @data: input buffer address +* @data_sz: input buffer size +* +* Return: returns start code position. +*/ +int mtk_vdec_h264_find_start_code (unsigned char *data,unsigned int data_sz); + +/** +* mtk_vdec_h264_get_mv_buf_size - get mv buffer size. +* +* @width: picture width +* @height: picture height +* +* Return: returns mv buffer size. +*/ +unsigned int mtk_vdec_h264_get_mv_buf_size (unsigned int width,unsigned int height); + +#endif drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_if.c +44
-383@@ -12,109 +12,7 @@#include "../vdec_drv_base.h" #include "../vdec_drv_if.h" #include "../vdec_vpu_if.h" - -#define BUF_PREDICTION_SZ (64 * 4096) -#define MB_UNIT_LEN 16 - -/* get used parameters for sps/pps */ -#define GET_MTK_VDEC_FLAG (cond, flag) \ - { dst_param->cond = ((src_param->flags & (flag)) ? (1) : (0)); } -#define GET_MTK_VDEC_PARAM (param) \ - { dst_param->param = src_param->param; } -/* motion vector size (bytes) for every macro block */ -#define HW_MB_STORE_SZ 64 - -#define H264_MAX_FB_NUM 17 -#define H264_MAX_MV_NUM 32 -#define HDR_PARSING_BUF_SZ 1024 - -/** -* struct mtk_h264_dpb_info - h264 dpb information -* @y_dma_addr: Y bitstream physical address -* @c_dma_addr: CbCr bitstream physical address -* @reference_flag: reference picture flag (short/long term reference picture) -* @field: field picture flag -*/ -struct mtk_h264_dpb_info { -dma_addr_t y_dma_addr; -dma_addr_t c_dma_addr; -int reference_flag; -int field; -}; - -/* -* struct mtk_h264_sps_param - parameters for sps -*/ -struct mtk_h264_sps_param { -unsigned char chroma_format_idc; -unsigned char bit_depth_luma_minus8; -unsigned char bit_depth_chroma_minus8; -unsigned char log2_max_frame_num_minus4; -unsigned char pic_order_cnt_type; -unsigned char log2_max_pic_order_cnt_lsb_minus4; -unsigned char max_num_ref_frames; -unsigned char separate_colour_plane_flag; -unsigned short pic_width_in_mbs_minus1; -unsigned short pic_height_in_map_units_minus1; -unsigned int max_frame_nums; -unsigned char qpprime_y_zero_transform_bypass_flag; -unsigned char delta_pic_order_always_zero_flag; -unsigned char frame_mbs_only_flag; -unsigned char mb_adaptive_frame_field_flag; -unsigned char direct_8x8_inference_flag; -unsigned char reserved[3 ]; -}; - -/* -* struct mtk_h264_pps_param - parameters for pps -*/ -struct mtk_h264_pps_param { -unsigned char num_ref_idx_l0_default_active_minus1; -unsigned char num_ref_idx_l1_default_active_minus1; -unsigned char weighted_bipred_idc; -char pic_init_qp_minus26; -char chroma_qp_index_offset; -char second_chroma_qp_index_offset; -unsigned char entropy_coding_mode_flag; -unsigned char pic_order_present_flag; -unsigned char deblocking_filter_control_present_flag; -unsigned char constrained_intra_pred_flag; -unsigned char weighted_pred_flag; -unsigned char redundant_pic_cnt_present_flag; -unsigned char transform_8x8_mode_flag; -unsigned char scaling_matrix_present_flag; -unsigned char reserved[2 ]; -}; - -struct slice_api_h264_scaling_matrix { -unsigned char scaling_list_4x4[6 ][16 ]; -unsigned char scaling_list_8x8[6 ][64 ]; -}; - -struct slice_h264_dpb_entry { -unsigned long long reference_ts; -unsigned short frame_num; -unsigned short pic_num; -/* Note that field is indicated by v4l2_buffer.field */ -int top_field_order_cnt; -int bottom_field_order_cnt; -unsigned int flags;/* V4L2_H264_DPB_ENTRY_FLAG_* */ -}; - -/* -* struct slice_api_h264_decode_param - parameters for decode. -*/ -struct slice_api_h264_decode_param { -struct slice_h264_dpb_entry dpb[16 ]; -unsigned short num_slices; -unsigned short nal_ref_idc; -unsigned char ref_pic_list_p0[32 ]; -unsigned char ref_pic_list_b0[32 ]; -unsigned char ref_pic_list_b1[32 ]; -int top_field_order_cnt; -int bottom_field_order_cnt; -unsigned int flags;/* V4L2_H264_DECODE_PARAM_FLAG_* */ -}; +#include "vdec_h264_req_common.h" /* * struct mtk_h264_dec_slice_param - parameters for decode current frame @@ -127,22 +25,6 @@ struct mtk_h264_dec_slice_param {struct mtk_h264_dpb_info h264_dpb_info[16 ]; }; -/** -* struct h264_fb - h264 decode frame buffer information -* @vdec_fb_va : virtual address of struct vdec_fb -* @y_fb_dma : dma address of Y frame buffer (luma) -* @c_fb_dma : dma address of C frame buffer (chroma) -* @poc : picture order count of frame buffer -* @reserved : for 8 bytes alignment -*/ -struct h264_fb { -u64 vdec_fb_va; -u64 y_fb_dma; -u64 c_fb_dma; -s32 poc; -u32 reserved; -}; -/** * struct vdec_h264_dec_info - decode information * @dpb_sz : decoding picture buffer size @@ -212,265 +94,45 @@ struct vdec_h264_slice_inst {struct v4l2_h264_dpb_entry dpb[16 ]; }; -static void *get_ctrl_ptr (struct mtk_vcodec_ctx *ctx,int id) -{ -struct v4l2_ctrl *ctrl =v4l2_ctrl_find (&ctx->ctrl_hdl, id); - -return ctrl->p_cur.p; -} - -static void get_h264_dpb_list (struct vdec_h264_slice_inst *inst, -struct mtk_h264_dec_slice_param *slice_param) -{ -struct vb2_queue *vq; -struct vb2_buffer *vb; -struct vb2_v4l2_buffer *vb2_v4l2; -u64 index; - - vq =v4l2_m2m_get_vq (inst->ctx->m2m_ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ); - -for (index =0 ; index <ARRAY_SIZE (slice_param->decode_params.dpb); index++) { -const struct slice_h264_dpb_entry *dpb; -int vb2_index; - - dpb = &slice_param->decode_params.dpb[index]; -if (!(dpb->flags &V4L2_H264_DPB_ENTRY_FLAG_ACTIVE )) { - slice_param->h264_dpb_info[index].reference_flag =0 ; -continue ; - } - - vb2_index =vb2_find_timestamp (vq, dpb->reference_ts,0 ); -if (vb2_index <0 ) { -mtk_vcodec_err (inst,"Reference invalid: dpb_index(%lld) reference_ts(%lld)" , - index, dpb->reference_ts); -continue ; - } -/* 1 for short term reference, 2 for long term reference */ -if (!(dpb->flags &V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM )) - slice_param->h264_dpb_info[index].reference_flag =1 ; -else - slice_param->h264_dpb_info[index].reference_flag =2 ; - - vb = vq->bufs[vb2_index]; - vb2_v4l2 = container_of(vb, struct vb2_v4l2_buffer, vb2_buf); - slice_param->h264_dpb_info[index].field = vb2_v4l2->field; - - slice_param->h264_dpb_info[index].y_dma_addr = -vb2_dma_contig_plane_dma_addr (vb,0 ); -if (inst->ctx->q_data[MTK_Q_DATA_DST ].fmt->num_planes ==2 ) { - slice_param->h264_dpb_info[index].c_dma_addr = -vb2_dma_contig_plane_dma_addr (vb,1 ); - } - } -} - -static void get_h264_sps_parameters (struct mtk_h264_sps_param *dst_param, -const struct v4l2_ctrl_h264_sps *src_param) -{ -GET_MTK_VDEC_PARAM (chroma_format_idc); -GET_MTK_VDEC_PARAM (bit_depth_luma_minus8); -GET_MTK_VDEC_PARAM (bit_depth_chroma_minus8); -GET_MTK_VDEC_PARAM (log2_max_frame_num_minus4); -GET_MTK_VDEC_PARAM (pic_order_cnt_type); -GET_MTK_VDEC_PARAM (log2_max_pic_order_cnt_lsb_minus4); -GET_MTK_VDEC_PARAM (max_num_ref_frames); -GET_MTK_VDEC_PARAM (pic_width_in_mbs_minus1); -GET_MTK_VDEC_PARAM (pic_height_in_map_units_minus1); - -GET_MTK_VDEC_FLAG (separate_colour_plane_flag, -V4L2_H264_SPS_FLAG_SEPARATE_COLOUR_PLANE ); -GET_MTK_VDEC_FLAG (qpprime_y_zero_transform_bypass_flag, -V4L2_H264_SPS_FLAG_QPPRIME_Y_ZERO_TRANSFORM_BYPASS ); -GET_MTK_VDEC_FLAG (delta_pic_order_always_zero_flag, -V4L2_H264_SPS_FLAG_DELTA_PIC_ORDER_ALWAYS_ZERO ); -GET_MTK_VDEC_FLAG (frame_mbs_only_flag, -V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY ); -GET_MTK_VDEC_FLAG (mb_adaptive_frame_field_flag, -V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD ); -GET_MTK_VDEC_FLAG (direct_8x8_inference_flag, -V4L2_H264_SPS_FLAG_DIRECT_8X8_INFERENCE ); -} - -static void get_h264_pps_parameters (struct mtk_h264_pps_param *dst_param, -const struct v4l2_ctrl_h264_pps *src_param) +static int get_vdec_decode_parameters (struct vdec_h264_slice_inst *inst) { -GET_MTK_VDEC_PARAM (num_ref_idx_l0_default_active_minus1); -GET_MTK_VDEC_PARAM (num_ref_idx_l1_default_active_minus1); -GET_MTK_VDEC_PARAM (weighted_bipred_idc); -GET_MTK_VDEC_PARAM (pic_init_qp_minus26); -GET_MTK_VDEC_PARAM (chroma_qp_index_offset); -GET_MTK_VDEC_PARAM (second_chroma_qp_index_offset); - -GET_MTK_VDEC_FLAG (entropy_coding_mode_flag, -V4L2_H264_PPS_FLAG_ENTROPY_CODING_MODE ); -GET_MTK_VDEC_FLAG (pic_order_present_flag, -V4L2_H264_PPS_FLAG_BOTTOM_FIELD_PIC_ORDER_IN_FRAME_PRESENT ); -GET_MTK_VDEC_FLAG (weighted_pred_flag, -V4L2_H264_PPS_FLAG_WEIGHTED_PRED ); -GET_MTK_VDEC_FLAG (deblocking_filter_control_present_flag, -V4L2_H264_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT ); -GET_MTK_VDEC_FLAG (constrained_intra_pred_flag, -V4L2_H264_PPS_FLAG_CONSTRAINED_INTRA_PRED ); -GET_MTK_VDEC_FLAG (redundant_pic_cnt_present_flag, -V4L2_H264_PPS_FLAG_REDUNDANT_PIC_CNT_PRESENT ); -GET_MTK_VDEC_FLAG (transform_8x8_mode_flag, -V4L2_H264_PPS_FLAG_TRANSFORM_8X8_MODE ); -GET_MTK_VDEC_FLAG (scaling_matrix_present_flag, -V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT ); -} - -static void -get_h264_scaling_matrix (struct slice_api_h264_scaling_matrix *dst_matrix, -const struct v4l2_ctrl_h264_scaling_matrix *src_matrix) -{ -memcpy (dst_matrix->scaling_list_4x4, src_matrix->scaling_list_4x4, -sizeof (dst_matrix->scaling_list_4x4)); - -memcpy (dst_matrix->scaling_list_8x8, src_matrix->scaling_list_8x8, -sizeof (dst_matrix->scaling_list_8x8)); -} - -static void -get_h264_decode_parameters (struct slice_api_h264_decode_param *dst_params, -const struct v4l2_ctrl_h264_decode_params *src_params, -const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES ]) -{ -int i; - -for (i =0 ; i <ARRAY_SIZE (dst_params->dpb); i++) { -struct slice_h264_dpb_entry *dst_entry = &dst_params->dpb[i]; -const struct v4l2_h264_dpb_entry *src_entry = &dpb[i]; - - dst_entry->reference_ts = src_entry->reference_ts; - dst_entry->frame_num = src_entry->frame_num; - dst_entry->pic_num = src_entry->pic_num; - dst_entry->top_field_order_cnt = src_entry->top_field_order_cnt; - dst_entry->bottom_field_order_cnt = - src_entry->bottom_field_order_cnt; - dst_entry->flags = src_entry->flags; - } - -/* -* num_slices is a leftover from the old H.264 support and is ignored -* by the firmware. -*/ - dst_params->num_slices =0 ; - dst_params->nal_ref_idc = src_params->nal_ref_idc; - dst_params->top_field_order_cnt = src_params->top_field_order_cnt; - dst_params->bottom_field_order_cnt = src_params->bottom_field_order_cnt; - dst_params->flags = src_params->flags; -} - -static bool dpb_entry_match (const struct v4l2_h264_dpb_entry *a, -const struct v4l2_h264_dpb_entry *b) -{ -return a->top_field_order_cnt == b->top_field_order_cnt && - a->bottom_field_order_cnt == b->bottom_field_order_cnt; -} - -/* -* Move DPB entries of dec_param that refer to a frame already existing in dpb -* into the already existing slot in dpb, and move other entries into new slots. -* -* This function is an adaptation of the similarly-named function in -* hantro_h264.c. -*/ -static void update_dpb (const struct v4l2_ctrl_h264_decode_params *dec_param, -struct v4l2_h264_dpb_entry *dpb) -{ - DECLARE_BITMAP(new, ARRAY_SIZE(dec_param->dpb)) = { 0, }; - DECLARE_BITMAP(in_use, ARRAY_SIZE(dec_param->dpb)) = { 0, }; - DECLARE_BITMAP(used, ARRAY_SIZE(dec_param->dpb)) = { 0, }; -unsigned int i, j; - -/* Disable all entries by default, and mark the ones in use. */ -for (i =0 ; i <ARRAY_SIZE (dec_param->dpb); i++) { -if (dpb[i].flags &V4L2_H264_DPB_ENTRY_FLAG_ACTIVE ) -set_bit (i, in_use); - dpb[i].flags &= ~V4L2_H264_DPB_ENTRY_FLAG_ACTIVE ; - } - -/* Try to match new DPB entries with existing ones by their POCs. */ -for (i =0 ; i <ARRAY_SIZE (dec_param->dpb); i++) { -const struct v4l2_h264_dpb_entry *ndpb = &dec_param->dpb[i]; - -if (!(ndpb->flags &V4L2_H264_DPB_ENTRY_FLAG_ACTIVE )) -continue ; - -/* -* To cut off some comparisons, iterate only on target DPB -* entries were already used. -*/ -for_each_set_bit (j, in_use,ARRAY_SIZE (dec_param->dpb)) { -struct v4l2_h264_dpb_entry *cdpb; - - cdpb = &dpb[j]; -if (!dpb_entry_match (cdpb, ndpb)) -continue ; - - *cdpb = *ndpb; -set_bit (j, used); -/* Don't reiterate on this one. */ -clear_bit (j, in_use); -break ; - } - -if (j ==ARRAY_SIZE (dec_param->dpb)) -set_bit (i, new); - } - -/* For entries that could not be matched, use remaining free slots. */ -for_each_set_bit (i, new,ARRAY_SIZE (dec_param->dpb)) { -const struct v4l2_h264_dpb_entry *ndpb = &dec_param->dpb[i]; -struct v4l2_h264_dpb_entry *cdpb; - -/* -* Both arrays are of the same sizes, so there is no way -* we can end up with no space in target array, unless -* something is buggy. -*/ - j =find_first_zero_bit (used,ARRAY_SIZE (dec_param->dpb)); -if (WARN_ON (j >=ARRAY_SIZE (dec_param->dpb))) -return ; - - cdpb = &dpb[j]; - *cdpb = *ndpb; -set_bit (j, used); - } -} - -/* -* The firmware expects unused reflist entries to have the value 0x20. -*/ -static void fixup_ref_list (u8 *ref_list,size_t num_valid) -{ -memset (&ref_list[num_valid],0x20 ,32 - num_valid); -} - -static void get_vdec_decode_parameters (struct vdec_h264_slice_inst *inst) -{ -const struct v4l2_ctrl_h264_decode_params *dec_params = -get_ctrl_ptr (inst->ctx,V4L2_CID_STATELESS_H264_DECODE_PARAMS ); -const struct v4l2_ctrl_h264_sps *sps = -get_ctrl_ptr (inst->ctx,V4L2_CID_STATELESS_H264_SPS ); -const struct v4l2_ctrl_h264_pps *pps = -get_ctrl_ptr (inst->ctx,V4L2_CID_STATELESS_H264_PPS ); -const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix = -get_ctrl_ptr (inst->ctx,V4L2_CID_STATELESS_H264_SCALING_MATRIX ); +const struct v4l2_ctrl_h264_decode_params *dec_params; +const struct v4l2_ctrl_h264_sps *sps; +const struct v4l2_ctrl_h264_pps *pps; +const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;struct mtk_h264_dec_slice_param *slice_param = &inst->h264_slice_param;struct v4l2_h264_reflist_builder reflist_builder;u8 *p0_reflist = slice_param->decode_params.ref_pic_list_p0;u8 *b0_reflist = slice_param->decode_params.ref_pic_list_b0;u8 *b1_reflist = slice_param->decode_params.ref_pic_list_b1; -update_dpb (dec_params, inst->dpb); + dec_params = +mtk_vdec_h264_get_ctrl_ptr (inst->ctx,V4L2_CID_STATELESS_H264_DECODE_PARAMS ); +if (IS_ERR (dec_params)) +return PTR_ERR (dec_params); + + sps =mtk_vdec_h264_get_ctrl_ptr (inst->ctx,V4L2_CID_STATELESS_H264_SPS ); +if (IS_ERR (sps)) +return PTR_ERR (sps); + + pps =mtk_vdec_h264_get_ctrl_ptr (inst->ctx,V4L2_CID_STATELESS_H264_PPS ); +if (IS_ERR (pps)) +return PTR_ERR (pps); -get_h264_sps_parameters (&slice_param->sps, sps); -get_h264_pps_parameters (&slice_param->pps, pps); -get_h264_scaling_matrix (&slice_param->scaling_matrix, scaling_matrix); -get_h264_decode_parameters (&slice_param->decode_params, dec_params, - inst->dpb); -get_h264_dpb_list (inst, slice_param); + scaling_matrix = +mtk_vdec_h264_get_ctrl_ptr (inst->ctx,V4L2_CID_STATELESS_H264_SCALING_MATRIX ); +if (IS_ERR (scaling_matrix)) +return PTR_ERR (scaling_matrix); + +mtk_vdec_h264_update_dpb (dec_params, inst->dpb); + +mtk_vdec_h264_copy_sps_params (&slice_param->sps, sps); +mtk_vdec_h264_copy_pps_params (&slice_param->pps, pps); +mtk_vdec_h264_copy_scaling_matrix (&slice_param->scaling_matrix, scaling_matrix); +mtk_vdec_h264_copy_decode_params (&slice_param->decode_params, + dec_params, inst->dpb); +mtk_vdec_h264_fill_dpb_info (inst->ctx, &slice_param->decode_params, + slice_param->h264_dpb_info);/* Build the reference lists */ v4l2_h264_init_reflist_builder(&reflist_builder, dec_params, sps,@@ -478,19 +140,14 @@ static void get_vdec_decode_parameters(struct vdec_h264_slice_inst *inst)v4l2_h264_build_p_ref_list (&reflist_builder, p0_reflist);v4l2_h264_build_b_ref_lists (&reflist_builder, b0_reflist, b1_reflist);/* Adapt the built lists to the firmware's expectations */ -fixup_ref_list (p0_reflist, reflist_builder.num_valid); -fixup_ref_list (b0_reflist, reflist_builder.num_valid); -fixup_ref_list (b1_reflist, reflist_builder.num_valid); +mtk_vdec_h264_fixup_ref_list (p0_reflist, reflist_builder.num_valid); +mtk_vdec_h264_fixup_ref_list (b0_reflist, reflist_builder.num_valid); +mtk_vdec_h264_fixup_ref_list (b1_reflist, reflist_builder.num_valid);memcpy (&inst->vsi_ctx.h264_slice_params, slice_param,sizeof (inst->vsi_ctx.h264_slice_params)); -} -static unsigned int get_mv_buf_size (unsigned int width,unsigned int height) -{ -int unit_size = (width /MB_UNIT_LEN ) * (height /MB_UNIT_LEN ) +8 ; - -return HW_MB_STORE_SZ * unit_size; +return 0 ; }static int allocate_predication_buf (struct vdec_h264_slice_inst *inst)@@ -525,7 +182,7 @@ static int alloc_mv_buf(struct vdec_h264_slice_inst *inst,int i;int err;struct mtk_vcodec_mem *mem =NULL ; -unsigned int buf_sz =get_mv_buf_size (pic->buf_w, pic->buf_h); +unsigned int buf_sz =mtk_vdec_h264_get_mv_buf_size (pic->buf_w, pic->buf_h);mtk_v4l2_debug (3 ,"size = 0x%x" , buf_sz);for (i =0 ; i <H264_MAX_MV_NUM ; i++) {@@ -674,7 +331,7 @@ static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs, {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 ); +mtk_vdec_h264_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;@@ -684,6 +341,7 @@ static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,u64 c_fb_dma;int err; + inst->num_nalu++;/* bs NULL means flush decoder */ if (!bs)return vpu_dec_reset (vpu);@@ -696,7 +354,7 @@ static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs, c_fb_dma = fb ? (u64 )fb->base_c.dma_addr :0 ;mtk_vcodec_debug (inst,"+ [%d] FB y_dma=%llx c_dma=%llx va=%p" , - ++inst->num_nalu, y_fb_dma, c_fb_dma, fb); + inst->num_nalu, y_fb_dma, c_fb_dma, fb); inst->vsi_ctx.dec.bs_dma = (uint64_t )bs->dma_addr; inst->vsi_ctx.dec.y_fb_dma = y_fb_dma;@@ -705,7 +363,10 @@ static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,v4l2_m2m_buf_copy_metadata (&src_buf_info->m2m_buf.vb, &dst_buf_info->m2m_buf.vb, true); -get_vdec_decode_parameters (inst); + err =get_vdec_decode_parameters (inst); +if (err) + goto err_free_fb_out; + data[0 ] = bs->size;/* * Reconstruct the first byte of the NAL unit, as the firmware requests
Yunfei Dong
maintainerPATCH v11 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 | 629 ++++++++++++++++++ .../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, 643 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 +629 -0
629 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 v11 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 v11 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.
--- .../media/platform/mediatek/vcodec/Kconfig | 1 + .../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 | 2031 +++++++++++++++++ .../platform/mediatek/vcodec/vdec_drv_if.c | 4 + .../platform/mediatek/vcodec/vdec_drv_if.h | 1 + 7 files changed, 2062 insertions(+), 3 deletions(-) create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
drivers/media/platform/mediatek/vcodec/Kconfig +1 -0
@@ -22,6 +22,7 @@ config VIDEO_MEDIATEK_VCODEC select VIDEO_MEDIATEK_VCODEC_VPU if VIDEO_MEDIATEK_VPU select VIDEO_MEDIATEK_VCODEC_SCP if MTK_SCP select V4L2_H264 + select V4L2_VP9 select MEDIA_CONTROLLER select MEDIA_CONTROLLER_REQUEST_API help
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 +2031 -0
2,031 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
Yunfei Dong
maintainerPATCH v11 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