// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2016 MediaTek Inc. * Author: Daniel Hsiao <[email protected]> * PoChun Lin <[email protected]> */ #include <linux/interrupt.h> #include <linux/kernel.h> #include <linux/slab.h> #include "../mtk_vcodec_enc_drv.h" #include "../../common/mtk_vcodec_intr.h" #include "../mtk_vcodec_enc.h" #include "../mtk_vcodec_enc_pm.h" #include "../venc_drv_base.h" #include "../venc_ipi_msg.h" #include "../venc_vpu_if.h" #define VENC_BITSTREAM_FRAME_SIZE … #define VENC_BITSTREAM_HEADER_LEN … /* This ac_tag is vp8 frame tag. */ #define MAX_AC_TAG_SIZE … /* * enum venc_vp8_vpu_work_buf - vp8 encoder buffer index */ enum venc_vp8_vpu_work_buf { … }; /* * struct venc_vp8_vpu_config - Structure for vp8 encoder configuration * AP-W/R : AP is writer/reader on this item * VPU-W/R: VPU is write/reader on this item * @input_fourcc: input fourcc * @bitrate: target bitrate (in bps) * @pic_w: picture width. Picture size is visible stream resolution, in pixels, * to be used for display purposes; must be smaller or equal to buffer * size. * @pic_h: picture height * @buf_w: buffer width (with 16 alignment). Buffer size is stream resolution * in pixels aligned to hardware requirements. * @buf_h: buffer height (with 16 alignment) * @gop_size: group of picture size (key frame) * @framerate: frame rate in fps * @ts_mode: temporal scalability mode (0: disable, 1: enable) * support three temporal layers - 0: 7.5fps 1: 7.5fps 2: 15fps. */ struct venc_vp8_vpu_config { … }; /* * struct venc_vp8_vpu_buf - Structure for buffer information * AP-W/R : AP is writer/reader on this item * VPU-W/R: VPU is write/reader on this item * @iova: IO virtual address * @vpua: VPU side memory addr which is used by RC_CODE * @size: buffer size (in bytes) */ struct venc_vp8_vpu_buf { … }; /* * struct venc_vp8_vsi - Structure for VPU driver control and info share * AP-W/R : AP is writer/reader on this item * VPU-W/R: VPU is write/reader on this item * This structure is allocated in VPU side and shared to AP side. * @config: vp8 encoder configuration * @work_bufs: working buffer information in VPU side * The work_bufs here is for storing the 'size' info shared to AP side. * The similar item in struct venc_vp8_inst is for memory allocation * in AP side. The AP driver will copy the 'size' from here to the one in * struct mtk_vcodec_mem, then invoke mtk_vcodec_mem_alloc to allocate * the buffer. After that, bypass the 'dma_addr' to the 'iova' field here for * register setting in VPU side. */ struct venc_vp8_vsi { … }; /* * struct venc_vp8_inst - vp8 encoder AP driver instance * @hw_base: vp8 encoder hardware register base * @work_bufs: working buffer * @work_buf_allocated: working buffer allocated flag * @frm_cnt: encoded frame count, it's used for I-frame judgement and * reset when force intra cmd received. * @ts_mode: temporal scalability mode (0: disable, 1: enable) * support three temporal layers - 0: 7.5fps 1: 7.5fps 2: 15fps. * @vpu_inst: VPU instance to exchange information between AP and VPU * @vsi: driver structure allocated by VPU side and shared to AP side for * control and info share * @ctx: context for v4l2 layer integration */ struct venc_vp8_inst { … }; static inline u32 vp8_enc_read_reg(struct venc_vp8_inst *inst, u32 addr) { … } static void vp8_enc_free_work_buf(struct venc_vp8_inst *inst) { … } static int vp8_enc_alloc_work_buf(struct venc_vp8_inst *inst) { … } static unsigned int vp8_enc_wait_venc_done(struct venc_vp8_inst *inst) { … } /* * Compose ac_tag, bitstream header and bitstream payload into * one bitstream buffer. */ static int vp8_enc_compose_one_frame(struct venc_vp8_inst *inst, struct mtk_vcodec_mem *bs_buf, unsigned int *bs_size) { … } static int vp8_enc_encode_frame(struct venc_vp8_inst *inst, struct venc_frm_buf *frm_buf, struct mtk_vcodec_mem *bs_buf, unsigned int *bs_size) { … } static int vp8_enc_init(struct mtk_vcodec_enc_ctx *ctx) { … } static int vp8_enc_encode(void *handle, enum venc_start_opt opt, struct venc_frm_buf *frm_buf, struct mtk_vcodec_mem *bs_buf, struct venc_done_result *result) { … } static int vp8_enc_set_param(void *handle, enum venc_set_param_type type, struct venc_enc_param *enc_prm) { … } static int vp8_enc_deinit(void *handle) { … } const struct venc_common_if venc_vp8_if = …;