xref: /linux/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.h (revision f4b369c6fe0ceaba2da2daff8c9eb415f85926dd)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Rockchip video decoder hevc common functions
4  *
5  * Copyright (C) 2025 Collabora, Ltd.
6  *      Detlev Casanova <detlev.casanova@collabora.com>
7  *
8  * Copyright (C) 2023 Collabora, Ltd.
9  *      Sebastian Fricke <sebastian.fricke@collabora.com>
10  *
11  * Copyright (C) 2019 Collabora, Ltd.
12  *	Boris Brezillon <boris.brezillon@collabora.com>
13  *
14  * Copyright (C) 2016 Rockchip Electronics Co., Ltd.
15  *	Jeffy Chen <jeffy.chen@rock-chips.com>
16  */
17 
18 #include <media/v4l2-mem2mem.h>
19 #include <linux/types.h>
20 
21 #include "rkvdec.h"
22 
23 struct rkvdec_rps_refs {
24 	u16 lt_ref_pic_poc_lsb;
25 	u16 used_by_curr_pic_lt_flag	: 1;
26 	u16 reserved			: 15;
27 } __packed;
28 
29 struct rkvdec_rps_short_term_ref_set {
30 	u32 num_negative	: 4;
31 	u32 num_positive	: 4;
32 	u32 delta_poc0		: 16;
33 	u32 used_flag0		: 1;
34 	u32 delta_poc1		: 16;
35 	u32 used_flag1		: 1;
36 	u32 delta_poc2		: 16;
37 	u32 used_flag2		: 1;
38 	u32 delta_poc3		: 16;
39 	u32 used_flag3		: 1;
40 	u32 delta_poc4		: 16;
41 	u32 used_flag4		: 1;
42 	u32 delta_poc5		: 16;
43 	u32 used_flag5		: 1;
44 	u32 delta_poc6		: 16;
45 	u32 used_flag6		: 1;
46 	u32 delta_poc7		: 16;
47 	u32 used_flag7		: 1;
48 	u32 delta_poc8		: 16;
49 	u32 used_flag8		: 1;
50 	u32 delta_poc9		: 16;
51 	u32 used_flag9		: 1;
52 	u32 delta_poc10		: 16;
53 	u32 used_flag10		: 1;
54 	u32 delta_poc11		: 16;
55 	u32 used_flag11		: 1;
56 	u32 delta_poc12		: 16;
57 	u32 used_flag12		: 1;
58 	u32 delta_poc13		: 16;
59 	u32 used_flag13		: 1;
60 	u32 delta_poc14		: 16;
61 	u32 used_flag14		: 1;
62 	u32 reserved_bits	: 25;
63 	u32 reserved[3];
64 } __packed;
65 
66 struct rkvdec_rps {
67 	struct rkvdec_rps_refs refs[32];
68 	struct rkvdec_rps_short_term_ref_set short_term_ref_sets[64];
69 } __packed;
70 
71 struct rkvdec_hevc_run {
72 	struct rkvdec_run base;
73 	const struct v4l2_ctrl_hevc_slice_params *slices_params;
74 	const struct v4l2_ctrl_hevc_decode_params *decode_params;
75 	const struct v4l2_ctrl_hevc_sps *sps;
76 	const struct v4l2_ctrl_hevc_pps *pps;
77 	const struct v4l2_ctrl_hevc_scaling_matrix *scaling_matrix;
78 	const struct v4l2_ctrl_hevc_ext_sps_st_rps *ext_sps_st_rps;
79 	const struct v4l2_ctrl_hevc_ext_sps_lt_rps *ext_sps_lt_rps;
80 	int num_slices;
81 };
82 
83 struct scaling_factor {
84 	u8 scalingfactor0[1248];
85 	u8 scalingfactor1[96];	/*4X4 TU Rotate, total 16X4*/
86 	u8 scalingdc[12];	/*N1005 Vienna Meeting*/
87 	u8 reserved[4];		/*16Bytes align*/
88 };
89 
90 void compute_tiles_uniform(struct rkvdec_hevc_run *run, u16 log2_min_cb_size,
91 			   u16 width, u16 height, s32 pic_in_cts_width,
92 			   s32 pic_in_cts_height, u16 *column_width, u16 *row_height);
93 void compute_tiles_non_uniform(struct rkvdec_hevc_run *run, u16 log2_min_cb_size,
94 			       u16 width, u16 height, s32 pic_in_cts_width,
95 			       s32 pic_in_cts_height, u16 *column_width, u16 *row_height);
96 void rkvdec_hevc_assemble_hw_rps(struct rkvdec_hevc_run *run, struct rkvdec_rps *rps,
97 				 struct v4l2_ctrl_hevc_ext_sps_st_rps *st_cache);
98 void rkvdec_hevc_assemble_hw_scaling_list(struct rkvdec_ctx *ctx,
99 					  struct rkvdec_hevc_run *run,
100 					  struct scaling_factor *scaling_factor,
101 					  struct v4l2_ctrl_hevc_scaling_matrix *cache);
102 struct vb2_buffer *get_ref_buf(struct rkvdec_ctx *ctx,
103 			       struct rkvdec_hevc_run *run,
104 			       unsigned int dpb_idx);
105 int rkvdec_hevc_adjust_fmt(struct rkvdec_ctx *ctx, struct v4l2_format *f);
106 enum rkvdec_image_fmt rkvdec_hevc_get_image_fmt(struct rkvdec_ctx *ctx, struct v4l2_ctrl *ctrl);
107 void rkvdec_hevc_run_preamble(struct rkvdec_ctx *ctx, struct rkvdec_hevc_run *run);
108