linux/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_common.h

/* 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_dec_drv.h"

#define NAL_NON_IDR_SLICE
#define NAL_IDR_SLICE
#define NAL_TYPE(value)

#define BUF_PREDICTION_SZ
#define MB_UNIT_LEN

/* motion vector size (bytes) for every macro block */
#define HW_MB_STORE_SZ

#define H264_MAX_MV_NUM

/**
 * 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 {};

/*
 * struct mtk_h264_sps_param  - parameters for sps
 */
struct mtk_h264_sps_param {};

/*
 * struct mtk_h264_pps_param  - parameters for pps
 */
struct mtk_h264_pps_param {};

/*
 * struct mtk_h264_slice_hd_param  - parameters for slice header
 */
struct mtk_h264_slice_hd_param {};

/*
 * struct slice_api_h264_scaling_matrix  - parameters for scaling list
 */
struct slice_api_h264_scaling_matrix {};

/*
 * struct slice_h264_dpb_entry  - each dpb information
 */
struct slice_h264_dpb_entry {};

/*
 * struct slice_api_h264_decode_param - parameters for decode.
 */
struct slice_api_h264_decode_param {};

/**
 * 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 {};

/**
 * mtk_vdec_h264_get_ref_list - translate V4L2 reference list
 *
 * @ref_list:		Mediatek reference picture list
 * @v4l2_ref_list:	V4L2 reference picture list
 * @num_valid:		used reference number
 */
void mtk_vdec_h264_get_ref_list(u8 *ref_list,
				const struct v4l2_h264_reference *v4l2_ref_list,
				int num_valid);

/**
 * mtk_vdec_h264_get_ctrl_ptr - get each CID control address.
 *
 * @ctx:	v4l2 ctx
 * @id:	CID control ID
 *
 * Return: returns CID ctrl address.
 */
void *mtk_vdec_h264_get_ctrl_ptr(struct mtk_vcodec_dec_ctx *ctx, int id);

/**
 * mtk_vdec_h264_fill_dpb_info - Fill the decoded picture buffer info
 *
 * @ctx:		v4l2 ctx
 * @decode_params:	slice decode params
 * @h264_dpb_info:	dpb buffer information
 */
void mtk_vdec_h264_fill_dpb_info(struct mtk_vcodec_dec_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 - Copy scaling matrix from a control to the driver
 *
 * @dst_matrix:	scaling list params for the HW decoder
 * @src_matrix:	scaling list params from a V4L2 control
 *
 * This function is used to copy the scaling matrix from a
 * v4l2 control into the slice parameters for a decode.
 */
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 - update 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