// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2016 MediaTek Inc. * Author: Daniel Hsiao <[email protected]> * Kai-Sean Yang <[email protected]> * Tiffany Lin <[email protected]> */ #include <linux/fs.h> #include <linux/slab.h> #include <linux/syscalls.h> #include <linux/delay.h> #include <linux/time.h> #include "../../common/mtk_vcodec_intr.h" #include "../vdec_drv_base.h" #include "../vdec_vpu_if.h" #define VP9_MAX_SUPER_FRAMES_NUM … #define VP9_SUPER_FRAME_BS_SZ … #define MAX_VP9_DPB_SIZE … #define REFS_PER_FRAME … #define MAX_NUM_REF_FRAMES … #define VP9_MAX_FRM_BUF_NUM … #define VP9_MAX_FRM_BUF_NODE_NUM … #define VP9_SEG_ID_SZ … /** * struct vp9_dram_buf - contains buffer info for vpu * @va : cpu address * @pa : iova address * @sz : buffer size * @padding : for 64 bytes alignment */ struct vp9_dram_buf { … }; /** * struct vp9_fb_info - contains frame buffer info * @fb : frame buffer * @reserved : reserved field used by vpu */ struct vp9_fb_info { … }; /** * struct vp9_ref_cnt_buf - contains reference buffer information * @buf : referenced frame buffer * @ref_cnt : referenced frame buffer's reference count. * When reference count=0, remove it from reference list */ struct vp9_ref_cnt_buf { … }; /** * struct vp9_ref_buf - contains current frame's reference buffer information * @buf : reference buffer * @idx : reference buffer index to frm_bufs * @reserved : reserved field used by vpu */ struct vp9_ref_buf { … }; /** * struct vp9_sf_ref_fb - contains frame buffer info * @fb : super frame reference frame buffer * @used : this reference frame info entry is used * @padding : for 64 bytes size align */ struct vp9_sf_ref_fb { … }; /* * struct vdec_vp9_vsi - shared buffer between host and VPU firmware * AP-W/R : AP is writer/reader on this item * VPU-W/R: VPU is write/reader on this item * @sf_bs_buf : super frame backup buffer (AP-W, VPU-R) * @sf_ref_fb : record super frame reference buffer information * (AP-R/W, VPU-R/W) * @sf_next_ref_fb_idx : next available super frame (AP-W, VPU-R) * @sf_frm_cnt : super frame count, filled by vpu (AP-R, VPU-W) * @sf_frm_offset : super frame offset, filled by vpu (AP-R, VPU-W) * @sf_frm_sz : super frame size, filled by vpu (AP-R, VPU-W) * @sf_frm_idx : current super frame (AP-R, VPU-W) * @sf_init : inform super frame info already parsed by vpu (AP-R, VPU-W) * @fb : capture buffer (AP-W, VPU-R) * @bs : bs buffer (AP-W, VPU-R) * @cur_fb : current show capture buffer (AP-R/W, VPU-R/W) * @pic_w : picture width (AP-R, VPU-W) * @pic_h : picture height (AP-R, VPU-W) * @buf_w : codec width (AP-R, VPU-W) * @buf_h : coded height (AP-R, VPU-W) * @buf_sz_y_bs : ufo compressed y plane size (AP-R, VPU-W) * @buf_sz_c_bs : ufo compressed cbcr plane size (AP-R, VPU-W) * @buf_len_sz_y : size used to store y plane ufo info (AP-R, VPU-W) * @buf_len_sz_c : size used to store cbcr plane ufo info (AP-R, VPU-W) * @profile : profile sparsed from vpu (AP-R, VPU-W) * @show_frame : [BIT(0)] display this frame or not (AP-R, VPU-W) * [BIT(1)] reset segment data or not (AP-R, VPU-W) * [BIT(2)] trig decoder hardware or not (AP-R, VPU-W) * [BIT(3)] ask VPU to set bits(0~4) accordingly (AP-W, VPU-R) * [BIT(4)] do not reset segment data before every frame (AP-R, VPU-W) * @show_existing_frame : inform this frame is show existing frame * (AP-R, VPU-W) * @frm_to_show_idx : index to show frame (AP-R, VPU-W) * @refresh_frm_flags : indicate when frame need to refine reference count * (AP-R, VPU-W) * @resolution_changed : resolution change in this frame (AP-R, VPU-W) * @frm_bufs : maintain reference buffer info (AP-R/W, VPU-R/W) * @ref_frm_map : maintain reference buffer map info (AP-R/W, VPU-R/W) * @new_fb_idx : index to frm_bufs array (AP-R, VPU-W) * @frm_num : decoded frame number, include sub-frame count (AP-R, VPU-W) * @mv_buf : motion vector working buffer (AP-W, VPU-R) * @frm_refs : maintain three reference buffer info (AP-R/W, VPU-R/W) * @seg_id_buf : segmentation map working buffer (AP-W, VPU-R) */ struct vdec_vp9_vsi { … }; /* * struct vdec_vp9_inst - vp9 decode instance * @mv_buf : working buffer for mv * @seg_id_buf : working buffer for segmentation map * @dec_fb : vdec_fb node to link fb to different fb_xxx_list * @available_fb_node_list : current available vdec_fb node * @fb_use_list : current used or referenced vdec_fb * @fb_free_list : current available to free vdec_fb * @fb_disp_list : current available to display vdec_fb * @cur_fb : current frame buffer * @ctx : current decode context * @vpu : vpu instance information * @vsi : shared buffer between host and VPU firmware * @total_frm_cnt : total frame count, it do not include sub-frames in super * frame * @mem : instance memory information */ struct vdec_vp9_inst { … }; static bool vp9_is_sf_ref_fb(struct vdec_vp9_inst *inst, struct vdec_fb *fb) { … } static struct vdec_fb *vp9_rm_from_fb_use_list(struct vdec_vp9_inst *inst, void *addr) { … } static void vp9_add_to_fb_free_list(struct vdec_vp9_inst *inst, struct vdec_fb *fb) { … } static void vp9_free_sf_ref_fb(struct vdec_fb *fb) { … } static void vp9_ref_cnt_fb(struct vdec_vp9_inst *inst, int *idx, int new_idx) { … } static void vp9_free_all_sf_ref_fb(struct vdec_vp9_inst *inst) { … } /* For each sub-frame except the last one, the driver will dynamically * allocate reference buffer by calling vp9_get_sf_ref_fb() * The last sub-frame will use the original fb provided by the * vp9_dec_decode() interface */ static int vp9_get_sf_ref_fb(struct vdec_vp9_inst *inst) { … } static bool vp9_alloc_work_buf(struct vdec_vp9_inst *inst) { … } static bool vp9_add_to_fb_disp_list(struct vdec_vp9_inst *inst, struct vdec_fb *fb) { … } /* If any buffer updating is signaled it should be done here. */ static void vp9_swap_frm_bufs(struct vdec_vp9_inst *inst) { … } static bool vp9_wait_dec_end(struct vdec_vp9_inst *inst) { … } static struct vdec_vp9_inst *vp9_alloc_inst(struct mtk_vcodec_dec_ctx *ctx) { … } static void vp9_free_inst(struct vdec_vp9_inst *inst) { … } static bool vp9_decode_end_proc(struct vdec_vp9_inst *inst) { … } static bool vp9_is_last_sub_frm(struct vdec_vp9_inst *inst) { … } static struct vdec_fb *vp9_rm_from_fb_disp_list(struct vdec_vp9_inst *inst) { … } static bool vp9_add_to_fb_use_list(struct vdec_vp9_inst *inst, struct vdec_fb *fb) { … } static void vp9_reset(struct vdec_vp9_inst *inst) { … } static void init_all_fb_lists(struct vdec_vp9_inst *inst) { … } static void get_pic_info(struct vdec_vp9_inst *inst, struct vdec_pic_info *pic) { … } static void get_disp_fb(struct vdec_vp9_inst *inst, struct vdec_fb **out_fb) { … } static void get_free_fb(struct vdec_vp9_inst *inst, struct vdec_fb **out_fb) { … } static int validate_vsi_array_indexes(struct vdec_vp9_inst *inst, struct vdec_vp9_vsi *vsi) { … } static void vdec_vp9_deinit(void *h_vdec) { … } static int vdec_vp9_init(struct mtk_vcodec_dec_ctx *ctx) { … } static int vdec_vp9_decode(void *h_vdec, struct mtk_vcodec_mem *bs, struct vdec_fb *fb, bool *res_chg) { … } static void get_crop_info(struct vdec_vp9_inst *inst, struct v4l2_rect *cr) { … } static int vdec_vp9_get_param(void *h_vdec, enum vdec_get_param_type type, void *out) { … } const struct vdec_common_if vdec_vp9_if = …;