• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: (GPL-2.0+ OR MIT) */
2 /*
3  * Copyright (c) 2021 Rockchip Electronics Co., Ltd
4  *
5  * author:
6  *	Herman Chen <herman.chen@rock-chips.com>
7  *
8  */
9 #ifndef __ROCKCHIP_MPP_RKVDEC2_H__
10 #define __ROCKCHIP_MPP_RKVDEC2_H__
11 
12 #include <linux/dma-iommu.h>
13 #include <linux/iopoll.h>
14 #include <linux/of_platform.h>
15 #include <linux/of_address.h>
16 #include <linux/slab.h>
17 #include <linux/uaccess.h>
18 #include <linux/regmap.h>
19 #include <linux/kernel.h>
20 #include <linux/thermal.h>
21 #include <linux/notifier.h>
22 #include <linux/proc_fs.h>
23 #include <linux/nospec.h>
24 #include <linux/rockchip/rockchip_sip.h>
25 #include <linux/regulator/consumer.h>
26 
27 #include <soc/rockchip/pm_domains.h>
28 #include <soc/rockchip/rockchip_sip.h>
29 
30 #include "mpp_debug.h"
31 #include "mpp_common.h"
32 #include "mpp_iommu.h"
33 
34 #define RKVDEC_DRIVER_NAME		"mpp_rkvdec2"
35 
36 #define	RKVDEC_SESSION_MAX_BUFFERS	40
37 /* The maximum registers number of all the version */
38 #define RKVDEC_REG_NUM			278
39 #define RKVDEC_REG_HW_ID_INDEX		0
40 #define RKVDEC_REG_START_INDEX		0
41 #define RKVDEC_REG_END_INDEX		277
42 
43 #define REVDEC_GET_PROD_NUM(x)		(((x) >> 16) & 0xffff)
44 #define RKVDEC_REG_FORMAT_INDEX		9
45 #define RKVDEC_GET_FORMAT(x)		((x) & 0x3ff)
46 
47 #define RKVDEC_REG_START_EN_BASE       0x28
48 
49 #define RKVDEC_REG_START_EN_INDEX      10
50 
51 #define RKVDEC_START_EN			BIT(0)
52 
53 #define RKVDEC_REG_YSTRIDE_INDEX	20
54 #define RKVDEC_REG_CORE_CTRL_INDEX	28
55 #define RKVDEC_REG_FILM_IDX_MASK	(0x3ff0000)
56 
57 #define RKVDEC_REG_RLC_BASE		0x200
58 #define RKVDEC_REG_RLC_BASE_INDEX	(128)
59 
60 #define RKVDEC_REG_INT_EN		0x380
61 #define RKVDEC_REG_INT_EN_INDEX		(224)
62 #define RKVDEC_SOFT_RESET_READY		BIT(9)
63 #define RKVDEC_CABAC_END_STA		BIT(8)
64 #define RKVDEC_COLMV_REF_ERR_STA	BIT(7)
65 #define RKVDEC_BUF_EMPTY_STA		BIT(6)
66 #define RKVDEC_TIMEOUT_STA		BIT(5)
67 #define RKVDEC_ERROR_STA		BIT(4)
68 #define RKVDEC_BUS_STA			BIT(3)
69 #define RKVDEC_READY_STA		BIT(2)
70 #define RKVDEC_IRQ_RAW			BIT(1)
71 #define RKVDEC_IRQ			BIT(0)
72 #define RKVDEC_INT_ERROR_MASK		(RKVDEC_COLMV_REF_ERR_STA |\
73 					RKVDEC_BUF_EMPTY_STA |\
74 					RKVDEC_TIMEOUT_STA |\
75 					RKVDEC_ERROR_STA)
76 
77 /* perf sel reference register */
78 #define RKVDEC_PERF_SEL_OFFSET		0x20000
79 #define RKVDEC_PERF_SEL_NUM		64
80 #define RKVDEC_PERF_SEL_BASE		0x424
81 #define RKVDEC_SEL_VAL0_BASE		0x428
82 #define RKVDEC_SEL_VAL1_BASE		0x42c
83 #define RKVDEC_SEL_VAL2_BASE		0x430
84 #define RKVDEC_SET_PERF_SEL(a, b, c)	((a) | ((b) << 8) | ((c) << 16))
85 
86 /* cache reference register */
87 #define RKVDEC_REG_CACHE0_SIZE_BASE	0x51c
88 #define RKVDEC_REG_CACHE1_SIZE_BASE	0x55c
89 #define RKVDEC_REG_CACHE2_SIZE_BASE	0x59c
90 #define RKVDEC_REG_CLR_CACHE0_BASE	0x510
91 #define RKVDEC_REG_CLR_CACHE1_BASE	0x550
92 #define RKVDEC_REG_CLR_CACHE2_BASE	0x590
93 
94 #define RKVDEC_CACHE_PERMIT_CACHEABLE_ACCESS	BIT(0)
95 #define RKVDEC_CACHE_PERMIT_READ_ALLOCATE	BIT(1)
96 #define RKVDEC_CACHE_LINE_SIZE_64_BYTES		BIT(4)
97 
98 #define to_rkvdec2_task(task)		\
99 		container_of(task, struct rkvdec2_task, mpp_task)
100 #define to_rkvdec2_dev(dev)		\
101 		container_of(dev, struct rkvdec2_dev, mpp)
102 
103 enum RKVDEC_FMT {
104 	RKVDEC_FMT_H265D	= 0,
105 	RKVDEC_FMT_H264D	= 1,
106 	RKVDEC_FMT_VP9D		= 2,
107 	RKVDEC_FMT_AVS2		= 3,
108 };
109 
110 #define RKVDEC_MAX_RCB_NUM		(16)
111 
112 struct rcb_info_elem {
113 	u32 index;
114 	u32 size;
115 };
116 
117 struct rkvdec2_rcb_info {
118 	u32 cnt;
119 	struct rcb_info_elem elem[RKVDEC_MAX_RCB_NUM];
120 };
121 
122 struct rkvdec2_task {
123 	struct mpp_task mpp_task;
124 
125 	enum MPP_CLOCK_MODE clk_mode;
126 	u32 reg[RKVDEC_REG_NUM];
127 	struct reg_offset_info off_inf;
128 
129 	/* perf sel data back */
130 	u32 reg_sel[RKVDEC_PERF_SEL_NUM];
131 
132 	u32 strm_addr;
133 	u32 irq_status;
134 	/* req for current task */
135 	u32 w_req_cnt;
136 	struct mpp_request w_reqs[MPP_MAX_MSG_NUM];
137 	u32 r_req_cnt;
138 	struct mpp_request r_reqs[MPP_MAX_MSG_NUM];
139 	/* image info */
140 	u32 width;
141 	u32 height;
142 	u32 pixels;
143 
144 	/* task index for link table rnunning list */
145 	int slot_idx;
146 	u32 need_hack;
147 
148 	/* event for task wait timeout or session timeout */
149 	wait_queue_head_t wait;
150 	/* link table DMA buffer */
151 	struct mpp_dma_buffer *table;
152 };
153 
154 struct rkvdec2_session_priv {
155 	/* codec info from user */
156 	struct {
157 		/* show mode */
158 		u32 flag;
159 		/* item data */
160 		u64 val;
161 	} codec_info[DEC_INFO_BUTT];
162 	/* rcb_info for sram */
163 	struct rkvdec2_rcb_info rcb_inf;
164 };
165 
166 struct rkvdec2_dev {
167 	struct mpp_dev mpp;
168 	/* sip smc reset lock */
169 	struct mutex sip_reset_lock;
170 
171 	struct mpp_clk_info aclk_info;
172 	struct mpp_clk_info hclk_info;
173 	struct mpp_clk_info core_clk_info;
174 	struct mpp_clk_info cabac_clk_info;
175 	struct mpp_clk_info hevc_cabac_clk_info;
176 	u32 default_max_load;
177 #ifdef CONFIG_ROCKCHIP_MPP_PROC_FS
178 	struct proc_dir_entry *procfs;
179 #endif
180 	struct reset_control *rst_a;
181 	struct reset_control *rst_h;
182 	struct reset_control *rst_niu_a;
183 	struct reset_control *rst_niu_h;
184 	struct reset_control *rst_core;
185 	struct reset_control *rst_cabac;
186 	struct reset_control *rst_hevc_cabac;
187 
188 	/* internal rcb-memory */
189 	u32 sram_size;
190 	u32 rcb_size;
191 	dma_addr_t rcb_iova;
192 	struct page *rcb_page;
193 	u32 rcb_min_width;
194 
195 	/* for link mode */
196 	struct rkvdec_link_dev *link_dec;
197 	struct mpp_dma_buffer *fix;
198 
199 	/* for ccu link mode */
200 	struct rkvdec2_ccu *ccu;
201 	u32 core_mask;
202 	bool disable_work;
203 	u32 task_index;
204 };
205 
206 int mpp_set_rcbbuf(struct mpp_dev *mpp, struct mpp_session *session,
207 		   struct mpp_task *task);
208 int rkvdec2_task_init(struct mpp_dev *mpp, struct mpp_session *session,
209 		      struct rkvdec2_task *task, struct mpp_task_msgs *msgs);
210 void *rkvdec2_alloc_task(struct mpp_session *session,
211 			 struct mpp_task_msgs *msgs);
212 int rkvdec2_free_task(struct mpp_session *session, struct mpp_task *mpp_task);
213 
214 int rkvdec2_free_session(struct mpp_session *session);
215 
216 int rkvdec2_result(struct mpp_dev *mpp, struct mpp_task *mpp_task,
217 		   struct mpp_task_msgs *msgs);
218 int rkvdec2_reset(struct mpp_dev *mpp);
219 
220 #endif
221