forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/video/rockchip/mpp/mpp_rkvdec2_link.h
....@@ -10,9 +10,21 @@
1010
1111 #include "mpp_rkvdec2.h"
1212
13
+#define RKVDEC_REG_IMPORTANT_BASE 0x2c
14
+#define RKVDEC_REG_IMPORTANT_INDEX 11
15
+#define RKVDEC_SOFTREST_EN BIT(20)
16
+
1317 #define RKVDEC_REG_SECOND_EN_BASE 0x30
1418 #define RKVDEC_REG_SECOND_EN_INDEX 12
1519 #define RKVDEC_WAIT_RESET_EN BIT(7)
20
+
21
+#define RKVDEC_REG_EN_MODE_SET 13
22
+
23
+#define RKVDEC_REG_DEBUG_INT_BASE 0x440
24
+#define RKVDEC_REG_DEBUG_INT_INDEX 272
25
+#define RKVDEC_BIT_BUS_IDLE BIT(0)
26
+
27
+#define RKVDEC_REG_TIMEOUT_THRESHOLD 32
1628
1729 /* define for link hardware */
1830 #define RKVDEC_LINK_ADD_CFG_NUM 1
....@@ -21,6 +33,8 @@
2133 #define RKVDEC_LINK_BIT_IRQ_DIS BIT(2)
2234 #define RKVDEC_LINK_BIT_IRQ BIT(8)
2335 #define RKVDEC_LINK_BIT_IRQ_RAW BIT(9)
36
+#define RKVDEC_LINK_BIT_CORE_WORK_MODE BIT(16)
37
+#define RKVDEC_LINK_BIT_CCU_WORK_MODE BIT(17)
2438
2539 #define RKVDEC_LINK_CFG_ADDR_BASE 0x004
2640
....@@ -43,6 +57,76 @@
4357
4458 #define RKVDEC_LINK_REG_CYCLE_CNT 179
4559
60
+/* define for ccu link hardware */
61
+#define RKVDEC_CCU_CTRL_BASE 0x000
62
+#define RKVDEC_CCU_BIT_AUTOGATE BIT(0)
63
+#define RKVDEC_CCU_BIT_FIX_RCB BIT(20)
64
+
65
+#define RKVDEC_CCU_CFG_ADDR_BASE 0x004
66
+#define RKVDEC_CCU_LINK_MODE_BASE 0x008
67
+#define RKVDEC_CCU_BIT_ADD_MODE BIT(31)
68
+
69
+#define RKVDEC_CCU_CFG_DONE_BASE 0x00c
70
+#define RKVDEC_CCU_BIT_CFG_DONE BIT(0)
71
+
72
+#define RKVDEC_CCU_DEC_NUM_BASE 0x010
73
+#define RKVDEC_CCU_TOTAL_NUM_BASE 0x014
74
+
75
+#define RKVDEC_CCU_WORK_BASE 0x018
76
+#define RKVDEC_CCU_BIT_WORK_EN BIT(0)
77
+
78
+#define RKVDEC_CCU_SEND_NUM_BASE 0x024
79
+#define RKVDEC_CCU_WORK_MODE_BASE 0x040
80
+#define RKVDEC_CCU_BIT_WORK_MODE BIT(0)
81
+
82
+#define RKVDEC_CCU_CORE_WORK_BASE 0x044
83
+#define RKVDEC_CCU_CORE_STA_BASE 0x048
84
+#define RKVDEC_CCU_CORE_IDLE_BASE 0x04c
85
+#define RKVDEC_CCU_CORE_ERR_BASE 0x054
86
+
87
+#define RKVDEC_CCU_CORE_RW_MASK 0x30000
88
+
89
+#define RKVDEC_MAX_WRITE_PART 6
90
+#define RKVDEC_MAX_READ_PART 2
91
+
92
+struct rkvdec_link_part {
93
+ /* register offset of table buffer */
94
+ u32 tb_reg_off;
95
+ /* start idx of task register */
96
+ u32 reg_start;
97
+ /* number of task register */
98
+ u32 reg_num;
99
+};
100
+
101
+struct rkvdec_link_status {
102
+ u32 dec_num_mask;
103
+ u32 err_flag_base;
104
+ u32 err_flag_bit;
105
+};
106
+
107
+struct rkvdec_link_info {
108
+ dma_addr_t iova;
109
+ /* total register for link table buffer */
110
+ u32 tb_reg_num;
111
+ /* next link table addr in table buffer */
112
+ u32 tb_reg_next;
113
+ /* current read back addr in table buffer */
114
+ u32 tb_reg_r;
115
+ /* secondary enable in table buffer */
116
+ u32 tb_reg_second_en;
117
+ u32 part_w_num;
118
+ u32 part_r_num;
119
+
120
+ struct rkvdec_link_part part_w[RKVDEC_MAX_WRITE_PART];
121
+ struct rkvdec_link_part part_r[RKVDEC_MAX_READ_PART];
122
+
123
+ /* interrupt read back in table buffer */
124
+ u32 tb_reg_int;
125
+ u32 tb_reg_cycle;
126
+ bool hack_setup;
127
+ struct rkvdec_link_status reg_status;
128
+};
129
+
46130 struct rkvdec_link_dev {
47131 struct device *dev;
48132 struct mpp_dev *mpp;
....@@ -56,35 +140,16 @@
56140 u32 decoded;
57141 u32 total;
58142 u32 error;
59
- u32 stuff_err;
60
- u32 stuff_total;
61
- u32 stuff_on_error;
143
+ u32 hack_task_running;
62144
63145 struct rkvdec_link_info *info;
64146 struct mpp_dma_buffer *table;
65147 u32 link_node_size;
66148 u32 link_reg_count;
67149
68
- struct mpp_task **tasks_hw;
69
- u32 task_capacity;
70
- s32 task_total;
71
- s32 task_decoded;
72
- s32 task_size;
73
- s32 task_count;
74
- s32 task_write;
75
- s32 task_read;
76
- s32 task_send;
77
- s32 task_recv;
78
-
79150 /* taskqueue variables */
80151 u32 task_running;
81
- u32 task_prepared;
82
- s32 task_to_run;
83
- u32 task_on_timeout;
84
-
85
- /* taskqueue trigger variables */
86
- u32 task_irq;
87
- u32 task_irq_prev;
152
+ atomic_t task_pending;
88153 /* timeout can be trigger in different thread so atomic is needed */
89154 atomic_t task_timeout;
90155 u32 task_timeout_prev;
....@@ -99,10 +164,44 @@
99164 u32 task_cnt;
100165 u64 stuff_cycle_sum;
101166 u32 stuff_cnt;
167
+
168
+ /* link info */
169
+ u32 task_capacity;
170
+ struct mpp_dma_buffer *table_array;
171
+ struct list_head unused_list;
172
+ struct list_head used_list;
102173 };
103174
104
-extern struct rkvdec_link_info rkvdec_link_rk3568_hw_info;
175
+enum RKVDEC2_CCU_MODE {
176
+ RKVDEC2_CCU_MODE_NULL = 0,
177
+ RKVDEC2_CCU_TASK_SOFT = 1,
178
+ RKVDEC2_CCU_TASK_HARD = 2,
179
+ RKVDEC2_CCU_MODE_BUTT,
180
+};
181
+
182
+struct rkvdec2_ccu {
183
+ struct device *dev;
184
+ /* register base */
185
+ void __iomem *reg_base;
186
+
187
+ atomic_t power_enabled;
188
+ struct mpp_clk_info aclk_info;
189
+#ifdef CONFIG_ROCKCHIP_MPP_PROC_FS
190
+ struct proc_dir_entry *procfs;
191
+#endif
192
+ struct reset_control *rst_a;
193
+ enum RKVDEC2_CCU_MODE ccu_mode;
194
+ u32 ccu_core_work_mode;
195
+
196
+ struct mpp_dma_buffer *table_array;
197
+ struct list_head unused_list;
198
+ struct list_head used_list;
199
+ u32 timeout_flag;
200
+};
201
+
202
+extern struct rkvdec_link_info rkvdec_link_rk356x_hw_info;
105203 extern struct rkvdec_link_info rkvdec_link_v2_hw_info;
204
+extern struct rkvdec_link_info rkvdec_link_vdpu382_hw_info;
106205
107206 int rkvdec_link_dump(struct mpp_dev *mpp);
108207
....@@ -118,4 +217,22 @@
118217 void rkvdec2_link_worker(struct kthread_work *work_s);
119218 void rkvdec2_link_session_deinit(struct mpp_session *session);
120219
220
+/* for ccu link */
221
+int rkvdec2_attach_ccu(struct device *dev, struct rkvdec2_dev *dec);
222
+int rkvdec2_ccu_link_init(struct platform_device *pdev, struct rkvdec2_dev *dec);
223
+void *rkvdec2_ccu_alloc_task(struct mpp_session *session, struct mpp_task_msgs *msgs);
224
+int rkvdec2_soft_ccu_iommu_fault_handle(struct iommu_domain *iommu,
225
+ struct device *iommu_dev,
226
+ unsigned long iova, int status, void *arg);
227
+irqreturn_t rkvdec2_soft_ccu_irq(int irq, void *param);
228
+void rkvdec2_soft_ccu_worker(struct kthread_work *work_s);
229
+
230
+int rkvdec2_ccu_alloc_table(struct rkvdec2_dev *dec,
231
+ struct rkvdec_link_dev *link_dec);
232
+irqreturn_t rkvdec2_hard_ccu_irq(int irq, void *param);
233
+void rkvdec2_hard_ccu_worker(struct kthread_work *work_s);
234
+int rkvdec2_hard_ccu_iommu_fault_handle(struct iommu_domain *iommu,
235
+ struct device *iommu_dev,
236
+ unsigned long iova, int status, void *arg);
237
+
121238 #endif