linux/drivers/staging/media/meson/vdec/codec_vp9.c

// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2018 Maxime Jourdan <[email protected]>
 * Copyright (C) 2015 Amlogic, Inc. All rights reserved.
 */

#include <media/v4l2-mem2mem.h>
#include <media/videobuf2-dma-contig.h>

#include "dos_regs.h"
#include "hevc_regs.h"
#include "codec_vp9.h"
#include "vdec_helpers.h"
#include "codec_hevc_common.h"

/* HEVC reg mapping */
#define VP9_DEC_STATUS_REG
	#define VP9_10B_DECODE_SLICE
	#define VP9_HEAD_PARSER_DONE
#define VP9_RPM_BUFFER
#define VP9_SHORT_TERM_RPS
#define VP9_ADAPT_PROB_REG
#define VP9_MMU_MAP_BUFFER
#define VP9_PPS_BUFFER
#define VP9_SAO_UP
#define VP9_STREAM_SWAP_BUFFER
#define VP9_STREAM_SWAP_BUFFER2
#define VP9_PROB_SWAP_BUFFER
#define VP9_COUNT_SWAP_BUFFER
#define VP9_SEG_MAP_BUFFER
#define VP9_SCALELUT
#define VP9_WAIT_FLAG
#define LMEM_DUMP_ADR
#define NAL_SEARCH_CTL
#define VP9_DECODE_MODE
	#define DECODE_MODE_SINGLE
#define DECODE_STOP_POS
#define HEVC_DECODE_COUNT
#define HEVC_DECODE_SIZE

/* VP9 Constants */
#define LCU_SIZE
#define MAX_REF_PIC_NUM
#define REFS_PER_FRAME
#define REF_FRAMES
#define MV_MEM_UNIT
#define ADAPT_PROB_SIZE

enum FRAME_TYPE {};

/* VP9 Workspace layout */
#define MPRED_MV_BUF_SIZE

#define IPP_SIZE
#define SAO_ABV_SIZE
#define SAO_VB_SIZE
#define SH_TM_RPS_SIZE
#define VPS_SIZE
#define SPS_SIZE
#define PPS_SIZE
#define SAO_UP_SIZE
#define SWAP_BUF_SIZE
#define SWAP_BUF2_SIZE
#define SCALELUT_SIZE
#define DBLK_PARA_SIZE
#define DBLK_DATA_SIZE
#define SEG_MAP_SIZE
#define PROB_SIZE
#define COUNT_SIZE
#define MMU_VBH_SIZE
#define MPRED_ABV_SIZE
#define MPRED_MV_SIZE
#define RPM_BUF_SIZE
#define LMEM_SIZE

#define IPP_OFFSET
#define SAO_ABV_OFFSET
#define SAO_VB_OFFSET
#define SH_TM_RPS_OFFSET
#define VPS_OFFSET
#define SPS_OFFSET
#define PPS_OFFSET
#define SAO_UP_OFFSET
#define SWAP_BUF_OFFSET
#define SWAP_BUF2_OFFSET
#define SCALELUT_OFFSET
#define DBLK_PARA_OFFSET
#define DBLK_DATA_OFFSET
#define SEG_MAP_OFFSET
#define PROB_OFFSET
#define COUNT_OFFSET
#define MMU_VBH_OFFSET
#define MPRED_ABV_OFFSET
#define MPRED_MV_OFFSET
#define RPM_OFFSET
#define LMEM_OFFSET

#define SIZE_WORKSPACE

#define NONE
#define INTRA_FRAME
#define LAST_FRAME
#define GOLDEN_FRAME
#define ALTREF_FRAME
#define MAX_REF_FRAMES

/*
 * Defines, declarations, sub-functions for vp9 de-block loop
	filter Thr/Lvl table update
 * - struct segmentation is for loop filter only (removed something)
 * - function "vp9_loop_filter_init" and "vp9_loop_filter_frame_init" will
	be instantiated in C_Entry
 * - vp9_loop_filter_init run once before decoding start
 * - vp9_loop_filter_frame_init run before every frame decoding start
 * - set video format to VP9 is in vp9_loop_filter_init
 */
#define MAX_LOOP_FILTER
#define MAX_REF_LF_DELTAS
#define MAX_MODE_LF_DELTAS
#define SEGMENT_DELTADATA
#define SEGMENT_ABSDATA
#define MAX_SEGMENTS

/* VP9 PROB processing defines */
#define VP9_PARTITION_START
#define VP9_PARTITION_SIZE_STEP
#define VP9_PARTITION_ONE_SIZE
#define VP9_PARTITION_KEY_START
#define VP9_PARTITION_P_START
#define VP9_PARTITION_SIZE
#define VP9_SKIP_START
#define VP9_SKIP_SIZE
#define VP9_TX_MODE_START
#define VP9_TX_MODE_8_0_OFFSET
#define VP9_TX_MODE_8_1_OFFSET
#define VP9_TX_MODE_16_0_OFFSET
#define VP9_TX_MODE_16_1_OFFSET
#define VP9_TX_MODE_32_0_OFFSET
#define VP9_TX_MODE_32_1_OFFSET
#define VP9_TX_MODE_SIZE
#define VP9_COEF_START
#define VP9_COEF_BAND_0_OFFSET
#define VP9_COEF_BAND_1_OFFSET
#define VP9_COEF_BAND_2_OFFSET
#define VP9_COEF_BAND_3_OFFSET
#define VP9_COEF_BAND_4_OFFSET
#define VP9_COEF_BAND_5_OFFSET
#define VP9_COEF_SIZE_ONE_SET
#define VP9_COEF_4X4_START
#define VP9_COEF_8X8_START
#define VP9_COEF_16X16_START
#define VP9_COEF_32X32_START
#define VP9_COEF_SIZE_PLANE
#define VP9_COEF_SIZE
#define VP9_INTER_MODE_START
#define VP9_INTER_MODE_SIZE
#define VP9_INTERP_START
#define VP9_INTERP_SIZE
#define VP9_INTRA_INTER_START
#define VP9_INTRA_INTER_SIZE
#define VP9_INTERP_INTRA_INTER_START
#define VP9_INTERP_INTRA_INTER_SIZE
#define VP9_COMP_INTER_START
#define VP9_COMP_INTER_SIZE
#define VP9_COMP_REF_START
#define VP9_COMP_REF_SIZE
#define VP9_SINGLE_REF_START
#define VP9_SINGLE_REF_SIZE
#define VP9_REF_MODE_START
#define VP9_REF_MODE_SIZE
#define VP9_IF_Y_MODE_START
#define VP9_IF_Y_MODE_SIZE
#define VP9_IF_UV_MODE_START
#define VP9_IF_UV_MODE_SIZE
#define VP9_MV_JOINTS_START
#define VP9_MV_JOINTS_SIZE
#define VP9_MV_SIGN_0_START
#define VP9_MV_SIGN_0_SIZE
#define VP9_MV_CLASSES_0_START
#define VP9_MV_CLASSES_0_SIZE
#define VP9_MV_CLASS0_0_START
#define VP9_MV_CLASS0_0_SIZE
#define VP9_MV_BITS_0_START
#define VP9_MV_BITS_0_SIZE
#define VP9_MV_SIGN_1_START
#define VP9_MV_SIGN_1_SIZE
#define VP9_MV_CLASSES_1_START
#define VP9_MV_CLASSES_1_SIZE
#define VP9_MV_CLASS0_1_START
#define VP9_MV_CLASS0_1_SIZE
#define VP9_MV_BITS_1_START
#define VP9_MV_BITS_1_SIZE
#define VP9_MV_CLASS0_FP_0_START
#define VP9_MV_CLASS0_FP_0_SIZE
#define VP9_MV_CLASS0_FP_1_START
#define VP9_MV_CLASS0_FP_1_SIZE
#define VP9_MV_CLASS0_HP_0_START
#define VP9_MV_CLASS0_HP_0_SIZE
#define VP9_MV_CLASS0_HP_1_START
#define VP9_MV_CLASS0_HP_1_SIZE
#define VP9_MV_START
#define VP9_MV_SIZE

#define VP9_TOTAL_SIZE

/* VP9 COUNT mem processing defines */
#define VP9_COEF_COUNT_START
#define VP9_COEF_COUNT_BAND_0_OFFSET
#define VP9_COEF_COUNT_BAND_1_OFFSET
#define VP9_COEF_COUNT_BAND_2_OFFSET
#define VP9_COEF_COUNT_BAND_3_OFFSET
#define VP9_COEF_COUNT_BAND_4_OFFSET
#define VP9_COEF_COUNT_BAND_5_OFFSET
#define VP9_COEF_COUNT_SIZE_ONE_SET
#define VP9_COEF_COUNT_4X4_START
#define VP9_COEF_COUNT_8X8_START
#define VP9_COEF_COUNT_16X16_START
#define VP9_COEF_COUNT_32X32_START
#define VP9_COEF_COUNT_SIZE_PLANE
#define VP9_COEF_COUNT_SIZE

#define VP9_INTRA_INTER_COUNT_START
#define VP9_INTRA_INTER_COUNT_SIZE
#define VP9_COMP_INTER_COUNT_START
#define VP9_COMP_INTER_COUNT_SIZE
#define VP9_COMP_REF_COUNT_START
#define VP9_COMP_REF_COUNT_SIZE
#define VP9_SINGLE_REF_COUNT_START
#define VP9_SINGLE_REF_COUNT_SIZE
#define VP9_TX_MODE_COUNT_START
#define VP9_TX_MODE_COUNT_SIZE
#define VP9_SKIP_COUNT_START
#define VP9_SKIP_COUNT_SIZE
#define VP9_MV_SIGN_0_COUNT_START
#define VP9_MV_SIGN_0_COUNT_SIZE
#define VP9_MV_SIGN_1_COUNT_START
#define VP9_MV_SIGN_1_COUNT_SIZE
#define VP9_MV_BITS_0_COUNT_START
#define VP9_MV_BITS_0_COUNT_SIZE
#define VP9_MV_BITS_1_COUNT_START
#define VP9_MV_BITS_1_COUNT_SIZE
#define VP9_MV_CLASS0_HP_0_COUNT_START
#define VP9_MV_CLASS0_HP_0_COUNT_SIZE
#define VP9_MV_CLASS0_HP_1_COUNT_START
#define VP9_MV_CLASS0_HP_1_COUNT_SIZE

/* Start merge_tree */
#define VP9_INTER_MODE_COUNT_START
#define VP9_INTER_MODE_COUNT_SIZE
#define VP9_IF_Y_MODE_COUNT_START
#define VP9_IF_Y_MODE_COUNT_SIZE
#define VP9_IF_UV_MODE_COUNT_START
#define VP9_IF_UV_MODE_COUNT_SIZE
#define VP9_PARTITION_P_COUNT_START
#define VP9_PARTITION_P_COUNT_SIZE
#define VP9_INTERP_COUNT_START
#define VP9_INTERP_COUNT_SIZE
#define VP9_MV_JOINTS_COUNT_START
#define VP9_MV_JOINTS_COUNT_SIZE
#define VP9_MV_CLASSES_0_COUNT_START
#define VP9_MV_CLASSES_0_COUNT_SIZE
#define VP9_MV_CLASS0_0_COUNT_START
#define VP9_MV_CLASS0_0_COUNT_SIZE
#define VP9_MV_CLASSES_1_COUNT_START
#define VP9_MV_CLASSES_1_COUNT_SIZE
#define VP9_MV_CLASS0_1_COUNT_START
#define VP9_MV_CLASS0_1_COUNT_SIZE
#define VP9_MV_CLASS0_FP_0_COUNT_START
#define VP9_MV_CLASS0_FP_0_COUNT_SIZE
#define VP9_MV_CLASS0_FP_1_COUNT_START
#define VP9_MV_CLASS0_FP_1_COUNT_SIZE

#define DC_PRED
#define V_PRED
#define H_PRED
#define D45_PRED
#define D135_PRED
#define D117_PRED
#define D153_PRED
#define D207_PRED
#define D63_PRED
#define TM_PRED

/* Use a static inline to avoid possible side effect from num being reused */
static inline int round_power_of_two(int value, int num)
{}

#define MODE_MV_COUNT_SAT
static const int count_to_update_factor[MODE_MV_COUNT_SAT + 1] =;

rpm_param;

enum SEG_LVL_FEATURES {};

struct segmentation {};

struct loop_filter_thresh {};

struct loop_filter_info_n {};

struct loopfilter {};

struct vp9_frame {};

struct codec_vp9 {};

static int div_r32(s64 m, int n)
{}

static int clip_prob(int p)
{}

static int segfeature_active(struct segmentation *seg, int segment_id,
			     enum SEG_LVL_FEATURES feature_id)
{}

static int get_segdata(struct segmentation *seg, int segment_id,
		       enum SEG_LVL_FEATURES feature_id)
{}

static void vp9_update_sharpness(struct loop_filter_info_n *lfi,
				 int sharpness_lvl)
{}

/* Instantiate this function once when decode is started */
static void
vp9_loop_filter_init(struct amvdec_core *core, struct codec_vp9 *vp9)
{}

static void
vp9_loop_filter_frame_init(struct amvdec_core *core, struct segmentation *seg,
			   struct loop_filter_info_n *lfi,
			   struct loopfilter *lf, int default_filt_lvl)
{}

static void codec_vp9_flush_output(struct amvdec_session *sess)
{}

static u32 codec_vp9_num_pending_bufs(struct amvdec_session *sess)
{}

static int codec_vp9_alloc_workspace(struct amvdec_core *core,
				     struct codec_vp9 *vp9)
{}

static void codec_vp9_setup_workspace(struct amvdec_session *sess,
				      struct codec_vp9 *vp9)
{}

static int codec_vp9_start(struct amvdec_session *sess)
{}

static int codec_vp9_stop(struct amvdec_session *sess)
{}

/*
 * Program LAST & GOLDEN frames into the motion compensation reference cache
 * controller
 */
static void codec_vp9_set_mcrcc(struct amvdec_session *sess)
{}

static void codec_vp9_set_sao(struct amvdec_session *sess,
			      struct vb2_buffer *vb)
{}

static dma_addr_t codec_vp9_get_frame_mv_paddr(struct codec_vp9 *vp9,
					       struct vp9_frame *frame)
{}

static void codec_vp9_set_mpred_mv(struct amvdec_core *core,
				   struct codec_vp9 *vp9)
{}

static void codec_vp9_update_next_ref(struct codec_vp9 *vp9)
{}

static void codec_vp9_save_refs(struct codec_vp9 *vp9)
{}

static void codec_vp9_update_ref(struct codec_vp9 *vp9)
{}

static struct vp9_frame *codec_vp9_get_frame_by_idx(struct codec_vp9 *vp9,
						    int idx)
{}

static void codec_vp9_sync_ref(struct codec_vp9 *vp9)
{}

static void codec_vp9_set_refs(struct amvdec_session *sess,
			       struct codec_vp9 *vp9)
{}

static void codec_vp9_set_mc(struct amvdec_session *sess,
			     struct codec_vp9 *vp9)
{}

static struct vp9_frame *codec_vp9_get_new_frame(struct amvdec_session *sess)
{}

static void codec_vp9_show_existing_frame(struct codec_vp9 *vp9)
{}

static void codec_vp9_rm_noshow_frame(struct amvdec_session *sess)
{}

static void codec_vp9_process_frame(struct amvdec_session *sess)
{}

static void codec_vp9_process_lf(struct codec_vp9 *vp9)
{}

static void codec_vp9_resume(struct amvdec_session *sess)
{}

/*
 * The RPM section within the workspace contains
 * many information regarding the parsed bitstream
 */
static void codec_vp9_fetch_rpm(struct amvdec_session *sess)
{}

static int codec_vp9_process_rpm(struct codec_vp9 *vp9)
{}

static bool codec_vp9_is_ref(struct codec_vp9 *vp9, struct vp9_frame *frame)
{}

static void codec_vp9_show_frame(struct amvdec_session *sess)
{}

static void vp9_tree_merge_probs(unsigned int *prev_prob,
				 unsigned int *cur_prob,
				 int coef_node_start, int tree_left,
				 int tree_right,
				 int tree_i, int node)
{}

static void adapt_coef_probs_cxt(unsigned int *prev_prob,
				 unsigned int *cur_prob,
				 unsigned int *count,
				 int update_factor,
				 int cxt_num,
				 int coef_cxt_start,
				 int coef_count_cxt_start)
{}

static void adapt_coef_probs(int prev_kf, int cur_kf, int pre_fc,
			     unsigned int *prev_prob, unsigned int *cur_prob,
			     unsigned int *count)
{}

static irqreturn_t codec_vp9_threaded_isr(struct amvdec_session *sess)
{}

static irqreturn_t codec_vp9_isr(struct amvdec_session *sess)
{}

struct amvdec_codec_ops codec_vp9_ops =;