// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2022 MediaTek Inc. * Author: Yunfei Dong <[email protected]> */ #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_dec.h" #include "../../common/mtk_vcodec_intr.h" #include "../vdec_drv_base.h" #include "../vdec_drv_if.h" #include "../vdec_vpu_if.h" #include "vdec_h264_req_common.h" /** * enum vdec_h264_core_dec_err_type - core decode error type * * @TRANS_BUFFER_FULL: trans buffer is full * @SLICE_HEADER_FULL: slice header buffer is full */ enum vdec_h264_core_dec_err_type { … }; /** * struct vdec_h264_slice_lat_dec_param - parameters for decode current frame * * @sps: h264 sps syntax parameters * @pps: h264 pps syntax parameters * @slice_header: h264 slice header syntax parameters * @scaling_matrix: h264 scaling list parameters * @decode_params: decoder parameters of each frame used for hardware decode * @h264_dpb_info: dpb reference list */ struct vdec_h264_slice_lat_dec_param { … }; /** * struct vdec_h264_slice_info - decode information * * @nal_info: nal info of current picture * @timeout: Decode timeout: 1 timeout, 0 no timeout * @bs_buf_size: bitstream size * @bs_buf_addr: bitstream buffer dma address * @y_fb_dma: Y frame buffer dma address * @c_fb_dma: C frame buffer dma address * @vdec_fb_va: VDEC frame buffer struct virtual address * @crc: Used to check whether hardware's status is right */ struct vdec_h264_slice_info { … }; /** * struct vdec_h264_slice_vsi - shared memory for decode information exchange * between SCP and Host. * * @wdma_err_addr: wdma error dma address * @wdma_start_addr: wdma start dma address * @wdma_end_addr: wdma end dma address * @slice_bc_start_addr: slice bc start dma address * @slice_bc_end_addr: slice bc end dma address * @row_info_start_addr: row info start dma address * @row_info_end_addr: row info end dma address * @trans_start: trans start dma address * @trans_end: trans end dma address * @wdma_end_addr_offset: wdma end address offset * * @mv_buf_dma: HW working motion vector buffer * dma address (AP-W, VPU-R) * @dec: decode information (AP-R, VPU-W) * @h264_slice_params: decode parameters for hw used */ struct vdec_h264_slice_vsi { … }; /** * struct vdec_h264_slice_share_info - shared information used to exchange * message between lat and core * * @sps: sequence header information from user space * @dec_params: decoder params from user space * @h264_slice_params: decoder params used for hardware * @trans_start: trans start dma address * @trans_end: trans end dma address * @nal_info: nal info of current picture */ struct vdec_h264_slice_share_info { … }; /** * struct vdec_h264_slice_inst - h264 decoder instance * * @slice_dec_num: Number of frames to be decoded * @ctx: point to mtk_vcodec_dec_ctx * @pred_buf: HW working prediction buffer * @mv_buf: HW working motion vector buffer * @vpu: VPU instance * @vsi: vsi used for lat * @vsi_core: vsi used for core * * @vsi_ctx: Local VSI data for this decoding context * @h264_slice_param: the parameters that hardware use to decode * * @resolution_changed:resolution changed * @realloc_mv_buf: reallocate mv buffer * @cap_num_planes: number of capture queue plane * * @dpb: decoded picture buffer used to store reference * buffer information *@is_field_bitstream: is field bitstream */ struct vdec_h264_slice_inst { … }; static int vdec_h264_slice_fill_decode_parameters(struct vdec_h264_slice_inst *inst, struct vdec_h264_slice_share_info *share_info) { … } static int get_vdec_sig_decode_parameters(struct vdec_h264_slice_inst *inst) { … } static void vdec_h264_slice_fill_decode_reflist(struct vdec_h264_slice_inst *inst, struct vdec_h264_slice_lat_dec_param *slice_param, struct vdec_h264_slice_share_info *share_info) { … } static int vdec_h264_slice_alloc_mv_buf(struct vdec_h264_slice_inst *inst, struct vdec_pic_info *pic) { … } static void vdec_h264_slice_free_mv_buf(struct vdec_h264_slice_inst *inst) { … } static void vdec_h264_slice_get_pic_info(struct vdec_h264_slice_inst *inst) { … } static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst, struct v4l2_rect *cr) { … } static int vdec_h264_slice_init(struct mtk_vcodec_dec_ctx *ctx) { … } static void vdec_h264_slice_deinit(void *h_vdec) { … } static int vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf) { … } static void vdec_h264_insert_startcode(struct mtk_vcodec_dec_dev *vcodec_dev, unsigned char *buf, size_t *bs_size, struct mtk_h264_pps_param *pps) { … } static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, struct vdec_fb *fb, bool *res_chg) { … } static int vdec_h264_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs, struct vdec_fb *unused, bool *res_chg) { … } static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs, struct vdec_fb *unused, bool *res_chg) { … } static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type, void *out) { … } const struct vdec_common_if vdec_h264_slice_multi_if = …;