blob: a466b2a8d2812f9fa3fcd3f051318af003a3274b
1 | /* |
2 | * drivers/amlogic/amports/vmpeg12.c |
3 | * |
4 | * Copyright (C) 2015 Amlogic, Inc. All rights reserved. |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
14 | * more details. |
15 | * |
16 | */ |
17 | |
18 | #include <linux/kernel.h> |
19 | #include <linux/types.h> |
20 | #include <linux/errno.h> |
21 | #include <linux/interrupt.h> |
22 | #include <linux/timer.h> |
23 | #include <linux/kfifo.h> |
24 | #include <linux/platform_device.h> |
25 | #include <linux/random.h> |
26 | #include <linux/dma-mapping.h> |
27 | #include <linux/slab.h> |
28 | #include <linux/delay.h> |
29 | |
30 | #include <linux/amlogic/media/frame_sync/ptsserv.h> |
31 | #include <linux/amlogic/media/utils/amstream.h> |
32 | #include <linux/amlogic/media/canvas/canvas.h> |
33 | #include <linux/amlogic/media/vfm/vframe.h> |
34 | #include <linux/amlogic/media/vfm/vframe_provider.h> |
35 | #include <linux/amlogic/media/vfm/vframe_receiver.h> |
36 | #include <linux/amlogic/tee.h> |
37 | |
38 | #include <linux/amlogic/media/utils/vdec_reg.h> |
39 | #include <linux/amlogic/media/registers/register.h> |
40 | #include "../../../stream_input/amports/amports_priv.h" |
41 | |
42 | #include "../utils/vdec_input.h" |
43 | #include "../utils/vdec.h" |
44 | #include "../utils/amvdec.h" |
45 | #include "../utils/decoder_mmu_box.h" |
46 | #include "../utils/decoder_bmmu_box.h" |
47 | #include <linux/amlogic/media/codec_mm/codec_mm.h> |
48 | #include <linux/amlogic/media/codec_mm/configs.h> |
49 | #include "../utils/firmware.h" |
50 | |
51 | |
52 | #define MEM_NAME "codec_mmpeg12" |
53 | #define CHECK_INTERVAL (HZ/100) |
54 | |
55 | #define DRIVER_NAME "ammvdec_mpeg12" |
56 | #define MODULE_NAME "ammvdec_mpeg12" |
57 | #define MREG_REF0 AV_SCRATCH_2 |
58 | #define MREG_REF1 AV_SCRATCH_3 |
59 | /* protocol registers */ |
60 | #define MREG_SEQ_INFO AV_SCRATCH_4 |
61 | #define MREG_PIC_INFO AV_SCRATCH_5 |
62 | #define MREG_PIC_WIDTH AV_SCRATCH_6 |
63 | #define MREG_PIC_HEIGHT AV_SCRATCH_7 |
64 | #define MREG_INPUT AV_SCRATCH_8 /*input_type*/ |
65 | #define MREG_BUFFEROUT AV_SCRATCH_9 /*FROM_AMRISC_REG*/ |
66 | |
67 | #define MREG_CMD AV_SCRATCH_A |
68 | #define MREG_CO_MV_START AV_SCRATCH_B |
69 | #define MREG_ERROR_COUNT AV_SCRATCH_C |
70 | #define MREG_FRAME_OFFSET AV_SCRATCH_D |
71 | #define MREG_WAIT_BUFFER AV_SCRATCH_E |
72 | #define MREG_FATAL_ERROR AV_SCRATCH_F |
73 | |
74 | #define GET_SLICE_TYPE(type) ("IPB##"[((type&PICINFO_TYPE_MASK)>>16)&0x3]) |
75 | #define PICINFO_ERROR 0x80000000 |
76 | #define PICINFO_TYPE_MASK 0x00030000 |
77 | #define PICINFO_TYPE_I 0x00000000 |
78 | #define PICINFO_TYPE_P 0x00010000 |
79 | #define PICINFO_TYPE_B 0x00020000 |
80 | #define PICINFO_PROG 0x8000 |
81 | #define PICINFO_RPT_FIRST 0x4000 |
82 | #define PICINFO_TOP_FIRST 0x2000 |
83 | #define PICINFO_FRAME 0x1000 |
84 | |
85 | #define TOP_FIELD 0x1000 |
86 | #define BOTTOM_FIELD 0x2000 |
87 | #define FRAME_PICTURE 0x3000 |
88 | #define FRAME_PICTURE_MASK 0x3000 |
89 | |
90 | #define SEQINFO_EXT_AVAILABLE 0x80000000 |
91 | #define SEQINFO_PROG 0x00010000 |
92 | #define CCBUF_SIZE (5*1024) |
93 | |
94 | #define VF_POOL_SIZE 32 |
95 | #define DECODE_BUFFER_NUM_MAX 8 |
96 | #define PUT_INTERVAL (HZ/100) |
97 | #define WORKSPACE_SIZE (4*SZ_64K) /*swap&ccbuf&matirx&MV*/ |
98 | #define CTX_LMEM_SWAP_OFFSET 0 |
99 | #define CTX_CCBUF_OFFSET 0x800 |
100 | #define CTX_QUANT_MATRIX_OFFSET (CTX_CCBUF_OFFSET + 5*1024) |
101 | #define CTX_CO_MV_OFFSET (CTX_QUANT_MATRIX_OFFSET + 1*1024) |
102 | #define CTX_DECBUF_OFFSET (CTX_CO_MV_OFFSET + 0x11000) |
103 | |
104 | #define MAX_BMMU_BUFFER_NUM (DECODE_BUFFER_NUM_MAX + 1) |
105 | #define DEFAULT_MEM_SIZE (32*SZ_1M) |
106 | static u32 buf_size = 32 * 1024 * 1024; |
107 | static int pre_decode_buf_level = 0x800; |
108 | static u32 dec_control; |
109 | static u32 error_frame_skip_level = 2; |
110 | static u32 stat; |
111 | static u32 udebug_flag; |
112 | static unsigned int radr; |
113 | static unsigned int rval; |
114 | |
115 | static u32 without_display_mode; |
116 | |
117 | #define VMPEG12_DEV_NUM 9 |
118 | static unsigned int max_decode_instance_num = VMPEG12_DEV_NUM; |
119 | static unsigned int max_process_time[VMPEG12_DEV_NUM]; |
120 | static unsigned int decode_timeout_val = 100; |
121 | #define INCPTR(p) ptr_atomic_wrap_inc(&p) |
122 | |
123 | #define DEC_CONTROL_FLAG_FORCE_2500_720_576_INTERLACE 0x0002 |
124 | #define DEC_CONTROL_FLAG_FORCE_3000_704_480_INTERLACE 0x0004 |
125 | #define DEC_CONTROL_FLAG_FORCE_2500_704_576_INTERLACE 0x0008 |
126 | #define DEC_CONTROL_FLAG_FORCE_2500_544_576_INTERLACE 0x0010 |
127 | #define DEC_CONTROL_FLAG_FORCE_2500_480_576_INTERLACE 0x0020 |
128 | #define DEC_CONTROL_INTERNAL_MASK 0x0fff |
129 | #define DEC_CONTROL_FLAG_FORCE_SEQ_INTERLACE 0x1000 |
130 | |
131 | #define INTERLACE_SEQ_ALWAYS |
132 | |
133 | #if 1/* MESON_CPU_TYPE >= MESON_CPU_TYPE_MESON6 */ |
134 | #define NV21 |
135 | #endif |
136 | |
137 | #define AGAIN_HAS_THRESHOLD |
138 | |
139 | #ifdef AGAIN_HAS_THRESHOLD |
140 | u32 again_threshold; |
141 | #endif |
142 | |
143 | /* |
144 | #define DUMP_USER_DATA |
145 | */ |
146 | |
147 | enum { |
148 | FRAME_REPEAT_TOP, |
149 | FRAME_REPEAT_BOT, |
150 | FRAME_REPEAT_NONE |
151 | }; |
152 | #define DEC_RESULT_NONE 0 |
153 | #define DEC_RESULT_DONE 1 |
154 | #define DEC_RESULT_AGAIN 2 |
155 | #define DEC_RESULT_ERROR 3 |
156 | #define DEC_RESULT_FORCE_EXIT 4 |
157 | #define DEC_RESULT_EOS 5 |
158 | #define DEC_RESULT_GET_DATA 6 |
159 | #define DEC_RESULT_GET_DATA_RETRY 7 |
160 | |
161 | #define DEC_DECODE_TIMEOUT 0x21 |
162 | #define DECODE_ID(hw) (hw_to_vdec(hw)->id) |
163 | #define DECODE_STOP_POS AV_SCRATCH_K |
164 | |
165 | static struct vframe_s *vmpeg_vf_peek(void *); |
166 | static struct vframe_s *vmpeg_vf_get(void *); |
167 | static void vmpeg_vf_put(struct vframe_s *, void *); |
168 | static int vmpeg_vf_states(struct vframe_states *states, void *); |
169 | static int vmpeg_event_cb(int type, void *data, void *private_data); |
170 | |
171 | struct mmpeg2_userdata_record_t { |
172 | struct userdata_meta_info_t meta_info; |
173 | u32 rec_start; |
174 | u32 rec_len; |
175 | }; |
176 | |
177 | #define USERDATA_FIFO_NUM 256 |
178 | #define MAX_FREE_USERDATA_NODES 5 |
179 | |
180 | struct mmpeg2_userdata_info_t { |
181 | struct mmpeg2_userdata_record_t records[USERDATA_FIFO_NUM]; |
182 | u8 *data_buf; |
183 | u8 *data_buf_end; |
184 | u32 buf_len; |
185 | u32 read_index; |
186 | u32 write_index; |
187 | u32 last_wp; |
188 | }; |
189 | #define MAX_UD_RECORDS 5 |
190 | |
191 | struct pic_info_t { |
192 | u32 buffer_info; |
193 | u32 index; |
194 | u32 offset; |
195 | u32 width; |
196 | u32 height; |
197 | u32 pts; |
198 | u64 pts64; |
199 | bool pts_valid; |
200 | }; |
201 | |
202 | struct vdec_mpeg12_hw_s { |
203 | spinlock_t lock; |
204 | struct platform_device *platform_dev; |
205 | DECLARE_KFIFO(newframe_q, struct vframe_s *, VF_POOL_SIZE); |
206 | DECLARE_KFIFO(display_q, struct vframe_s *, VF_POOL_SIZE); |
207 | struct vframe_s vfpool[VF_POOL_SIZE]; |
208 | s32 vfbuf_use[DECODE_BUFFER_NUM_MAX]; |
209 | u32 frame_width; |
210 | u32 frame_height; |
211 | u32 frame_dur; |
212 | u32 frame_prog; |
213 | u32 seqinfo; |
214 | u32 ctx_valid; |
215 | u32 dec_control; |
216 | void *mm_blk_handle; |
217 | struct vframe_chunk_s *chunk; |
218 | u32 stat; |
219 | u8 init_flag; |
220 | unsigned long buf_start; |
221 | u32 buf_size; |
222 | u32 reg_pic_width; |
223 | u32 reg_pic_height; |
224 | u32 reg_mpeg1_2_reg; |
225 | u32 reg_pic_head_info; |
226 | u32 reg_f_code_reg; |
227 | u32 reg_slice_ver_pos_pic_type; |
228 | u32 reg_vcop_ctrl_reg; |
229 | u32 reg_mb_info; |
230 | u32 reg_signal_type; |
231 | u32 dec_num; |
232 | u32 disp_num; |
233 | struct timer_list check_timer; |
234 | u32 decode_timeout_count; |
235 | unsigned long int start_process_time; |
236 | u32 last_vld_level; |
237 | u32 eos; |
238 | struct pic_info_t pics[DECODE_BUFFER_NUM_MAX]; |
239 | u32 canvas_spec[DECODE_BUFFER_NUM_MAX]; |
240 | u64 lastpts64; |
241 | u32 last_chunk_pts; |
242 | struct canvas_config_s canvas_config[DECODE_BUFFER_NUM_MAX][2]; |
243 | struct dec_sysinfo vmpeg12_amstream_dec_info; |
244 | |
245 | s32 refs[2]; |
246 | int dec_result; |
247 | struct work_struct work; |
248 | struct work_struct timeout_work; |
249 | struct work_struct notify_work; |
250 | void (*vdec_cb)(struct vdec_s *, void *); |
251 | void *vdec_cb_arg; |
252 | unsigned long ccbuf_phyAddress; |
253 | void *ccbuf_phyAddress_virt; |
254 | unsigned long ccbuf_phyAddress_is_remaped_nocache; |
255 | u32 frame_rpt_state; |
256 | /* for error handling */ |
257 | s32 frame_force_skip_flag; |
258 | s32 error_frame_skip_level; |
259 | s32 wait_buffer_counter; |
260 | u32 first_i_frame_ready; |
261 | u32 run_count; |
262 | u32 not_run_ready; |
263 | u32 input_empty; |
264 | u32 put_num; |
265 | u32 peek_num; |
266 | u32 get_num; |
267 | u32 drop_frame_count; |
268 | u32 buffer_not_ready; |
269 | u32 ratio_control; |
270 | int frameinfo_enable; |
271 | struct firmware_s *fw; |
272 | u32 canvas_mode; |
273 | #ifdef AGAIN_HAS_THRESHOLD |
274 | u32 pre_parser_wr_ptr; |
275 | u8 next_again_flag; |
276 | #endif |
277 | struct work_struct userdata_push_work; |
278 | struct mutex userdata_mutex; |
279 | struct mmpeg2_userdata_info_t userdata_info; |
280 | struct mmpeg2_userdata_record_t ud_record[MAX_UD_RECORDS]; |
281 | int cur_ud_idx; |
282 | u8 *user_data_buffer; |
283 | int wait_for_udr_send; |
284 | u32 ucode_cc_last_wp; |
285 | u32 notify_ucode_cc_last_wp; |
286 | u32 notify_data_cc_last_wp; |
287 | u32 userdata_wp_ctx; |
288 | #ifdef DUMP_USER_DATA |
289 | #define MAX_USER_DATA_SIZE 1572864 |
290 | void *user_data_dump_buf; |
291 | unsigned char *pdump_buf_cur_start; |
292 | int total_len; |
293 | int bskip; |
294 | int n_userdata_id; |
295 | u32 reference[MAX_UD_RECORDS]; |
296 | #endif |
297 | int tvp_flag; |
298 | }; |
299 | static void vmpeg12_local_init(struct vdec_mpeg12_hw_s *hw); |
300 | static int vmpeg12_hw_ctx_restore(struct vdec_mpeg12_hw_s *hw); |
301 | static void reset_process_time(struct vdec_mpeg12_hw_s *hw); |
302 | static struct vdec_info gvs; |
303 | static int debug_enable; |
304 | /*static struct work_struct userdata_push_work;*/ |
305 | #undef pr_info |
306 | #define pr_info printk |
307 | unsigned int mpeg12_debug_mask = 0xff; |
308 | /*static int counter_max = 5;*/ |
309 | |
310 | #define PRINT_FLAG_ERROR 0x0 |
311 | #define PRINT_FLAG_RUN_FLOW 0X0001 |
312 | #define PRINT_FLAG_TIMEINFO 0x0002 |
313 | #define PRINT_FLAG_UCODE_DETAIL 0x0004 |
314 | #define PRINT_FLAG_VLD_DETAIL 0x0008 |
315 | #define PRINT_FLAG_DEC_DETAIL 0x0010 |
316 | #define PRINT_FLAG_BUFFER_DETAIL 0x0020 |
317 | #define PRINT_FLAG_RESTORE 0x0040 |
318 | #define PRINT_FRAME_NUM 0x0080 |
319 | #define PRINT_FLAG_FORCE_DONE 0x0100 |
320 | #define PRINT_FLAG_COUNTER 0X0200 |
321 | #define PRINT_FRAMEBASE_DATA 0x0400 |
322 | #define PRINT_FLAG_VDEC_STATUS 0x0800 |
323 | #define PRINT_FLAG_PARA_DATA 0x1000 |
324 | #define PRINT_FLAG_USERDATA_DETAIL 0x2000 |
325 | #define PRINT_FLAG_TIMEOUT_STATUS 0x4000 |
326 | |
327 | |
328 | |
329 | int debug_print(int index, int debug_flag, const char *fmt, ...) |
330 | { |
331 | if (((debug_enable & debug_flag) && |
332 | ((1 << index) & mpeg12_debug_mask)) |
333 | || (debug_flag == PRINT_FLAG_ERROR)) { |
334 | unsigned char buf[512]; |
335 | int len = 0; |
336 | va_list args; |
337 | va_start(args, fmt); |
338 | len = sprintf(buf, "%d: ", index); |
339 | vsnprintf(buf + len, 512-len, fmt, args); |
340 | pr_info("%s", buf); |
341 | va_end(args); |
342 | } |
343 | return 0; |
344 | } |
345 | |
346 | |
347 | /*static bool is_reset;*/ |
348 | #define PROVIDER_NAME "vdec.mpeg12" |
349 | static const struct vframe_operations_s vf_provider_ops = { |
350 | .peek = vmpeg_vf_peek, |
351 | .get = vmpeg_vf_get, |
352 | .put = vmpeg_vf_put, |
353 | .event_cb = vmpeg_event_cb, |
354 | .vf_states = vmpeg_vf_states, |
355 | }; |
356 | |
357 | |
358 | static const u32 frame_rate_tab[16] = { |
359 | 96000 / 30, 96000000 / 23976, 96000 / 24, 96000 / 25, |
360 | 9600000 / 2997, 96000 / 30, 96000 / 50, 9600000 / 5994, |
361 | 96000 / 60, |
362 | /* > 8 reserved, use 24 */ |
363 | 96000 / 24, 96000 / 24, 96000 / 24, 96000 / 24, |
364 | 96000 / 24, 96000 / 24, 96000 / 24 |
365 | }; |
366 | |
367 | |
368 | static u32 find_buffer(struct vdec_mpeg12_hw_s *hw) |
369 | { |
370 | u32 i; |
371 | |
372 | for (i = 0; i < DECODE_BUFFER_NUM_MAX; i++) { |
373 | if (hw->vfbuf_use[i] == 0) |
374 | return i; |
375 | } |
376 | |
377 | return DECODE_BUFFER_NUM_MAX; |
378 | } |
379 | |
380 | static u32 spec_to_index(struct vdec_mpeg12_hw_s *hw, u32 spec) |
381 | { |
382 | u32 i; |
383 | |
384 | for (i = 0; i < DECODE_BUFFER_NUM_MAX; i++) { |
385 | if (hw->canvas_spec[i] == spec) |
386 | return i; |
387 | } |
388 | |
389 | return DECODE_BUFFER_NUM_MAX; |
390 | } |
391 | |
392 | static void set_frame_info(struct vdec_mpeg12_hw_s *hw, struct vframe_s *vf) |
393 | { |
394 | u32 ar_bits; |
395 | u32 buffer_index = vf->index; |
396 | |
397 | vf->width = hw->pics[buffer_index].width; |
398 | vf->height = hw->pics[buffer_index].height; |
399 | |
400 | if (hw->frame_dur > 0) |
401 | vf->duration = hw->frame_dur; |
402 | else { |
403 | vf->duration = hw->frame_dur = |
404 | frame_rate_tab[(READ_VREG(MREG_SEQ_INFO) >> 4) & 0xf]; |
405 | vdec_schedule_work(&hw->notify_work); |
406 | } |
407 | |
408 | ar_bits = READ_VREG(MREG_SEQ_INFO) & 0xf; |
409 | |
410 | if (ar_bits == 0x2) |
411 | vf->ratio_control = 0xc0 << DISP_RATIO_ASPECT_RATIO_BIT; |
412 | |
413 | else if (ar_bits == 0x3) |
414 | vf->ratio_control = 0x90 << DISP_RATIO_ASPECT_RATIO_BIT; |
415 | |
416 | else if (ar_bits == 0x4) |
417 | vf->ratio_control = 0x74 << DISP_RATIO_ASPECT_RATIO_BIT; |
418 | else |
419 | vf->ratio_control = 0; |
420 | |
421 | hw->ratio_control = vf->ratio_control; |
422 | |
423 | vf->canvas0Addr = vf->canvas1Addr = -1; |
424 | vf->plane_num = 2; |
425 | |
426 | vf->canvas0_config[0] = hw->canvas_config[buffer_index][0]; |
427 | vf->canvas0_config[1] = hw->canvas_config[buffer_index][1]; |
428 | |
429 | vf->canvas1_config[0] = hw->canvas_config[buffer_index][0]; |
430 | vf->canvas1_config[1] = hw->canvas_config[buffer_index][1]; |
431 | |
432 | debug_print(DECODE_ID(hw), PRINT_FLAG_PARA_DATA, |
433 | "mpeg2dec: w(%d), h(%d), dur(%d), dur-ES(%d)\n", |
434 | hw->frame_width, hw->frame_height, hw->frame_dur, |
435 | frame_rate_tab[(READ_VREG(MREG_SEQ_INFO) >> 4) & 0xf]); |
436 | } |
437 | |
438 | static bool error_skip(struct vdec_mpeg12_hw_s *hw, |
439 | u32 info, struct vframe_s *vf) |
440 | { |
441 | if (hw->error_frame_skip_level) { |
442 | /* skip error frame */ |
443 | if ((info & PICINFO_ERROR) || (hw->frame_force_skip_flag)) { |
444 | if ((info & PICINFO_ERROR) == 0) { |
445 | if ((info & PICINFO_TYPE_MASK) == |
446 | PICINFO_TYPE_I) |
447 | hw->frame_force_skip_flag = 0; |
448 | } else { |
449 | if (hw->error_frame_skip_level >= 2) |
450 | hw->frame_force_skip_flag = 1; |
451 | } |
452 | if ((info & PICINFO_ERROR) |
453 | || (hw->frame_force_skip_flag)) |
454 | return true; |
455 | } |
456 | } |
457 | return false; |
458 | } |
459 | |
460 | static inline void vmpeg12_save_hw_context(struct vdec_mpeg12_hw_s *hw, u32 reg) |
461 | { |
462 | if (reg == 3) { |
463 | hw->ctx_valid = 0; |
464 | //pr_info("%s, hw->userdata_wp_ctx %d\n", __func__, hw->userdata_wp_ctx); |
465 | } else { |
466 | hw->seqinfo = READ_VREG(MREG_SEQ_INFO); |
467 | hw->reg_pic_width = READ_VREG(MREG_PIC_WIDTH); |
468 | hw->reg_pic_height = READ_VREG(MREG_PIC_HEIGHT); |
469 | hw->reg_mpeg1_2_reg = READ_VREG(MPEG1_2_REG); |
470 | hw->reg_pic_head_info = READ_VREG(PIC_HEAD_INFO); |
471 | hw->reg_f_code_reg = READ_VREG(F_CODE_REG); |
472 | hw->reg_slice_ver_pos_pic_type = READ_VREG(SLICE_VER_POS_PIC_TYPE); |
473 | hw->reg_vcop_ctrl_reg = READ_VREG(VCOP_CTRL_REG); |
474 | hw->reg_mb_info = READ_VREG(MB_INFO); |
475 | hw->reg_signal_type = READ_VREG(AV_SCRATCH_H); |
476 | debug_print(DECODE_ID(hw), PRINT_FLAG_PARA_DATA, |
477 | "signal_type = %x", hw->reg_signal_type); |
478 | hw->ctx_valid = 1; |
479 | } |
480 | } |
481 | |
482 | static void vmmpeg2_reset_udr_mgr(struct vdec_mpeg12_hw_s *hw) |
483 | { |
484 | hw->wait_for_udr_send = 0; |
485 | hw->cur_ud_idx = 0; |
486 | memset(&hw->ud_record, 0, sizeof(hw->ud_record)); |
487 | } |
488 | |
489 | static void vmmpeg2_crate_userdata_manager( |
490 | struct vdec_mpeg12_hw_s *hw, |
491 | u8 *userdata_buf, |
492 | int buf_len) |
493 | { |
494 | if (hw) { |
495 | mutex_init(&hw->userdata_mutex); |
496 | |
497 | memset(&hw->userdata_info, 0, |
498 | sizeof(struct mmpeg2_userdata_info_t)); |
499 | hw->userdata_info.data_buf = userdata_buf; |
500 | hw->userdata_info.buf_len = buf_len; |
501 | hw->userdata_info.data_buf_end = userdata_buf + buf_len; |
502 | hw->userdata_wp_ctx = 0; |
503 | |
504 | vmmpeg2_reset_udr_mgr(hw); |
505 | } |
506 | } |
507 | |
508 | static void vmmpeg2_destroy_userdata_manager(struct vdec_mpeg12_hw_s *hw) |
509 | { |
510 | if (hw) |
511 | memset(&hw->userdata_info, |
512 | 0, |
513 | sizeof(struct mmpeg2_userdata_info_t)); |
514 | } |
515 | |
516 | static void aml_swap_data(uint8_t *user_data, int ud_size) |
517 | { |
518 | int swap_blocks, i, j, k, m; |
519 | unsigned char c_temp; |
520 | |
521 | /* swap byte order */ |
522 | swap_blocks = ud_size / 8; |
523 | for (i = 0; i < swap_blocks; i++) { |
524 | j = i * 8; |
525 | k = j + 7; |
526 | for (m = 0; m < 4; m++) { |
527 | c_temp = user_data[j]; |
528 | user_data[j++] = user_data[k]; |
529 | user_data[k--] = c_temp; |
530 | } |
531 | } |
532 | } |
533 | |
534 | #ifdef DUMP_USER_DATA |
535 | static void push_to_buf(struct vdec_mpeg12_hw_s *hw, |
536 | u8 *pdata, |
537 | int len, |
538 | struct userdata_meta_info_t *pmeta, |
539 | u32 reference) |
540 | { |
541 | u32 *pLen; |
542 | int info_cnt; |
543 | u8 *pbuf_end; |
544 | |
545 | if (!hw->user_data_dump_buf) |
546 | return; |
547 | |
548 | if (hw->bskip) { |
549 | pr_info("over size, skip\n"); |
550 | return; |
551 | } |
552 | info_cnt = 0; |
553 | pLen = (u32 *)hw->pdump_buf_cur_start; |
554 | |
555 | *pLen = len; |
556 | hw->pdump_buf_cur_start += sizeof(u32); |
557 | info_cnt++; |
558 | pLen++; |
559 | |
560 | *pLen = pmeta->duration; |
561 | hw->pdump_buf_cur_start += sizeof(u32); |
562 | info_cnt++; |
563 | pLen++; |
564 | |
565 | *pLen = pmeta->flags; |
566 | hw->pdump_buf_cur_start += sizeof(u32); |
567 | info_cnt++; |
568 | pLen++; |
569 | |
570 | *pLen = pmeta->vpts; |
571 | hw->pdump_buf_cur_start += sizeof(u32); |
572 | info_cnt++; |
573 | pLen++; |
574 | |
575 | *pLen = pmeta->vpts_valid; |
576 | hw->pdump_buf_cur_start += sizeof(u32); |
577 | info_cnt++; |
578 | pLen++; |
579 | |
580 | |
581 | *pLen = hw->n_userdata_id; |
582 | hw->pdump_buf_cur_start += sizeof(u32); |
583 | info_cnt++; |
584 | pLen++; |
585 | |
586 | *pLen = reference; |
587 | hw->pdump_buf_cur_start += sizeof(u32); |
588 | info_cnt++; |
589 | pLen++; |
590 | |
591 | pbuf_end = hw->userdata_info.data_buf_end; |
592 | if (pdata + len > pbuf_end) { |
593 | int first_section_len; |
594 | |
595 | first_section_len = pbuf_end - pdata; |
596 | memcpy(hw->pdump_buf_cur_start, pdata, first_section_len); |
597 | pdata = (u8 *)hw->userdata_info.data_buf; |
598 | hw->pdump_buf_cur_start += first_section_len; |
599 | memcpy(hw->pdump_buf_cur_start, pdata, len - first_section_len); |
600 | hw->pdump_buf_cur_start += len - first_section_len; |
601 | } else { |
602 | memcpy(hw->pdump_buf_cur_start, pdata, len); |
603 | hw->pdump_buf_cur_start += len; |
604 | } |
605 | |
606 | hw->total_len += len + info_cnt * sizeof(u32); |
607 | if (hw->total_len >= MAX_USER_DATA_SIZE-4096) |
608 | hw->bskip = 1; |
609 | } |
610 | |
611 | static void dump_userdata_info(struct vdec_mpeg12_hw_s *hw, |
612 | void *puser_data, |
613 | int len, |
614 | struct userdata_meta_info_t *pmeta, |
615 | u32 reference) |
616 | { |
617 | u8 *pstart; |
618 | |
619 | pstart = (u8 *)puser_data; |
620 | |
621 | #ifdef DUMP_HEAD_INFO_DATA |
622 | push_to_buf(hw, pstart, len, pmeta, reference); |
623 | #else |
624 | push_to_buf(hw, pstart+8, len - 8, pmeta, reference); |
625 | #endif |
626 | } |
627 | |
628 | |
629 | static void print_data(unsigned char *pdata, |
630 | int len, |
631 | unsigned int flag, |
632 | unsigned int duration, |
633 | unsigned int vpts, |
634 | unsigned int vpts_valid, |
635 | int rec_id, |
636 | u32 reference) |
637 | { |
638 | int nLeft; |
639 | |
640 | nLeft = len; |
641 | |
642 | pr_info("%d len:%d, flag:0x%x, dur:%d, vpts:0x%x, valid:%d, refer:%d\n", |
643 | rec_id, len, flag, |
644 | duration, vpts, vpts_valid, |
645 | reference); |
646 | while (nLeft >= 16) { |
647 | pr_info("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", |
648 | pdata[0], pdata[1], pdata[2], pdata[3], |
649 | pdata[4], pdata[5], pdata[6], pdata[7], |
650 | pdata[8], pdata[9], pdata[10], pdata[11], |
651 | pdata[12], pdata[13], pdata[14], pdata[15]); |
652 | nLeft -= 16; |
653 | pdata += 16; |
654 | } |
655 | |
656 | |
657 | while (nLeft > 0) { |
658 | pr_info("%02x %02x %02x %02x %02x %02x %02x %02x\n", |
659 | pdata[0], pdata[1], pdata[2], pdata[3], |
660 | pdata[4], pdata[5], pdata[6], pdata[7]); |
661 | nLeft -= 8; |
662 | pdata += 8; |
663 | } |
664 | } |
665 | |
666 | static void dump_data(u8 *pdata, |
667 | unsigned int user_data_length, |
668 | unsigned int flag, |
669 | unsigned int duration, |
670 | unsigned int vpts, |
671 | unsigned int vpts_valid, |
672 | int rec_id, |
673 | u32 reference) |
674 | { |
675 | unsigned char szBuf[256]; |
676 | |
677 | |
678 | memset(szBuf, 0, 256); |
679 | memcpy(szBuf, pdata, user_data_length); |
680 | |
681 | aml_swap_data(szBuf, user_data_length); |
682 | |
683 | print_data(szBuf, |
684 | user_data_length, |
685 | flag, |
686 | duration, |
687 | vpts, |
688 | vpts_valid, |
689 | rec_id, |
690 | reference); |
691 | } |
692 | |
693 | |
694 | static void show_user_data_buf(struct vdec_mpeg12_hw_s *hw) |
695 | { |
696 | u8 *pbuf; |
697 | int len; |
698 | unsigned int flag; |
699 | unsigned int duration; |
700 | unsigned int vpts; |
701 | unsigned int vpts_valid; |
702 | int rec_id; |
703 | u32 reference; |
704 | |
705 | pr_info("show user data buf\n"); |
706 | pbuf = hw->user_data_dump_buf; |
707 | |
708 | while (pbuf < hw->pdump_buf_cur_start) { |
709 | u32 *pLen; |
710 | |
711 | pLen = (u32 *)pbuf; |
712 | |
713 | len = *pLen; |
714 | pLen++; |
715 | pbuf += sizeof(u32); |
716 | |
717 | duration = *pLen; |
718 | pLen++; |
719 | pbuf += sizeof(u32); |
720 | |
721 | flag = *pLen; |
722 | pLen++; |
723 | pbuf += sizeof(u32); |
724 | |
725 | vpts = *pLen; |
726 | pLen++; |
727 | pbuf += sizeof(u32); |
728 | |
729 | vpts_valid = *pLen; |
730 | pLen++; |
731 | pbuf += sizeof(u32); |
732 | |
733 | rec_id = *pLen; |
734 | pLen++; |
735 | pbuf += sizeof(u32); |
736 | |
737 | reference = *pLen; |
738 | pLen++; |
739 | pbuf += sizeof(u32); |
740 | |
741 | |
742 | dump_data(pbuf, len, flag, duration, |
743 | vpts, vpts_valid, rec_id, reference); |
744 | pbuf += len; |
745 | msleep(30); |
746 | } |
747 | } |
748 | |
749 | static int amvdec_mmpeg12_init_userdata_dump(struct vdec_mpeg12_hw_s *hw) |
750 | { |
751 | hw->user_data_dump_buf = kmalloc(MAX_USER_DATA_SIZE, GFP_KERNEL); |
752 | if (hw->user_data_dump_buf) |
753 | return 1; |
754 | else |
755 | return 0; |
756 | } |
757 | |
758 | static void amvdec_mmpeg12_uninit_userdata_dump(struct vdec_mpeg12_hw_s *hw) |
759 | { |
760 | if (hw->user_data_dump_buf) { |
761 | show_user_data_buf(hw); |
762 | kfree(hw->user_data_dump_buf); |
763 | hw->user_data_dump_buf = NULL; |
764 | } |
765 | } |
766 | |
767 | static void reset_user_data_buf(struct vdec_mpeg12_hw_s *hw) |
768 | { |
769 | hw->total_len = 0; |
770 | hw->pdump_buf_cur_start = hw->user_data_dump_buf; |
771 | hw->bskip = 0; |
772 | hw->n_userdata_id = 0; |
773 | } |
774 | #endif |
775 | |
776 | static void user_data_ready_notify(struct vdec_mpeg12_hw_s *hw, |
777 | u32 pts, u32 pts_valid) |
778 | { |
779 | struct mmpeg2_userdata_record_t *p_userdata_rec; |
780 | int i; |
781 | |
782 | if (hw->wait_for_udr_send) { |
783 | for (i = 0; i < hw->cur_ud_idx; i++) { |
784 | mutex_lock(&hw->userdata_mutex); |
785 | |
786 | |
787 | p_userdata_rec = hw->userdata_info.records |
788 | + hw->userdata_info.write_index; |
789 | |
790 | hw->ud_record[i].meta_info.vpts_valid = pts_valid; |
791 | hw->ud_record[i].meta_info.vpts = pts; |
792 | |
793 | *p_userdata_rec = hw->ud_record[i]; |
794 | #ifdef DUMP_USER_DATA |
795 | dump_userdata_info(hw, |
796 | hw->userdata_info.data_buf + p_userdata_rec->rec_start, |
797 | p_userdata_rec->rec_len, |
798 | &p_userdata_rec->meta_info, |
799 | hw->reference[i]); |
800 | hw->n_userdata_id++; |
801 | #endif |
802 | /* |
803 | pr_info("notify: rec_start:%d, rec_len:%d, wi:%d, reference:%d\n", |
804 | p_userdata_rec->rec_start, |
805 | p_userdata_rec->rec_len, |
806 | hw->userdata_info.write_index, |
807 | hw->reference[i]); |
808 | */ |
809 | hw->userdata_info.write_index++; |
810 | if (hw->userdata_info.write_index >= USERDATA_FIFO_NUM) |
811 | hw->userdata_info.write_index = 0; |
812 | |
813 | mutex_unlock(&hw->userdata_mutex); |
814 | |
815 | |
816 | vdec_wakeup_userdata_poll(hw_to_vdec(hw)); |
817 | } |
818 | hw->wait_for_udr_send = 0; |
819 | hw->cur_ud_idx = 0; |
820 | } |
821 | hw->notify_ucode_cc_last_wp = hw->ucode_cc_last_wp; |
822 | hw->notify_data_cc_last_wp = hw->userdata_info.last_wp; |
823 | } |
824 | |
825 | static int vmmpeg2_user_data_read(struct vdec_s *vdec, |
826 | struct userdata_param_t *puserdata_para) |
827 | { |
828 | struct vdec_mpeg12_hw_s *hw = NULL; |
829 | int rec_ri, rec_wi; |
830 | int rec_len; |
831 | u8 *rec_data_start; |
832 | u8 *pdest_buf; |
833 | struct mmpeg2_userdata_record_t *p_userdata_rec; |
834 | u32 data_size; |
835 | u32 res; |
836 | int copy_ok = 1; |
837 | |
838 | hw = (struct vdec_mpeg12_hw_s *)vdec->private; |
839 | |
840 | pdest_buf = puserdata_para->pbuf_addr; |
841 | |
842 | mutex_lock(&hw->userdata_mutex); |
843 | |
844 | /* |
845 | pr_info("ri = %d, wi = %d\n", |
846 | hw->userdata_info.read_index, |
847 | hw->userdata_info.write_index); |
848 | */ |
849 | rec_ri = hw->userdata_info.read_index; |
850 | rec_wi = hw->userdata_info.write_index; |
851 | |
852 | if (rec_ri == rec_wi) { |
853 | mutex_unlock(&hw->userdata_mutex); |
854 | return 0; |
855 | } |
856 | |
857 | p_userdata_rec = hw->userdata_info.records + rec_ri; |
858 | |
859 | rec_len = p_userdata_rec->rec_len; |
860 | rec_data_start = p_userdata_rec->rec_start + hw->userdata_info.data_buf; |
861 | /* |
862 | pr_info("ri:%d, wi:%d, rec_len:%d, rec_start:%d, buf_len:%d\n", |
863 | rec_ri, rec_wi, |
864 | p_userdata_rec->rec_len, |
865 | p_userdata_rec->rec_start, |
866 | puserdata_para->buf_len); |
867 | */ |
868 | if (rec_len <= puserdata_para->buf_len) { |
869 | /* dvb user data buffer is enought to |
870 | copy the whole recored. */ |
871 | data_size = rec_len; |
872 | if (rec_data_start + data_size |
873 | > hw->userdata_info.data_buf_end) { |
874 | int first_section_len; |
875 | |
876 | first_section_len = hw->userdata_info.buf_len - |
877 | p_userdata_rec->rec_start; |
878 | res = (u32)copy_to_user((void *)pdest_buf, |
879 | (void *)rec_data_start, |
880 | first_section_len); |
881 | if (res) { |
882 | pr_info("p1 read not end res=%d, request=%d\n", |
883 | res, first_section_len); |
884 | copy_ok = 0; |
885 | |
886 | p_userdata_rec->rec_len -= |
887 | first_section_len - res; |
888 | p_userdata_rec->rec_start += |
889 | first_section_len - res; |
890 | puserdata_para->data_size = |
891 | first_section_len - res; |
892 | } else { |
893 | res = (u32)copy_to_user( |
894 | (void *)(pdest_buf+first_section_len), |
895 | (void *)hw->userdata_info.data_buf, |
896 | data_size - first_section_len); |
897 | if (res) { |
898 | pr_info("p2 read not end res=%d, request=%d\n", |
899 | res, data_size); |
900 | copy_ok = 0; |
901 | } |
902 | p_userdata_rec->rec_len -= |
903 | data_size - res; |
904 | p_userdata_rec->rec_start = |
905 | data_size - first_section_len - res; |
906 | puserdata_para->data_size = |
907 | data_size - res; |
908 | } |
909 | } else { |
910 | res = (u32)copy_to_user((void *)pdest_buf, |
911 | (void *)rec_data_start, |
912 | data_size); |
913 | if (res) { |
914 | pr_info("p3 read not end res=%d, request=%d\n", |
915 | res, data_size); |
916 | copy_ok = 0; |
917 | } |
918 | p_userdata_rec->rec_len -= data_size - res; |
919 | p_userdata_rec->rec_start += data_size - res; |
920 | puserdata_para->data_size = data_size - res; |
921 | } |
922 | |
923 | if (copy_ok) { |
924 | hw->userdata_info.read_index++; |
925 | if (hw->userdata_info.read_index >= USERDATA_FIFO_NUM) |
926 | hw->userdata_info.read_index = 0; |
927 | } |
928 | } else { |
929 | /* dvb user data buffer is not enought |
930 | to copy the whole recored. */ |
931 | data_size = puserdata_para->buf_len; |
932 | if (rec_data_start + data_size |
933 | > hw->userdata_info.data_buf_end) { |
934 | int first_section_len; |
935 | |
936 | first_section_len = hw->userdata_info.buf_len - |
937 | p_userdata_rec->rec_start; |
938 | res = (u32)copy_to_user((void *)pdest_buf, |
939 | (void *)rec_data_start, |
940 | first_section_len); |
941 | if (res) { |
942 | pr_info("p4 read not end res=%d, request=%d\n", |
943 | res, first_section_len); |
944 | copy_ok = 0; |
945 | p_userdata_rec->rec_len -= |
946 | first_section_len - res; |
947 | p_userdata_rec->rec_start += |
948 | first_section_len - res; |
949 | puserdata_para->data_size = |
950 | first_section_len - res; |
951 | } else { |
952 | /* first secton copy is ok*/ |
953 | res = (u32)copy_to_user( |
954 | (void *)(pdest_buf+first_section_len), |
955 | (void *)hw->userdata_info.data_buf, |
956 | data_size - first_section_len); |
957 | if (res) { |
958 | pr_info("p5 read not end res=%d, request=%d\n", |
959 | res, |
960 | data_size - first_section_len); |
961 | copy_ok = 0; |
962 | } |
963 | |
964 | p_userdata_rec->rec_len -= |
965 | data_size - res; |
966 | p_userdata_rec->rec_start = |
967 | data_size - first_section_len - res; |
968 | puserdata_para->data_size = |
969 | data_size - res; |
970 | } |
971 | } else { |
972 | res = (u32)copy_to_user((void *)pdest_buf, |
973 | (void *)rec_data_start, |
974 | data_size); |
975 | if (res) { |
976 | pr_info("p6 read not end res=%d, request=%d\n", |
977 | res, data_size); |
978 | copy_ok = 0; |
979 | } |
980 | |
981 | p_userdata_rec->rec_len -= data_size - res; |
982 | p_userdata_rec->rec_start += data_size - res; |
983 | puserdata_para->data_size = data_size - res; |
984 | } |
985 | |
986 | if (copy_ok) { |
987 | hw->userdata_info.read_index++; |
988 | if (hw->userdata_info.read_index >= USERDATA_FIFO_NUM) |
989 | hw->userdata_info.read_index = 0; |
990 | } |
991 | |
992 | } |
993 | puserdata_para->meta_info = p_userdata_rec->meta_info; |
994 | |
995 | if (hw->userdata_info.read_index <= hw->userdata_info.write_index) |
996 | puserdata_para->meta_info.records_in_que = |
997 | hw->userdata_info.write_index - |
998 | hw->userdata_info.read_index; |
999 | else |
1000 | puserdata_para->meta_info.records_in_que = |
1001 | hw->userdata_info.write_index + |
1002 | USERDATA_FIFO_NUM - |
1003 | hw->userdata_info.read_index; |
1004 | |
1005 | puserdata_para->version = (0<<24|0<<16|0<<8|1); |
1006 | |
1007 | mutex_unlock(&hw->userdata_mutex); |
1008 | |
1009 | |
1010 | return 1; |
1011 | } |
1012 | |
1013 | static void vmmpeg2_reset_userdata_fifo(struct vdec_s *vdec, int bInit) |
1014 | { |
1015 | struct vdec_mpeg12_hw_s *hw = NULL; |
1016 | |
1017 | hw = (struct vdec_mpeg12_hw_s *)vdec->private; |
1018 | |
1019 | if (hw) { |
1020 | mutex_lock(&hw->userdata_mutex); |
1021 | pr_info("vmh264_reset_userdata_fifo: bInit: %d, ri: %d, wi: %d\n", |
1022 | bInit, |
1023 | hw->userdata_info.read_index, |
1024 | hw->userdata_info.write_index); |
1025 | hw->userdata_info.read_index = 0; |
1026 | hw->userdata_info.write_index = 0; |
1027 | |
1028 | if (bInit) |
1029 | hw->userdata_info.last_wp = 0; |
1030 | mutex_unlock(&hw->userdata_mutex); |
1031 | } |
1032 | } |
1033 | |
1034 | static void vmmpeg2_wakeup_userdata_poll(struct vdec_s *vdec) |
1035 | { |
1036 | amstream_wakeup_userdata_poll(vdec); |
1037 | } |
1038 | |
1039 | /* |
1040 | #define PRINT_HEAD_INFO |
1041 | */ |
1042 | static void userdata_push_do_work(struct work_struct *work) |
1043 | { |
1044 | u32 reg; |
1045 | u8 *pdata; |
1046 | u8 *psrc_data; |
1047 | u8 head_info[8]; |
1048 | struct userdata_meta_info_t meta_info; |
1049 | u32 wp; |
1050 | u32 index; |
1051 | u32 picture_struct; |
1052 | u32 reference; |
1053 | u32 picture_type; |
1054 | u32 temp; |
1055 | u32 data_length; |
1056 | u32 data_start; |
1057 | int i; |
1058 | u32 offset; |
1059 | u32 cur_wp; |
1060 | #ifdef PRINT_HEAD_INFO |
1061 | u8 *ptype_str; |
1062 | #endif |
1063 | struct mmpeg2_userdata_record_t *pcur_ud_rec; |
1064 | |
1065 | struct vdec_mpeg12_hw_s *hw = container_of(work, |
1066 | struct vdec_mpeg12_hw_s, userdata_push_work); |
1067 | |
1068 | memset(&meta_info, 0, sizeof(meta_info)); |
1069 | |
1070 | meta_info.duration = hw->frame_dur; |
1071 | |
1072 | |
1073 | reg = READ_VREG(AV_SCRATCH_J); |
1074 | hw->userdata_wp_ctx = reg; |
1075 | meta_info.flags = ((reg >> 30) << 1); |
1076 | meta_info.flags |= (VFORMAT_MPEG12 << 3); |
1077 | /* check top_field_first flag */ |
1078 | if ((reg >> 28) & 0x1) { |
1079 | meta_info.flags |= (1 << 10); |
1080 | meta_info.flags |= (((reg >> 29) & 0x1) << 11); |
1081 | } |
1082 | |
1083 | cur_wp = reg & 0x7fff; |
1084 | if (cur_wp == hw->ucode_cc_last_wp) { |
1085 | debug_print(DECODE_ID(hw), 0, |
1086 | "Null user data package: wp = %d\n", cur_wp); |
1087 | WRITE_VREG(AV_SCRATCH_J, 0); |
1088 | return; |
1089 | } |
1090 | |
1091 | if (hw->cur_ud_idx >= MAX_UD_RECORDS) { |
1092 | debug_print(DECODE_ID(hw), PRINT_FLAG_DEC_DETAIL, |
1093 | "UD Records over: %d, skip it\n", MAX_UD_RECORDS); |
1094 | WRITE_VREG(AV_SCRATCH_J, 0); |
1095 | hw->cur_ud_idx = 0; |
1096 | return; |
1097 | } |
1098 | |
1099 | if (cur_wp < hw->ucode_cc_last_wp) |
1100 | hw->ucode_cc_last_wp = 0; |
1101 | |
1102 | offset = READ_VREG(AV_SCRATCH_I); |
1103 | |
1104 | codec_mm_dma_flush( |
1105 | hw->ccbuf_phyAddress_virt, |
1106 | CCBUF_SIZE, |
1107 | DMA_FROM_DEVICE); |
1108 | |
1109 | mutex_lock(&hw->userdata_mutex); |
1110 | if (hw->ccbuf_phyAddress_virt) { |
1111 | pdata = (u8 *)hw->ccbuf_phyAddress_virt + hw->ucode_cc_last_wp; |
1112 | memcpy(head_info, pdata, 8); |
1113 | } else |
1114 | memset(head_info, 0, 8); |
1115 | mutex_unlock(&hw->userdata_mutex); |
1116 | aml_swap_data(head_info, 8); |
1117 | |
1118 | wp = (head_info[0] << 8 | head_info[1]); |
1119 | index = (head_info[2] << 8 | head_info[3]); |
1120 | |
1121 | picture_struct = (head_info[6] << 8 | head_info[7]); |
1122 | temp = (head_info[4] << 8 | head_info[5]); |
1123 | reference = temp & 0x3FF; |
1124 | picture_type = (temp >> 10) & 0x7; |
1125 | |
1126 | if (debug_enable & PRINT_FLAG_USERDATA_DETAIL) |
1127 | pr_info("index:%d, wp:%d, ref:%d, type:%d, struct:0x%x, u_last_wp:0x%x\n", |
1128 | index, wp, reference, |
1129 | picture_type, picture_struct, |
1130 | hw->ucode_cc_last_wp); |
1131 | |
1132 | switch (picture_type) { |
1133 | case 1: |
1134 | /* pr_info("I type, pos:%d\n", |
1135 | (meta_info.flags>>1)&0x3); */ |
1136 | meta_info.flags |= (1<<7); |
1137 | #ifdef PRINT_HEAD_INFO |
1138 | ptype_str = " I"; |
1139 | #endif |
1140 | break; |
1141 | case 2: |
1142 | /* pr_info("P type, pos:%d\n", |
1143 | (meta_info.flags>>1)&0x3); */ |
1144 | meta_info.flags |= (2<<7); |
1145 | #ifdef PRINT_HEAD_INFO |
1146 | ptype_str = " P"; |
1147 | #endif |
1148 | break; |
1149 | case 3: |
1150 | /* pr_info("B type, pos:%d\n", |
1151 | (meta_info.flags>>1)&0x3); */ |
1152 | meta_info.flags |= (3<<7); |
1153 | #ifdef PRINT_HEAD_INFO |
1154 | ptype_str = " B"; |
1155 | #endif |
1156 | break; |
1157 | case 4: |
1158 | /* pr_info("D type, pos:%d\n", |
1159 | (meta_info.flags>>1)&0x3); */ |
1160 | meta_info.flags |= (4<<7); |
1161 | #ifdef PRINT_HEAD_INFO |
1162 | ptype_str = " D"; |
1163 | #endif |
1164 | break; |
1165 | default: |
1166 | /* pr_info("Unknown type:0x%x, pos:%d\n", |
1167 | pheader->picture_coding_type, |
1168 | (meta_info.flags>>1)&0x3); */ |
1169 | #ifdef PRINT_HEAD_INFO |
1170 | ptype_str = " U"; |
1171 | #endif |
1172 | break; |
1173 | } |
1174 | #ifdef PRINT_HEAD_INFO |
1175 | pr_info("ref:%d, type:%s, ext:%d, first:%d, data_length:%d\n", |
1176 | reference, ptype_str, |
1177 | (reg >> 30), |
1178 | (reg >> 28)&0x3, |
1179 | reg & 0xffff); |
1180 | #endif |
1181 | data_length = cur_wp - hw->ucode_cc_last_wp; |
1182 | data_start = reg & 0xffff; |
1183 | psrc_data = (u8 *)hw->ccbuf_phyAddress_virt + hw->ucode_cc_last_wp; |
1184 | |
1185 | pdata = hw->userdata_info.data_buf + hw->userdata_info.last_wp; |
1186 | for (i = 0; i < data_length; i++) { |
1187 | *pdata++ = *psrc_data++; |
1188 | if (pdata >= hw->userdata_info.data_buf_end) |
1189 | pdata = hw->userdata_info.data_buf; |
1190 | } |
1191 | pcur_ud_rec = hw->ud_record + hw->cur_ud_idx; |
1192 | |
1193 | pcur_ud_rec->meta_info = meta_info; |
1194 | pcur_ud_rec->rec_start = hw->userdata_info.last_wp; |
1195 | pcur_ud_rec->rec_len = data_length; |
1196 | |
1197 | hw->userdata_info.last_wp += data_length; |
1198 | if (hw->userdata_info.last_wp >= USER_DATA_SIZE) |
1199 | hw->userdata_info.last_wp -= USER_DATA_SIZE; |
1200 | |
1201 | hw->wait_for_udr_send = 1; |
1202 | |
1203 | hw->ucode_cc_last_wp = cur_wp; |
1204 | |
1205 | if (debug_enable & PRINT_FLAG_USERDATA_DETAIL) |
1206 | pr_info("cur_wp:%d, rec_start:%d, rec_len:%d\n", |
1207 | cur_wp, |
1208 | pcur_ud_rec->rec_start, |
1209 | pcur_ud_rec->rec_len); |
1210 | |
1211 | #ifdef DUMP_USER_DATA |
1212 | hw->reference[hw->cur_ud_idx] = reference; |
1213 | #endif |
1214 | |
1215 | hw->cur_ud_idx++; |
1216 | WRITE_VREG(AV_SCRATCH_J, 0); |
1217 | |
1218 | } |
1219 | |
1220 | |
1221 | void userdata_pushed_drop(struct vdec_mpeg12_hw_s *hw) |
1222 | { |
1223 | hw->userdata_info.last_wp = hw->notify_data_cc_last_wp; |
1224 | hw->ucode_cc_last_wp = hw->notify_ucode_cc_last_wp; |
1225 | hw->cur_ud_idx = 0; |
1226 | hw->wait_for_udr_send = 0; |
1227 | |
1228 | } |
1229 | |
1230 | |
1231 | static int prepare_display_buf(struct vdec_mpeg12_hw_s *hw, |
1232 | struct pic_info_t *pic) |
1233 | { |
1234 | u32 field_num = 0, i; |
1235 | u32 first_field_type = 0, type = 0; |
1236 | struct vframe_s *vf = NULL; |
1237 | u32 index = pic->index; |
1238 | u32 info = pic->buffer_info; |
1239 | struct vdec_s *vdec = hw_to_vdec(hw); |
1240 | |
1241 | if (hw == NULL || pic == NULL) |
1242 | return -1; |
1243 | |
1244 | user_data_ready_notify(hw, pic->pts, pic->pts_valid); |
1245 | #ifdef NV21 |
1246 | type = VIDTYPE_VIU_NV21; |
1247 | #endif |
1248 | |
1249 | if (hw->frame_prog & PICINFO_PROG) { |
1250 | field_num = 1; |
1251 | type |= VIDTYPE_PROGRESSIVE | VIDTYPE_VIU_FIELD; |
1252 | } else { |
1253 | #ifdef INTERLACE_SEQ_ALWAYS |
1254 | /* once an interlace seq, force interlace, to make di easy. */ |
1255 | hw->dec_control |= DEC_CONTROL_FLAG_FORCE_SEQ_INTERLACE; |
1256 | #endif |
1257 | hw->frame_rpt_state = FRAME_REPEAT_NONE; |
1258 | |
1259 | first_field_type = (info & PICINFO_TOP_FIRST) ? |
1260 | VIDTYPE_INTERLACE_TOP : VIDTYPE_INTERLACE_BOTTOM; |
1261 | field_num = (info & PICINFO_RPT_FIRST) ? 3 : 2; |
1262 | } |
1263 | |
1264 | for (i = 0; i < field_num; i++) { |
1265 | if (kfifo_get(&hw->newframe_q, &vf) == 0) { |
1266 | debug_print(DECODE_ID(hw), PRINT_FLAG_ERROR, |
1267 | "fatal error, no available buffer slot."); |
1268 | hw->dec_result = DEC_RESULT_ERROR; |
1269 | vdec_schedule_work(&hw->work); |
1270 | return -1; |
1271 | } |
1272 | hw->vfbuf_use[index]++; |
1273 | vf->index = index; |
1274 | set_frame_info(hw, vf); |
1275 | if (field_num > 1) { |
1276 | vf->duration = vf->duration / field_num; |
1277 | vf->duration_pulldown = (field_num == 3) ? |
1278 | (vf->duration >> 1):0; |
1279 | if (i > 0) |
1280 | type = VIDTYPE_VIU_NV21; |
1281 | if (i == 1) /* second field*/ |
1282 | type |= (first_field_type == VIDTYPE_INTERLACE_TOP) ? |
1283 | VIDTYPE_INTERLACE_BOTTOM : VIDTYPE_INTERLACE_TOP; |
1284 | else |
1285 | type |= (first_field_type == VIDTYPE_INTERLACE_TOP) ? |
1286 | VIDTYPE_INTERLACE_TOP : VIDTYPE_INTERLACE_BOTTOM; |
1287 | } else { |
1288 | if ((hw->seqinfo & SEQINFO_EXT_AVAILABLE) && |
1289 | (hw->seqinfo & SEQINFO_PROG)) { |
1290 | if (info & PICINFO_RPT_FIRST) { |
1291 | if (info & PICINFO_TOP_FIRST) |
1292 | vf->duration *= 3; |
1293 | else |
1294 | vf->duration *= 2; |
1295 | } |
1296 | vf->duration_pulldown = 0; |
1297 | } else { |
1298 | vf->duration_pulldown = |
1299 | (info & PICINFO_RPT_FIRST) ? |
1300 | vf->duration >> 1 : 0; |
1301 | } |
1302 | } |
1303 | vf->duration += vf->duration_pulldown; |
1304 | vf->type = type; |
1305 | vf->signal_type = hw->reg_signal_type; |
1306 | vf->orientation = 0; |
1307 | if (i > 0) { |
1308 | vf->pts = 0; |
1309 | vf->pts_us64 = 0; |
1310 | } else { |
1311 | vf->pts = (pic->pts_valid) ? pic->pts : 0; |
1312 | vf->pts_us64 = (pic->pts_valid) ? pic->pts64 : 0; |
1313 | } |
1314 | vf->type_original = vf->type; |
1315 | |
1316 | if ((error_skip(hw, pic->buffer_info, vf)) || |
1317 | ((hw->first_i_frame_ready == 0) && |
1318 | ((PICINFO_TYPE_MASK & pic->buffer_info) != |
1319 | PICINFO_TYPE_I))) { |
1320 | hw->drop_frame_count++; |
1321 | hw->vfbuf_use[index]--; |
1322 | kfifo_put(&hw->newframe_q, |
1323 | (const struct vframe_s *)vf); |
1324 | } else { |
1325 | debug_print(DECODE_ID(hw), PRINT_FLAG_TIMEINFO, |
1326 | "%s, num: %d(%c), i: %d, pts: %d(%lld), dur: %d, type: %x\n", |
1327 | __func__, hw->disp_num, GET_SLICE_TYPE(info), i, |
1328 | vf->pts, vf->pts_us64, vf->duration, vf->type); |
1329 | hw->disp_num++; |
1330 | if (i == 0) |
1331 | decoder_do_frame_check(hw_to_vdec(hw), vf); |
1332 | vdec->vdec_fps_detec(vdec->id); |
1333 | vf->mem_handle = |
1334 | decoder_bmmu_box_get_mem_handle( |
1335 | hw->mm_blk_handle, index); |
1336 | kfifo_put(&hw->display_q, |
1337 | (const struct vframe_s *)vf); |
1338 | if (without_display_mode == 0) { |
1339 | vf_notify_receiver(vdec->vf_provider_name, |
1340 | VFRAME_EVENT_PROVIDER_VFRAME_READY, |
1341 | NULL); |
1342 | } else |
1343 | vmpeg_vf_put(vmpeg_vf_get(vdec), vdec); |
1344 | |
1345 | |
1346 | } |
1347 | } |
1348 | return 0; |
1349 | } |
1350 | |
1351 | static void force_interlace_check(struct vdec_mpeg12_hw_s *hw) |
1352 | { |
1353 | if ((hw->dec_control & |
1354 | DEC_CONTROL_FLAG_FORCE_2500_720_576_INTERLACE) && |
1355 | (hw->frame_width == 720) && |
1356 | (hw->frame_height == 576) && |
1357 | (hw->frame_dur == 3840)) { |
1358 | hw->frame_prog = 0; |
1359 | } else if ((hw->dec_control |
1360 | & DEC_CONTROL_FLAG_FORCE_3000_704_480_INTERLACE) && |
1361 | (hw->frame_width == 704) && |
1362 | (hw->frame_height == 480) && |
1363 | (hw->frame_dur == 3200)) { |
1364 | hw->frame_prog = 0; |
1365 | } else if ((hw->dec_control |
1366 | & DEC_CONTROL_FLAG_FORCE_2500_704_576_INTERLACE) && |
1367 | (hw->frame_width == 704) && |
1368 | (hw->frame_height == 576) && |
1369 | (hw->frame_dur == 3840)) { |
1370 | hw->frame_prog = 0; |
1371 | } else if ((hw->dec_control |
1372 | & DEC_CONTROL_FLAG_FORCE_2500_544_576_INTERLACE) && |
1373 | (hw->frame_width == 544) && |
1374 | (hw->frame_height == 576) && |
1375 | (hw->frame_dur == 3840)) { |
1376 | hw->frame_prog = 0; |
1377 | } else if ((hw->dec_control |
1378 | & DEC_CONTROL_FLAG_FORCE_2500_480_576_INTERLACE) && |
1379 | (hw->frame_width == 480) && |
1380 | (hw->frame_height == 576) && |
1381 | (hw->frame_dur == 3840)) { |
1382 | hw->frame_prog = 0; |
1383 | } else if (hw->dec_control |
1384 | & DEC_CONTROL_FLAG_FORCE_SEQ_INTERLACE) { |
1385 | hw->frame_prog = 0; |
1386 | } |
1387 | |
1388 | } |
1389 | |
1390 | static int update_reference(struct vdec_mpeg12_hw_s *hw, |
1391 | int index) |
1392 | { |
1393 | hw->vfbuf_use[index]++; |
1394 | if (hw->refs[1] == -1) { |
1395 | hw->refs[1] = index; |
1396 | /* |
1397 | * first pic need output to show |
1398 | * usecnt do not decrease. |
1399 | */ |
1400 | } else if (hw->refs[0] == -1) { |
1401 | hw->refs[0] = hw->refs[1]; |
1402 | hw->refs[1] = index; |
1403 | /* second pic do not output */ |
1404 | index = DECODE_BUFFER_NUM_MAX; |
1405 | } else { |
1406 | hw->vfbuf_use[hw->refs[0]]--; |
1407 | hw->refs[0] = hw->refs[1]; |
1408 | hw->refs[1] = index; |
1409 | index = hw->refs[0]; |
1410 | } |
1411 | return index; |
1412 | } |
1413 | |
1414 | static bool is_ref_error(struct vdec_mpeg12_hw_s *hw) |
1415 | { |
1416 | if ((hw->pics[hw->refs[0]].buffer_info & PICINFO_ERROR) || |
1417 | (hw->pics[hw->refs[1]].buffer_info & PICINFO_ERROR)) |
1418 | return 1; |
1419 | return 0; |
1420 | } |
1421 | |
1422 | |
1423 | static irqreturn_t vmpeg12_isr_thread_fn(struct vdec_s *vdec, int irq) |
1424 | { |
1425 | u32 reg, index, info, seqinfo, offset, pts, frame_size, tmp; |
1426 | u64 pts_us64 = 0; |
1427 | struct pic_info_t *new_pic, *disp_pic; |
1428 | struct vdec_mpeg12_hw_s *hw = |
1429 | (struct vdec_mpeg12_hw_s *)(vdec->private); |
1430 | |
1431 | if (READ_VREG(AV_SCRATCH_M) != 0 && |
1432 | (debug_enable & PRINT_FLAG_UCODE_DETAIL)) { |
1433 | |
1434 | debug_print(DECODE_ID(hw), PRINT_FLAG_DEC_DETAIL, |
1435 | "dbg %x: %x, level %x, wp %x, rp %x, cnt %x\n", |
1436 | READ_VREG(AV_SCRATCH_M), READ_VREG(AV_SCRATCH_N), |
1437 | READ_VREG(VLD_MEM_VIFIFO_LEVEL), |
1438 | READ_VREG(VLD_MEM_VIFIFO_WP), |
1439 | READ_VREG(VLD_MEM_VIFIFO_RP), |
1440 | READ_VREG(VIFF_BIT_CNT)); |
1441 | WRITE_VREG(AV_SCRATCH_M, 0); |
1442 | return IRQ_HANDLED; |
1443 | } |
1444 | |
1445 | reg = READ_VREG(AV_SCRATCH_J); |
1446 | if (reg & (1<<16)) { |
1447 | vdec_schedule_work(&hw->userdata_push_work); |
1448 | return IRQ_HANDLED; |
1449 | } |
1450 | |
1451 | reg = READ_VREG(MREG_BUFFEROUT); |
1452 | if (reg == 2) { |
1453 | /*timeout when decoding next frame*/ |
1454 | debug_print(DECODE_ID(hw), PRINT_FLAG_VLD_DETAIL, |
1455 | "mmpeg12: lack data, lvl=%x ctrl=%x bcnt=%x\n", |
1456 | READ_VREG(VLD_MEM_VIFIFO_LEVEL), |
1457 | READ_VREG(VLD_MEM_VIFIFO_CONTROL), |
1458 | READ_VREG(VIFF_BIT_CNT)); |
1459 | |
1460 | if (vdec_frame_based(vdec)) { |
1461 | /* vmpeg12_save_hw_context(hw); */ |
1462 | reset_process_time(hw); |
1463 | hw->dec_result = DEC_RESULT_DONE; |
1464 | vdec_schedule_work(&hw->work); |
1465 | } else { |
1466 | hw->dec_result = DEC_RESULT_AGAIN; |
1467 | vdec_schedule_work(&hw->work); |
1468 | userdata_pushed_drop(hw); |
1469 | reset_process_time(hw); |
1470 | } |
1471 | return IRQ_HANDLED; |
1472 | } else { |
1473 | reset_process_time(hw); |
1474 | |
1475 | info = READ_VREG(MREG_PIC_INFO); |
1476 | offset = READ_VREG(MREG_FRAME_OFFSET); |
1477 | index = spec_to_index(hw, READ_VREG(REC_CANVAS_ADDR)); |
1478 | seqinfo = READ_VREG(MREG_SEQ_INFO); |
1479 | |
1480 | if ((info & PICINFO_PROG) == 0 && |
1481 | (info & FRAME_PICTURE_MASK) != FRAME_PICTURE) |
1482 | hw->first_i_frame_ready = 1; /* for field struct case*/ |
1483 | |
1484 | if (index >= DECODE_BUFFER_NUM_MAX) { |
1485 | debug_print(DECODE_ID(hw), PRINT_FLAG_ERROR, |
1486 | "mmpeg12: invalid buf index: %d\n", index); |
1487 | hw->dec_result = DEC_RESULT_ERROR; |
1488 | vdec_schedule_work(&hw->work); |
1489 | return IRQ_HANDLED; |
1490 | } |
1491 | hw->dec_num++; |
1492 | hw->dec_result = DEC_RESULT_DONE; |
1493 | new_pic = &hw->pics[index]; |
1494 | tmp = READ_VREG(MREG_PIC_WIDTH); |
1495 | if ((tmp > 1920) || (tmp == 0)) { |
1496 | new_pic->width = 1920; |
1497 | hw->frame_width = 1920; |
1498 | } else { |
1499 | new_pic->width = tmp; |
1500 | hw->frame_width = tmp; |
1501 | } |
1502 | |
1503 | tmp = READ_VREG(MREG_PIC_HEIGHT); |
1504 | if ((tmp > 1088) || (tmp == 0)) { |
1505 | new_pic->height = 1088; |
1506 | hw->frame_height = 1088; |
1507 | } else { |
1508 | new_pic->height = tmp; |
1509 | hw->frame_height = tmp; |
1510 | } |
1511 | |
1512 | new_pic->buffer_info = info; |
1513 | new_pic->offset = offset; |
1514 | new_pic->index = index; |
1515 | if (((info & PICINFO_TYPE_MASK) == PICINFO_TYPE_I) || |
1516 | ((info & PICINFO_TYPE_MASK) == PICINFO_TYPE_P)) { |
1517 | if (hw->chunk) { |
1518 | new_pic->pts_valid = hw->chunk->pts_valid; |
1519 | new_pic->pts = hw->chunk->pts; |
1520 | new_pic->pts64 = hw->chunk->pts64; |
1521 | if (hw->last_chunk_pts == hw->chunk->pts) { |
1522 | new_pic->pts_valid = 0; |
1523 | debug_print(DECODE_ID(hw), PRINT_FLAG_TIMEINFO, |
1524 | "pts invalid\n"); |
1525 | } |
1526 | } else { |
1527 | if (pts_lookup_offset_us64(PTS_TYPE_VIDEO, offset, |
1528 | &pts, &frame_size, 0, &pts_us64) == 0) { |
1529 | new_pic->pts_valid = true; |
1530 | new_pic->pts = pts; |
1531 | new_pic->pts64 = pts_us64; |
1532 | } else |
1533 | new_pic->pts_valid = false; |
1534 | } |
1535 | } else { |
1536 | if (hw->chunk) |
1537 | hw->last_chunk_pts = hw->chunk->pts; |
1538 | new_pic->pts_valid = false; |
1539 | } |
1540 | |
1541 | debug_print(DECODE_ID(hw), PRINT_FLAG_RUN_FLOW, |
1542 | "mmpeg12: new_pic=%d, ind=%d, info=%x, seq=%x, offset=%d\n", |
1543 | hw->dec_num, index, info, seqinfo, offset); |
1544 | |
1545 | hw->frame_prog = info & PICINFO_PROG; |
1546 | if ((seqinfo & SEQINFO_EXT_AVAILABLE) && |
1547 | ((seqinfo & SEQINFO_PROG) == 0)) |
1548 | hw->frame_prog = 0; |
1549 | force_interlace_check(hw); |
1550 | |
1551 | if (is_ref_error(hw)) { |
1552 | if ((info & PICINFO_TYPE_MASK) == PICINFO_TYPE_B) |
1553 | new_pic->buffer_info |= PICINFO_ERROR; |
1554 | } |
1555 | |
1556 | if (((info & PICINFO_TYPE_MASK) == PICINFO_TYPE_I) || |
1557 | ((info & PICINFO_TYPE_MASK) == PICINFO_TYPE_P)) { |
1558 | index = update_reference(hw, index); |
1559 | } else { |
1560 | /* drop b frame before reference pic ready */ |
1561 | if (hw->refs[0] == -1) |
1562 | index = DECODE_BUFFER_NUM_MAX; |
1563 | } |
1564 | vmpeg12_save_hw_context(hw, reg); |
1565 | |
1566 | if (index >= DECODE_BUFFER_NUM_MAX) { |
1567 | if (hw->dec_num != 2) { |
1568 | debug_print(DECODE_ID(hw), 0, |
1569 | "mmpeg12: drop pic num %d, type %c, index %d, offset %x\n", |
1570 | hw->dec_num, GET_SLICE_TYPE(info), index, offset); |
1571 | hw->dec_result = DEC_RESULT_ERROR; |
1572 | } |
1573 | vdec_schedule_work(&hw->work); |
1574 | return IRQ_HANDLED; |
1575 | } |
1576 | |
1577 | disp_pic = &hw->pics[index]; |
1578 | info = hw->pics[index].buffer_info; |
1579 | if (disp_pic->pts_valid && hw->lastpts64 == disp_pic->pts64) |
1580 | disp_pic->pts_valid = false; |
1581 | if (disp_pic->pts_valid) |
1582 | hw->lastpts64 = disp_pic->pts64; |
1583 | |
1584 | if ((hw->first_i_frame_ready == 0) && |
1585 | ((info & PICINFO_TYPE_MASK) == PICINFO_TYPE_I) && |
1586 | ((info & PICINFO_ERROR) == 0)) |
1587 | hw->first_i_frame_ready = 1; |
1588 | |
1589 | debug_print(DECODE_ID(hw), PRINT_FLAG_RUN_FLOW, |
1590 | "mmpeg12: disp_pic=%d(%c), ind=%d, offst=%x, pts=(%d,%lld)(%d)\n", |
1591 | hw->disp_num, GET_SLICE_TYPE(info), index, disp_pic->offset, |
1592 | disp_pic->pts, disp_pic->pts64, disp_pic->pts_valid); |
1593 | |
1594 | prepare_display_buf(hw, disp_pic); |
1595 | vdec_schedule_work(&hw->work); |
1596 | } |
1597 | |
1598 | return IRQ_HANDLED; |
1599 | } |
1600 | static irqreturn_t vmpeg12_isr(struct vdec_s *vdec, int irq) |
1601 | { |
1602 | u32 info, offset; |
1603 | struct vdec_mpeg12_hw_s *hw = |
1604 | (struct vdec_mpeg12_hw_s *)(vdec->private); |
1605 | if (hw->eos) |
1606 | return IRQ_HANDLED; |
1607 | info = READ_VREG(MREG_PIC_INFO); |
1608 | offset = READ_VREG(MREG_FRAME_OFFSET); |
1609 | |
1610 | vdec_count_info(&gvs, info & PICINFO_ERROR, offset); |
1611 | |
1612 | WRITE_VREG(ASSIST_MBOX1_CLR_REG, 1); |
1613 | |
1614 | return IRQ_WAKE_THREAD; |
1615 | } |
1616 | |
1617 | static void vmpeg12_notify_work(struct work_struct *work) |
1618 | { |
1619 | struct vdec_mpeg12_hw_s *hw = container_of(work, |
1620 | struct vdec_mpeg12_hw_s, notify_work); |
1621 | struct vdec_s *vdec = hw_to_vdec(hw); |
1622 | |
1623 | if (vdec->fr_hint_state == VDEC_NEED_HINT) { |
1624 | vf_notify_receiver(vdec->vf_provider_name, |
1625 | VFRAME_EVENT_PROVIDER_FR_HINT, |
1626 | (void *)((unsigned long)hw->frame_dur)); |
1627 | vdec->fr_hint_state = VDEC_HINTED; |
1628 | } |
1629 | } |
1630 | |
1631 | static void wait_vmmpeg12_search_done(struct vdec_mpeg12_hw_s *hw) |
1632 | { |
1633 | u32 vld_rp = READ_VREG(VLD_MEM_VIFIFO_RP); |
1634 | int count = 0; |
1635 | |
1636 | do { |
1637 | usleep_range(100, 500); |
1638 | if (vld_rp == READ_VREG(VLD_MEM_VIFIFO_RP)) |
1639 | break; |
1640 | if (count > 1000) { |
1641 | debug_print(DECODE_ID(hw), 0, |
1642 | "%s, count %d vld_rp 0x%x VLD_MEM_VIFIFO_RP 0x%x\n", |
1643 | __func__, count, vld_rp, READ_VREG(VLD_MEM_VIFIFO_RP)); |
1644 | break; |
1645 | } else |
1646 | vld_rp = READ_VREG(VLD_MEM_VIFIFO_RP); |
1647 | count++; |
1648 | } while (1); |
1649 | } |
1650 | |
1651 | static void flush_output(struct vdec_mpeg12_hw_s *hw) |
1652 | { |
1653 | int index = hw->refs[1]; |
1654 | |
1655 | /* video only one frame need not flush. */ |
1656 | if (hw->dec_num < 2) |
1657 | return; |
1658 | |
1659 | if (index >= 0 && index < DECODE_BUFFER_NUM_MAX) |
1660 | prepare_display_buf(hw, &hw->pics[index]); |
1661 | } |
1662 | |
1663 | static void vmpeg12_work_implement(struct vdec_mpeg12_hw_s *hw, |
1664 | struct vdec_s *vdec, int from) |
1665 | { |
1666 | if (hw->dec_result != DEC_RESULT_DONE) |
1667 | debug_print(DECODE_ID(hw), PRINT_FLAG_RUN_FLOW, |
1668 | "%s, result=%d, status=%d\n", __func__, |
1669 | hw->dec_result, vdec->next_status); |
1670 | |
1671 | if (hw->dec_result == DEC_RESULT_DONE) { |
1672 | vdec_vframe_dirty(vdec, hw->chunk); |
1673 | hw->chunk = NULL; |
1674 | } else if (hw->dec_result == DEC_RESULT_AGAIN && |
1675 | (vdec->next_status != VDEC_STATUS_DISCONNECTED)) { |
1676 | /* |
1677 | stream base: stream buf empty or timeout |
1678 | frame base: vdec_prepare_input fail |
1679 | */ |
1680 | if (!vdec_has_more_input(vdec)) { |
1681 | hw->dec_result = DEC_RESULT_EOS; |
1682 | vdec_schedule_work(&hw->work); |
1683 | return; |
1684 | } |
1685 | #ifdef AGAIN_HAS_THRESHOLD |
1686 | hw->next_again_flag = 1; |
1687 | #endif |
1688 | } else if (hw->dec_result == DEC_RESULT_GET_DATA && |
1689 | vdec->next_status != VDEC_STATUS_DISCONNECTED) { |
1690 | if (!vdec_has_more_input(vdec)) { |
1691 | hw->dec_result = DEC_RESULT_EOS; |
1692 | vdec_schedule_work(&hw->work); |
1693 | return; |
1694 | } |
1695 | debug_print(DECODE_ID(hw), PRINT_FLAG_VLD_DETAIL, |
1696 | "%s DEC_RESULT_GET_DATA %x %x %x\n", |
1697 | __func__, |
1698 | READ_VREG(VLD_MEM_VIFIFO_LEVEL), |
1699 | READ_VREG(VLD_MEM_VIFIFO_WP), |
1700 | READ_VREG(VLD_MEM_VIFIFO_RP)); |
1701 | vdec_vframe_dirty(vdec, hw->chunk); |
1702 | hw->chunk = NULL; |
1703 | vdec_clean_input(vdec); |
1704 | return; |
1705 | } else if (hw->dec_result == DEC_RESULT_FORCE_EXIT) { |
1706 | debug_print(DECODE_ID(hw), PRINT_FLAG_ERROR, |
1707 | "%s: force exit\n", __func__); |
1708 | if (hw->stat & STAT_ISR_REG) { |
1709 | amvdec_stop(); |
1710 | vdec_free_irq(VDEC_IRQ_1, (void *)hw); |
1711 | hw->stat &= ~STAT_ISR_REG; |
1712 | } |
1713 | } else if (hw->dec_result == DEC_RESULT_EOS) { |
1714 | if (hw->stat & STAT_VDEC_RUN) { |
1715 | amvdec_stop(); |
1716 | hw->stat &= ~STAT_VDEC_RUN; |
1717 | } |
1718 | hw->eos = 1; |
1719 | vdec_vframe_dirty(vdec, hw->chunk); |
1720 | hw->chunk = NULL; |
1721 | vdec_clean_input(vdec); |
1722 | flush_output(hw); |
1723 | debug_print(DECODE_ID(hw), 0, |
1724 | "%s: end of stream, num %d(%d)\n", |
1725 | __func__, hw->disp_num, hw->dec_num); |
1726 | } |
1727 | if (hw->stat & STAT_VDEC_RUN) { |
1728 | amvdec_stop(); |
1729 | hw->stat &= ~STAT_VDEC_RUN; |
1730 | } |
1731 | |
1732 | if (from == 1) { |
1733 | /*This is a timeout work*/ |
1734 | if (work_pending(&hw->work)) { |
1735 | pr_err("timeout work return befor finishing."); |
1736 | /* |
1737 | * The vmpeg12_work arrives at the last second, |
1738 | * give it a chance to handle the scenario. |
1739 | */ |
1740 | return; |
1741 | } |
1742 | } |
1743 | |
1744 | /*disable mbox interrupt */ |
1745 | WRITE_VREG(ASSIST_MBOX1_MASK, 0); |
1746 | wait_vmmpeg12_search_done(hw); |
1747 | if (vdec->parallel_dec == 1) |
1748 | vdec_core_finish_run(vdec, CORE_MASK_VDEC_1); |
1749 | else |
1750 | vdec_core_finish_run(vdec, CORE_MASK_VDEC_1 | CORE_MASK_HEVC); |
1751 | del_timer_sync(&hw->check_timer); |
1752 | hw->stat &= ~STAT_TIMER_ARM; |
1753 | |
1754 | if (hw->vdec_cb) |
1755 | hw->vdec_cb(vdec, hw->vdec_cb_arg); |
1756 | } |
1757 | |
1758 | static void vmpeg12_work(struct work_struct *work) |
1759 | { |
1760 | struct vdec_mpeg12_hw_s *hw = |
1761 | container_of(work, struct vdec_mpeg12_hw_s, work); |
1762 | struct vdec_s *vdec = hw_to_vdec(hw); |
1763 | |
1764 | vmpeg12_work_implement(hw, vdec, 0); |
1765 | } |
1766 | static void vmpeg12_timeout_work(struct work_struct *work) |
1767 | { |
1768 | struct vdec_mpeg12_hw_s *hw = |
1769 | container_of(work, struct vdec_mpeg12_hw_s, timeout_work); |
1770 | struct vdec_s *vdec = hw_to_vdec(hw); |
1771 | |
1772 | if (work_pending(&hw->work)) { |
1773 | pr_err("timeout work return befor executing."); |
1774 | return; |
1775 | } |
1776 | |
1777 | vmpeg12_work_implement(hw, vdec, 1); |
1778 | } |
1779 | |
1780 | static struct vframe_s *vmpeg_vf_peek(void *op_arg) |
1781 | { |
1782 | struct vframe_s *vf; |
1783 | struct vdec_s *vdec = op_arg; |
1784 | struct vdec_mpeg12_hw_s *hw = |
1785 | (struct vdec_mpeg12_hw_s *)vdec->private; |
1786 | hw->peek_num++; |
1787 | if (kfifo_peek(&hw->display_q, &vf)) |
1788 | return vf; |
1789 | |
1790 | return NULL; |
1791 | } |
1792 | |
1793 | static struct vframe_s *vmpeg_vf_get(void *op_arg) |
1794 | { |
1795 | struct vframe_s *vf; |
1796 | struct vdec_s *vdec = op_arg; |
1797 | struct vdec_mpeg12_hw_s *hw = |
1798 | (struct vdec_mpeg12_hw_s *)vdec->private; |
1799 | |
1800 | hw->get_num++; |
1801 | if (kfifo_get(&hw->display_q, &vf)) |
1802 | return vf; |
1803 | |
1804 | return NULL; |
1805 | } |
1806 | |
1807 | static void vmpeg_vf_put(struct vframe_s *vf, void *op_arg) |
1808 | { |
1809 | struct vdec_s *vdec = op_arg; |
1810 | struct vdec_mpeg12_hw_s *hw = |
1811 | (struct vdec_mpeg12_hw_s *)vdec->private; |
1812 | |
1813 | hw->vfbuf_use[vf->index]--; |
1814 | hw->put_num++; |
1815 | kfifo_put(&hw->newframe_q, |
1816 | (const struct vframe_s *)vf); |
1817 | debug_print(DECODE_ID(hw), PRINT_FLAG_RUN_FLOW, |
1818 | "%s: index %d, use %d\n", __func__, |
1819 | vf->index, hw->vfbuf_use[vf->index]); |
1820 | } |
1821 | |
1822 | static int vmpeg_event_cb(int type, void *data, void *private_data) |
1823 | { |
1824 | return 0; |
1825 | } |
1826 | |
1827 | static int vmpeg_vf_states(struct vframe_states *states, void *op_arg) |
1828 | { |
1829 | unsigned long flags; |
1830 | struct vdec_s *vdec = op_arg; |
1831 | struct vdec_mpeg12_hw_s *hw = |
1832 | (struct vdec_mpeg12_hw_s *)vdec->private; |
1833 | |
1834 | spin_lock_irqsave(&hw->lock, flags); |
1835 | |
1836 | states->vf_pool_size = VF_POOL_SIZE; |
1837 | states->buf_free_num = kfifo_len(&hw->newframe_q); |
1838 | states->buf_avail_num = kfifo_len(&hw->display_q); |
1839 | states->buf_recycle_num = 0; |
1840 | |
1841 | spin_unlock_irqrestore(&hw->lock, flags); |
1842 | return 0; |
1843 | } |
1844 | static int vmmpeg12_dec_status(struct vdec_s *vdec, struct vdec_info *vstatus) |
1845 | { |
1846 | struct vdec_mpeg12_hw_s *hw = |
1847 | (struct vdec_mpeg12_hw_s *)vdec->private; |
1848 | |
1849 | if (!hw) |
1850 | return -1; |
1851 | |
1852 | vstatus->frame_width = hw->frame_width; |
1853 | vstatus->frame_height = hw->frame_height; |
1854 | if (hw->frame_dur != 0) |
1855 | vstatus->frame_rate = 96000 / hw->frame_dur; |
1856 | else |
1857 | vstatus->frame_rate = -1; |
1858 | vstatus->error_count = READ_VREG(AV_SCRATCH_C); |
1859 | vstatus->status = hw->stat; |
1860 | vstatus->bit_rate = gvs.bit_rate; |
1861 | vstatus->frame_dur = hw->frame_dur; |
1862 | vstatus->frame_data = gvs.frame_data; |
1863 | vstatus->total_data = gvs.total_data; |
1864 | vstatus->frame_count = gvs.frame_count; |
1865 | vstatus->error_frame_count = gvs.error_frame_count; |
1866 | vstatus->drop_frame_count = hw->drop_frame_count; |
1867 | vstatus->total_data = gvs.total_data; |
1868 | vstatus->samp_cnt = gvs.samp_cnt; |
1869 | vstatus->offset = gvs.offset; |
1870 | vstatus->ratio_control = hw->ratio_control; |
1871 | snprintf(vstatus->vdec_name, sizeof(vstatus->vdec_name), |
1872 | "%s", DRIVER_NAME); |
1873 | |
1874 | return 0; |
1875 | } |
1876 | |
1877 | |
1878 | |
1879 | /****************************************/ |
1880 | static void vmpeg12_canvas_init(struct vdec_mpeg12_hw_s *hw) |
1881 | { |
1882 | int i, ret; |
1883 | u32 canvas_width, canvas_height; |
1884 | u32 decbuf_size, decbuf_y_size, decbuf_uv_size; |
1885 | unsigned long decbuf_start; |
1886 | /*u32 disp_addr = 0xffffffff;*/ |
1887 | struct vdec_s *vdec = hw_to_vdec(hw); |
1888 | |
1889 | if (buf_size <= 0x00400000) { |
1890 | /* SD only */ |
1891 | canvas_width = 768; |
1892 | canvas_height = 576; |
1893 | decbuf_y_size = 0x80000; |
1894 | decbuf_uv_size = 0x20000; |
1895 | decbuf_size = 0x100000; |
1896 | } else { |
1897 | /* HD & SD */ |
1898 | canvas_width = 1920; |
1899 | canvas_height = 1088; |
1900 | decbuf_y_size = 0x200000; |
1901 | decbuf_uv_size = 0x80000; |
1902 | decbuf_size = 0x300000; |
1903 | } |
1904 | |
1905 | for (i = 0; i < MAX_BMMU_BUFFER_NUM; i++) { |
1906 | |
1907 | unsigned canvas; |
1908 | if (i == (MAX_BMMU_BUFFER_NUM - 1)) /* SWAP&CCBUF&MATIRX&MV */ |
1909 | decbuf_size = WORKSPACE_SIZE; |
1910 | ret = decoder_bmmu_box_alloc_buf_phy(hw->mm_blk_handle, i, |
1911 | decbuf_size, DRIVER_NAME, &decbuf_start); |
1912 | if (ret < 0) { |
1913 | pr_err("mmu alloc failed! size 0x%d idx %d\n", |
1914 | decbuf_size, i); |
1915 | return; |
1916 | } |
1917 | |
1918 | if (i == (MAX_BMMU_BUFFER_NUM - 1)) { |
1919 | if (hw->ccbuf_phyAddress_is_remaped_nocache) |
1920 | codec_mm_unmap_phyaddr(hw->ccbuf_phyAddress_virt); |
1921 | hw->ccbuf_phyAddress_virt = NULL; |
1922 | hw->ccbuf_phyAddress = 0; |
1923 | hw->ccbuf_phyAddress_is_remaped_nocache = 0; |
1924 | |
1925 | hw->buf_start = decbuf_start; |
1926 | hw->ccbuf_phyAddress = hw->buf_start + CTX_CCBUF_OFFSET; |
1927 | hw->ccbuf_phyAddress_virt |
1928 | = codec_mm_phys_to_virt( |
1929 | hw->ccbuf_phyAddress); |
1930 | if ((!hw->ccbuf_phyAddress_virt) && (!hw->tvp_flag)) { |
1931 | hw->ccbuf_phyAddress_virt |
1932 | = codec_mm_vmap( |
1933 | hw->ccbuf_phyAddress, |
1934 | CCBUF_SIZE); |
1935 | hw->ccbuf_phyAddress_is_remaped_nocache = 1; |
1936 | } |
1937 | |
1938 | WRITE_VREG(MREG_CO_MV_START, hw->buf_start); |
1939 | } else { |
1940 | if (vdec->parallel_dec == 1) { |
1941 | unsigned tmp; |
1942 | if (canvas_u(hw->canvas_spec[i]) == 0xff) { |
1943 | tmp = |
1944 | vdec->get_canvas_ex(CORE_MASK_VDEC_1, vdec->id); |
1945 | hw->canvas_spec[i] &= ~(0xffff << 8); |
1946 | hw->canvas_spec[i] |= tmp << 8; |
1947 | hw->canvas_spec[i] |= tmp << 16; |
1948 | } |
1949 | if (canvas_y(hw->canvas_spec[i]) == 0xff) { |
1950 | tmp = |
1951 | vdec->get_canvas_ex(CORE_MASK_VDEC_1, vdec->id); |
1952 | hw->canvas_spec[i] &= ~0xff; |
1953 | hw->canvas_spec[i] |= tmp; |
1954 | } |
1955 | canvas = hw->canvas_spec[i]; |
1956 | } else { |
1957 | canvas = vdec->get_canvas(i, 2); |
1958 | hw->canvas_spec[i] = canvas; |
1959 | } |
1960 | |
1961 | hw->canvas_config[i][0].phy_addr = |
1962 | decbuf_start; |
1963 | hw->canvas_config[i][0].width = |
1964 | canvas_width; |
1965 | hw->canvas_config[i][0].height = |
1966 | canvas_height; |
1967 | hw->canvas_config[i][0].block_mode = |
1968 | hw->canvas_mode; |
1969 | hw->canvas_config[i][0].endian = |
1970 | (hw->canvas_mode == CANVAS_BLKMODE_LINEAR)?7:0; |
1971 | |
1972 | canvas_config_config(canvas_y(canvas), |
1973 | &hw->canvas_config[i][0]); |
1974 | |
1975 | hw->canvas_config[i][1].phy_addr = |
1976 | decbuf_start + decbuf_y_size; |
1977 | hw->canvas_config[i][1].width = canvas_width; |
1978 | hw->canvas_config[i][1].height = canvas_height / 2; |
1979 | hw->canvas_config[i][1].block_mode = hw->canvas_mode; |
1980 | hw->canvas_config[i][1].endian = |
1981 | (hw->canvas_mode == CANVAS_BLKMODE_LINEAR)?7:0; |
1982 | |
1983 | canvas_config_config(canvas_u(canvas), |
1984 | &hw->canvas_config[i][1]); |
1985 | } |
1986 | } |
1987 | return; |
1988 | } |
1989 | |
1990 | static void vmpeg2_dump_state(struct vdec_s *vdec) |
1991 | { |
1992 | struct vdec_mpeg12_hw_s *hw = |
1993 | (struct vdec_mpeg12_hw_s *)(vdec->private); |
1994 | u32 i; |
1995 | debug_print(DECODE_ID(hw), 0, |
1996 | "====== %s\n", __func__); |
1997 | debug_print(DECODE_ID(hw), 0, |
1998 | "width/height (%d/%d),i_first %d\n", |
1999 | hw->frame_width, |
2000 | hw->frame_height, |
2001 | hw->first_i_frame_ready |
2002 | ); |
2003 | debug_print(DECODE_ID(hw), 0, |
2004 | "is_framebase(%d), eos %d, state 0x%x, dec_result 0x%x dec_frm %d put_frm %d run %d not_run_ready %d,input_empty %d\n", |
2005 | vdec_frame_based(vdec), |
2006 | hw->eos, |
2007 | hw->stat, |
2008 | hw->dec_result, |
2009 | hw->dec_num, |
2010 | hw->put_num, |
2011 | hw->run_count, |
2012 | hw->not_run_ready, |
2013 | hw->input_empty |
2014 | ); |
2015 | |
2016 | for (i = 0; i < DECODE_BUFFER_NUM_MAX; i++) { |
2017 | debug_print(DECODE_ID(hw), 0, |
2018 | "index %d, used %d\n", i, hw->vfbuf_use[i]); |
2019 | } |
2020 | |
2021 | if (vf_get_receiver(vdec->vf_provider_name)) { |
2022 | enum receviver_start_e state = |
2023 | vf_notify_receiver(vdec->vf_provider_name, |
2024 | VFRAME_EVENT_PROVIDER_QUREY_STATE, |
2025 | NULL); |
2026 | debug_print(DECODE_ID(hw), 0, |
2027 | "\nreceiver(%s) state %d\n", |
2028 | vdec->vf_provider_name, |
2029 | state); |
2030 | } |
2031 | debug_print(DECODE_ID(hw), 0, |
2032 | "%s, newq(%d/%d), dispq(%d/%d) vf peek/get/put (%d/%d/%d),drop=%d, buffer_not_ready %d\n", |
2033 | __func__, |
2034 | kfifo_len(&hw->newframe_q), |
2035 | VF_POOL_SIZE, |
2036 | kfifo_len(&hw->display_q), |
2037 | VF_POOL_SIZE, |
2038 | hw->peek_num, |
2039 | hw->get_num, |
2040 | hw->put_num, |
2041 | hw->drop_frame_count, |
2042 | hw->buffer_not_ready |
2043 | ); |
2044 | debug_print(DECODE_ID(hw), 0, |
2045 | "VIFF_BIT_CNT=0x%x\n", |
2046 | READ_VREG(VIFF_BIT_CNT)); |
2047 | debug_print(DECODE_ID(hw), 0, |
2048 | "VLD_MEM_VIFIFO_LEVEL=0x%x\n", |
2049 | READ_VREG(VLD_MEM_VIFIFO_LEVEL)); |
2050 | debug_print(DECODE_ID(hw), 0, |
2051 | "VLD_MEM_VIFIFO_WP=0x%x\n", |
2052 | READ_VREG(VLD_MEM_VIFIFO_WP)); |
2053 | debug_print(DECODE_ID(hw), 0, |
2054 | "VLD_MEM_VIFIFO_RP=0x%x\n", |
2055 | READ_VREG(VLD_MEM_VIFIFO_RP)); |
2056 | debug_print(DECODE_ID(hw), 0, |
2057 | "PARSER_VIDEO_RP=0x%x\n", |
2058 | READ_PARSER_REG(PARSER_VIDEO_RP)); |
2059 | debug_print(DECODE_ID(hw), 0, |
2060 | "PARSER_VIDEO_WP=0x%x\n", |
2061 | READ_PARSER_REG(PARSER_VIDEO_WP)); |
2062 | if (vdec_frame_based(vdec) && |
2063 | debug_enable & PRINT_FRAMEBASE_DATA |
2064 | ) { |
2065 | int jj; |
2066 | if (hw->chunk && hw->chunk->block && |
2067 | hw->chunk->size > 0) { |
2068 | u8 *data = NULL; |
2069 | |
2070 | if (!hw->chunk->block->is_mapped) |
2071 | data = codec_mm_vmap(hw->chunk->block->start + |
2072 | hw->chunk->offset, hw->chunk->size); |
2073 | else |
2074 | data = ((u8 *)hw->chunk->block->start_virt) + |
2075 | hw->chunk->offset; |
2076 | |
2077 | debug_print(DECODE_ID(hw), 0, |
2078 | "frame data size 0x%x\n", |
2079 | hw->chunk->size); |
2080 | for (jj = 0; jj < hw->chunk->size; jj++) { |
2081 | if ((jj & 0xf) == 0) |
2082 | debug_print(DECODE_ID(hw), |
2083 | PRINT_FRAMEBASE_DATA, |
2084 | "%06x:", jj); |
2085 | debug_print(DECODE_ID(hw), |
2086 | PRINT_FRAMEBASE_DATA, |
2087 | "%02x ", data[jj]); |
2088 | if (((jj + 1) & 0xf) == 0) |
2089 | debug_print(DECODE_ID(hw), |
2090 | PRINT_FRAMEBASE_DATA, "\n"); |
2091 | } |
2092 | |
2093 | if (!hw->chunk->block->is_mapped) |
2094 | codec_mm_unmap_phyaddr(data); |
2095 | } |
2096 | } |
2097 | } |
2098 | |
2099 | static void reset_process_time(struct vdec_mpeg12_hw_s *hw) |
2100 | { |
2101 | if (hw->start_process_time) { |
2102 | unsigned process_time = |
2103 | 1000 * (jiffies - hw->start_process_time) / HZ; |
2104 | hw->start_process_time = 0; |
2105 | if (process_time > max_process_time[DECODE_ID(hw)]) |
2106 | max_process_time[DECODE_ID(hw)] = process_time; |
2107 | } |
2108 | } |
2109 | static void start_process_time(struct vdec_mpeg12_hw_s *hw) |
2110 | { |
2111 | hw->decode_timeout_count = 10; |
2112 | hw->start_process_time = jiffies; |
2113 | } |
2114 | static void timeout_process(struct vdec_mpeg12_hw_s *hw) |
2115 | { |
2116 | struct vdec_s *vdec = hw_to_vdec(hw); |
2117 | |
2118 | if (work_pending(&hw->work)) { |
2119 | pr_err("timeout_process return befor do anything."); |
2120 | return; |
2121 | } |
2122 | reset_process_time(hw); |
2123 | amvdec_stop(); |
2124 | debug_print(DECODE_ID(hw), PRINT_FLAG_ERROR, |
2125 | "%s decoder timeout, status=%d, level=%d\n", |
2126 | __func__, vdec->status, READ_VREG(VLD_MEM_VIFIFO_LEVEL)); |
2127 | hw->dec_result = DEC_RESULT_DONE; |
2128 | hw->first_i_frame_ready = 0; |
2129 | |
2130 | /* |
2131 | * In this very timeout point,the vmpeg12_work arrives, |
2132 | * let it to handle the scenario. |
2133 | */ |
2134 | if (work_pending(&hw->work)) { |
2135 | pr_err("timeout_process return befor schedule."); |
2136 | return; |
2137 | } |
2138 | vdec_schedule_work(&hw->timeout_work); |
2139 | } |
2140 | |
2141 | static void check_timer_func(unsigned long arg) |
2142 | { |
2143 | struct vdec_mpeg12_hw_s *hw = (struct vdec_mpeg12_hw_s *)arg; |
2144 | struct vdec_s *vdec = hw_to_vdec(hw); |
2145 | unsigned int timeout_val = decode_timeout_val; |
2146 | |
2147 | if (radr != 0) { |
2148 | if (rval != 0) { |
2149 | WRITE_VREG(radr, rval); |
2150 | pr_info("WRITE_VREG(%x,%x)\n", radr, rval); |
2151 | } else |
2152 | pr_info("READ_VREG(%x)=%x\n", radr, READ_VREG(radr)); |
2153 | rval = 0; |
2154 | radr = 0; |
2155 | } |
2156 | |
2157 | if (((debug_enable & PRINT_FLAG_TIMEOUT_STATUS) == 0) && |
2158 | (timeout_val > 0) && |
2159 | (hw->start_process_time > 0) && |
2160 | ((1000 * (jiffies - hw->start_process_time) / HZ) |
2161 | > timeout_val)) { |
2162 | if (hw->last_vld_level == READ_VREG(VLD_MEM_VIFIFO_LEVEL)) { |
2163 | if (hw->decode_timeout_count > 0) |
2164 | hw->decode_timeout_count--; |
2165 | if (hw->decode_timeout_count == 0) |
2166 | timeout_process(hw); |
2167 | } |
2168 | hw->last_vld_level = READ_VREG(VLD_MEM_VIFIFO_LEVEL); |
2169 | } |
2170 | |
2171 | if (vdec->next_status == VDEC_STATUS_DISCONNECTED) { |
2172 | hw->dec_result = DEC_RESULT_FORCE_EXIT; |
2173 | vdec_schedule_work(&hw->work); |
2174 | pr_info("vdec requested to be disconnected\n"); |
2175 | return; |
2176 | } |
2177 | |
2178 | mod_timer(&hw->check_timer, jiffies + CHECK_INTERVAL); |
2179 | } |
2180 | |
2181 | static int vmpeg12_hw_ctx_restore(struct vdec_mpeg12_hw_s *hw) |
2182 | { |
2183 | u32 index, i; |
2184 | index = find_buffer(hw); |
2185 | if (index >= DECODE_BUFFER_NUM_MAX) |
2186 | return -1; |
2187 | if (!hw->init_flag) |
2188 | vmpeg12_canvas_init(hw); |
2189 | else { |
2190 | WRITE_VREG(MREG_CO_MV_START, hw->buf_start); |
2191 | for (i = 0; i < DECODE_BUFFER_NUM_MAX; i++) { |
2192 | canvas_config_config(canvas_y(hw->canvas_spec[i]), |
2193 | &hw->canvas_config[i][0]); |
2194 | canvas_config_config(canvas_u(hw->canvas_spec[i]), |
2195 | &hw->canvas_config[i][1]); |
2196 | } |
2197 | } |
2198 | |
2199 | /* prepare REF0 & REF1 |
2200 | points to the past two IP buffers |
2201 | prepare REC_CANVAS_ADDR and ANC2_CANVAS_ADDR |
2202 | points to the output buffer*/ |
2203 | WRITE_VREG(MREG_REF0, |
2204 | (hw->refs[0] == -1) ? 0xffffffff : |
2205 | hw->canvas_spec[hw->refs[0]]); |
2206 | WRITE_VREG(MREG_REF1, |
2207 | (hw->refs[1] == -1) ? 0xffffffff : |
2208 | hw->canvas_spec[hw->refs[1]]); |
2209 | WRITE_VREG(REC_CANVAS_ADDR, hw->canvas_spec[index]); |
2210 | WRITE_VREG(ANC2_CANVAS_ADDR, hw->canvas_spec[index]); |
2211 | |
2212 | debug_print(DECODE_ID(hw), PRINT_FLAG_RESTORE, |
2213 | "%s,ref0=0x%x, ref1=0x%x,rec=0x%x, ctx_valid=%d,index=%d\n", |
2214 | __func__, |
2215 | READ_VREG(MREG_REF0), |
2216 | READ_VREG(MREG_REF1), |
2217 | READ_VREG(REC_CANVAS_ADDR), |
2218 | hw->ctx_valid, index); |
2219 | |
2220 | /* set to mpeg1 default */ |
2221 | WRITE_VREG(MPEG1_2_REG, |
2222 | (hw->ctx_valid) ? hw->reg_mpeg1_2_reg : 0); |
2223 | /* disable PSCALE for hardware sharing */ |
2224 | WRITE_VREG(PSCALE_CTRL, 0); |
2225 | /* for Mpeg1 default value */ |
2226 | WRITE_VREG(PIC_HEAD_INFO, |
2227 | (hw->ctx_valid) ? hw->reg_pic_head_info : 0x380); |
2228 | /* disable mpeg4 */ |
2229 | WRITE_VREG(M4_CONTROL_REG, 0); |
2230 | /* clear mailbox interrupt */ |
2231 | WRITE_VREG(ASSIST_MBOX1_CLR_REG, 1); |
2232 | /* clear buffer IN/OUT registers */ |
2233 | WRITE_VREG(MREG_BUFFEROUT, 0); |
2234 | /* enable mailbox interrupt */ |
2235 | WRITE_VREG(ASSIST_MBOX1_MASK, 1); |
2236 | /* set reference width and height */ |
2237 | if ((hw->frame_width != 0) && (hw->frame_height != 0)) |
2238 | WRITE_VREG(MREG_CMD, |
2239 | (hw->frame_width << 16) | hw->frame_height); |
2240 | else |
2241 | WRITE_VREG(MREG_CMD, 0); |
2242 | |
2243 | debug_print(DECODE_ID(hw), PRINT_FLAG_RESTORE, |
2244 | "0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", |
2245 | hw->frame_width, hw->frame_height, hw->seqinfo, |
2246 | hw->reg_f_code_reg, hw->reg_slice_ver_pos_pic_type, |
2247 | hw->reg_mb_info); |
2248 | |
2249 | WRITE_VREG(MREG_PIC_WIDTH, hw->reg_pic_width); |
2250 | WRITE_VREG(MREG_PIC_HEIGHT, hw->reg_pic_height); |
2251 | WRITE_VREG(MREG_SEQ_INFO, hw->seqinfo); |
2252 | WRITE_VREG(F_CODE_REG, hw->reg_f_code_reg); |
2253 | WRITE_VREG(SLICE_VER_POS_PIC_TYPE, |
2254 | hw->reg_slice_ver_pos_pic_type); |
2255 | WRITE_VREG(MB_INFO, hw->reg_mb_info); |
2256 | WRITE_VREG(VCOP_CTRL_REG, hw->reg_vcop_ctrl_reg); |
2257 | WRITE_VREG(AV_SCRATCH_H, hw->reg_signal_type); |
2258 | |
2259 | /* clear error count */ |
2260 | WRITE_VREG(MREG_ERROR_COUNT, 0); |
2261 | WRITE_VREG(MREG_FATAL_ERROR, 0); |
2262 | /* clear wait buffer status */ |
2263 | WRITE_VREG(MREG_WAIT_BUFFER, 0); |
2264 | #ifdef NV21 |
2265 | SET_VREG_MASK(MDEC_PIC_DC_CTRL, 1<<17); |
2266 | #endif |
2267 | if (!hw->ctx_valid) |
2268 | WRITE_VREG(AV_SCRATCH_J, hw->userdata_wp_ctx); |
2269 | |
2270 | if (hw->chunk) { |
2271 | /*frame based input*/ |
2272 | WRITE_VREG(MREG_INPUT, |
2273 | (hw->chunk->offset & 7) | (1<<7) | (hw->ctx_valid<<6)); |
2274 | } else { |
2275 | /*stream based input*/ |
2276 | WRITE_VREG(MREG_INPUT, (hw->ctx_valid<<6)); |
2277 | } |
2278 | return 0; |
2279 | } |
2280 | |
2281 | static void vmpeg12_local_init(struct vdec_mpeg12_hw_s *hw) |
2282 | { |
2283 | int i; |
2284 | INIT_KFIFO(hw->display_q); |
2285 | INIT_KFIFO(hw->newframe_q); |
2286 | |
2287 | for (i = 0; i < VF_POOL_SIZE; i++) { |
2288 | const struct vframe_s *vf; |
2289 | vf = &hw->vfpool[i]; |
2290 | hw->vfpool[i].index = DECODE_BUFFER_NUM_MAX; |
2291 | kfifo_put(&hw->newframe_q, (const struct vframe_s *)vf); |
2292 | } |
2293 | |
2294 | for (i = 0; i < DECODE_BUFFER_NUM_MAX; i++) |
2295 | hw->vfbuf_use[i] = 0; |
2296 | |
2297 | |
2298 | if (hw->mm_blk_handle) { |
2299 | decoder_bmmu_box_free(hw->mm_blk_handle); |
2300 | hw->mm_blk_handle = NULL; |
2301 | } |
2302 | |
2303 | hw->mm_blk_handle = decoder_bmmu_box_alloc_box( |
2304 | DRIVER_NAME, |
2305 | 0, |
2306 | MAX_BMMU_BUFFER_NUM, |
2307 | 4 + PAGE_SHIFT, |
2308 | CODEC_MM_FLAGS_CMA_CLEAR | |
2309 | CODEC_MM_FLAGS_FOR_VDECODER | |
2310 | hw->tvp_flag); |
2311 | hw->eos = 0; |
2312 | hw->frame_width = hw->frame_height = 0; |
2313 | hw->frame_dur = hw->frame_prog = 0; |
2314 | hw->frame_force_skip_flag = 0; |
2315 | hw->wait_buffer_counter = 0; |
2316 | hw->first_i_frame_ready = 0; |
2317 | hw->dec_control &= DEC_CONTROL_INTERNAL_MASK; |
2318 | hw->refs[0] = -1; |
2319 | hw->refs[1] = -1; |
2320 | hw->disp_num = 0; |
2321 | hw->dec_num = 0; |
2322 | hw->put_num = 0; |
2323 | hw->run_count = 0; |
2324 | hw->not_run_ready = 0; |
2325 | hw->input_empty = 0; |
2326 | hw->peek_num = 0; |
2327 | hw->get_num = 0; |
2328 | hw->drop_frame_count = 0; |
2329 | hw->buffer_not_ready = 0; |
2330 | hw->start_process_time = 0; |
2331 | hw->init_flag = 0; |
2332 | hw->error_frame_skip_level = error_frame_skip_level; |
2333 | if (dec_control) |
2334 | hw->dec_control = dec_control; |
2335 | } |
2336 | |
2337 | static s32 vmpeg12_init(struct vdec_mpeg12_hw_s *hw) |
2338 | { |
2339 | int size; |
2340 | u32 fw_size = 16*0x1000; |
2341 | struct firmware_s *fw; |
2342 | |
2343 | vmpeg12_local_init(hw); |
2344 | |
2345 | fw = vmalloc(sizeof(struct firmware_s) + fw_size); |
2346 | if (IS_ERR_OR_NULL(fw)) |
2347 | return -ENOMEM; |
2348 | |
2349 | pr_debug("get firmware ...\n"); |
2350 | size = get_firmware_data(VIDEO_DEC_MPEG12_MULTI, fw->data); |
2351 | if (size < 0) { |
2352 | pr_err("get firmware fail.\n"); |
2353 | vfree(fw); |
2354 | return -1; |
2355 | } |
2356 | |
2357 | fw->len = size; |
2358 | hw->fw = fw; |
2359 | |
2360 | INIT_WORK(&hw->userdata_push_work, userdata_push_do_work); |
2361 | INIT_WORK(&hw->work, vmpeg12_work); |
2362 | INIT_WORK(&hw->timeout_work, vmpeg12_timeout_work); |
2363 | INIT_WORK(&hw->notify_work, vmpeg12_notify_work); |
2364 | |
2365 | if (NULL == hw->user_data_buffer) { |
2366 | hw->user_data_buffer = kmalloc(USER_DATA_SIZE, |
2367 | GFP_KERNEL); |
2368 | if (!hw->user_data_buffer) { |
2369 | pr_info("%s: Can not allocate user_data_buffer\n", |
2370 | __func__); |
2371 | return -1; |
2372 | } |
2373 | } |
2374 | |
2375 | vmmpeg2_crate_userdata_manager(hw, |
2376 | hw->user_data_buffer, |
2377 | USER_DATA_SIZE); |
2378 | |
2379 | amvdec_enable(); |
2380 | init_timer(&hw->check_timer); |
2381 | hw->check_timer.data = (unsigned long)hw; |
2382 | hw->check_timer.function = check_timer_func; |
2383 | hw->check_timer.expires = jiffies + CHECK_INTERVAL; |
2384 | |
2385 | hw->stat |= STAT_TIMER_ARM; |
2386 | hw->stat |= STAT_ISR_REG; |
2387 | |
2388 | hw->buf_start = 0; |
2389 | WRITE_VREG(DECODE_STOP_POS, udebug_flag); |
2390 | |
2391 | return 0; |
2392 | } |
2393 | |
2394 | static unsigned long run_ready(struct vdec_s *vdec, unsigned long mask) |
2395 | { |
2396 | int index; |
2397 | |
2398 | struct vdec_mpeg12_hw_s *hw = |
2399 | (struct vdec_mpeg12_hw_s *)vdec->private; |
2400 | if (hw->eos) |
2401 | return 0; |
2402 | if (vdec_stream_based(vdec) && (hw->init_flag == 0) |
2403 | && pre_decode_buf_level != 0) { |
2404 | u32 rp, wp, level; |
2405 | |
2406 | rp = READ_PARSER_REG(PARSER_VIDEO_RP); |
2407 | wp = READ_PARSER_REG(PARSER_VIDEO_WP); |
2408 | if (wp < rp) |
2409 | level = vdec->input.size + wp - rp; |
2410 | else |
2411 | level = wp - rp; |
2412 | |
2413 | if (level < pre_decode_buf_level) { |
2414 | hw->not_run_ready++; |
2415 | return 0; |
2416 | } |
2417 | } |
2418 | |
2419 | #ifdef AGAIN_HAS_THRESHOLD |
2420 | if (hw->next_again_flag&& |
2421 | (!vdec_frame_based(vdec))) { |
2422 | u32 parser_wr_ptr = |
2423 | READ_PARSER_REG(PARSER_VIDEO_WP); |
2424 | if (parser_wr_ptr >= hw->pre_parser_wr_ptr && |
2425 | (parser_wr_ptr - hw->pre_parser_wr_ptr) < |
2426 | again_threshold) { |
2427 | int r = vdec_sync_input(vdec); |
2428 | debug_print(DECODE_ID(hw), PRINT_FLAG_RUN_FLOW, |
2429 | "%s buf level%x\n", |
2430 | __func__, r); |
2431 | return 0; |
2432 | } |
2433 | } |
2434 | #endif |
2435 | |
2436 | index = find_buffer(hw); |
2437 | if (index >= DECODE_BUFFER_NUM_MAX) { |
2438 | hw->buffer_not_ready++; |
2439 | return 0; |
2440 | } |
2441 | hw->not_run_ready = 0; |
2442 | hw->buffer_not_ready = 0; |
2443 | if (vdec->parallel_dec == 1) |
2444 | return (unsigned long)(CORE_MASK_VDEC_1); |
2445 | else |
2446 | return (unsigned long)(CORE_MASK_VDEC_1 | CORE_MASK_HEVC); |
2447 | } |
2448 | |
2449 | static unsigned char get_data_check_sum |
2450 | (struct vdec_mpeg12_hw_s *hw, int size) |
2451 | { |
2452 | int jj; |
2453 | int sum = 0; |
2454 | u8 *data = NULL; |
2455 | |
2456 | if (!hw->chunk->block->is_mapped) |
2457 | data = codec_mm_vmap(hw->chunk->block->start + |
2458 | hw->chunk->offset, size); |
2459 | else |
2460 | data = ((u8 *)hw->chunk->block->start_virt) + |
2461 | hw->chunk->offset; |
2462 | |
2463 | for (jj = 0; jj < size; jj++) |
2464 | sum += data[jj]; |
2465 | |
2466 | if (!hw->chunk->block->is_mapped) |
2467 | codec_mm_unmap_phyaddr(data); |
2468 | return sum; |
2469 | } |
2470 | |
2471 | static void run(struct vdec_s *vdec, unsigned long mask, |
2472 | void (*callback)(struct vdec_s *, void *), |
2473 | void *arg) |
2474 | { |
2475 | struct vdec_mpeg12_hw_s *hw = |
2476 | (struct vdec_mpeg12_hw_s *)vdec->private; |
2477 | int save_reg = READ_VREG(POWER_CTL_VLD); |
2478 | int size, ret; |
2479 | /* reset everything except DOS_TOP[1] and APB_CBUS[0]*/ |
2480 | WRITE_VREG(DOS_SW_RESET0, 0xfffffff0); |
2481 | WRITE_VREG(DOS_SW_RESET0, 0); |
2482 | WRITE_VREG(POWER_CTL_VLD, save_reg); |
2483 | hw->run_count++; |
2484 | vdec_reset_core(vdec); |
2485 | hw->vdec_cb_arg = arg; |
2486 | hw->vdec_cb = callback; |
2487 | |
2488 | #ifdef AGAIN_HAS_THRESHOLD |
2489 | hw->pre_parser_wr_ptr = |
2490 | READ_PARSER_REG(PARSER_VIDEO_WP); |
2491 | hw->next_again_flag = 0; |
2492 | #endif |
2493 | |
2494 | size = vdec_prepare_input(vdec, &hw->chunk); |
2495 | if (size < 0) { |
2496 | hw->input_empty++; |
2497 | hw->dec_result = DEC_RESULT_AGAIN; |
2498 | vdec_schedule_work(&hw->work); |
2499 | return; |
2500 | } |
2501 | if (vdec_frame_based(vdec) && debug_enable) { |
2502 | u8 *data = NULL; |
2503 | |
2504 | |
2505 | if (hw->chunk) |
2506 | debug_print(DECODE_ID(hw), PRINT_FLAG_RUN_FLOW, |
2507 | "run: chunk offset 0x%x, size %d\n", |
2508 | hw->chunk->offset, hw->chunk->size); |
2509 | |
2510 | if (!hw->chunk->block->is_mapped) |
2511 | data = codec_mm_vmap(hw->chunk->block->start + |
2512 | hw->chunk->offset, size); |
2513 | else |
2514 | data = ((u8 *)hw->chunk->block->start_virt) + |
2515 | hw->chunk->offset; |
2516 | |
2517 | if (debug_enable & PRINT_FLAG_VDEC_STATUS |
2518 | ) { |
2519 | debug_print(DECODE_ID(hw), 0, |
2520 | "%s: size 0x%x sum 0x%x %02x %02x %02x %02x %02x %02x .. %02x %02x %02x %02x\n", |
2521 | __func__, size, get_data_check_sum(hw, size), |
2522 | data[0], data[1], data[2], data[3], |
2523 | data[4], data[5], data[size - 4], |
2524 | data[size - 3], data[size - 2], |
2525 | data[size - 1]); |
2526 | } |
2527 | if (debug_enable & PRINT_FRAMEBASE_DATA |
2528 | ) { |
2529 | int jj; |
2530 | |
2531 | for (jj = 0; jj < size; jj++) { |
2532 | if ((jj & 0xf) == 0) |
2533 | debug_print(DECODE_ID(hw), |
2534 | PRINT_FRAMEBASE_DATA, |
2535 | "%06x:", jj); |
2536 | debug_print(DECODE_ID(hw), |
2537 | PRINT_FRAMEBASE_DATA, |
2538 | "%02x ", data[jj]); |
2539 | if (((jj + 1) & 0xf) == 0) |
2540 | debug_print(DECODE_ID(hw), |
2541 | PRINT_FRAMEBASE_DATA, |
2542 | "\n"); |
2543 | } |
2544 | } |
2545 | |
2546 | if (!hw->chunk->block->is_mapped) |
2547 | codec_mm_unmap_phyaddr(data); |
2548 | } else |
2549 | debug_print(DECODE_ID(hw), PRINT_FLAG_VDEC_STATUS, |
2550 | "%s: %x %x %x %x %x size 0x%x\n", |
2551 | __func__, |
2552 | READ_VREG(VLD_MEM_VIFIFO_LEVEL), |
2553 | READ_VREG(VLD_MEM_VIFIFO_WP), |
2554 | READ_VREG(VLD_MEM_VIFIFO_RP), |
2555 | READ_PARSER_REG(PARSER_VIDEO_RP), |
2556 | READ_PARSER_REG(PARSER_VIDEO_WP), |
2557 | size); |
2558 | |
2559 | |
2560 | hw->input_empty = 0; |
2561 | vdec_enable_input(vdec); |
2562 | |
2563 | hw->dec_result = DEC_RESULT_NONE; |
2564 | if (vdec->mc_loaded) { |
2565 | /*firmware have load before, |
2566 | and not changes to another. |
2567 | ignore reload. |
2568 | */ |
2569 | } else { |
2570 | ret = amvdec_vdec_loadmc_buf_ex(VFORMAT_MPEG12, "mmpeg12", vdec, |
2571 | hw->fw->data, hw->fw->len); |
2572 | if (ret < 0) { |
2573 | pr_err("[%d] %s: the %s fw loading failed, err: %x\n", vdec->id, |
2574 | hw->fw->name, tee_enabled() ? "TEE" : "local", ret); |
2575 | hw->dec_result = DEC_RESULT_FORCE_EXIT; |
2576 | vdec_schedule_work(&hw->work); |
2577 | return; |
2578 | } |
2579 | vdec->mc_loaded = 1; |
2580 | vdec->mc_type = VFORMAT_MPEG12; |
2581 | } |
2582 | if (vmpeg12_hw_ctx_restore(hw) < 0) { |
2583 | hw->dec_result = DEC_RESULT_ERROR; |
2584 | debug_print(DECODE_ID(hw), PRINT_FLAG_ERROR, |
2585 | "ammvdec_mpeg12: error HW context restore\n"); |
2586 | vdec_schedule_work(&hw->work); |
2587 | return; |
2588 | } |
2589 | /*wmb();*/ |
2590 | hw->stat |= STAT_MC_LOAD; |
2591 | hw->last_vld_level = 0; |
2592 | start_process_time(hw); |
2593 | amvdec_start(); |
2594 | hw->stat |= STAT_VDEC_RUN; |
2595 | hw->init_flag = 1; |
2596 | mod_timer(&hw->check_timer, jiffies + CHECK_INTERVAL); |
2597 | } |
2598 | |
2599 | static void reset(struct vdec_s *vdec) |
2600 | { |
2601 | pr_info("ammvdec_mpeg12: reset.\n"); |
2602 | } |
2603 | |
2604 | static int ammvdec_mpeg12_probe(struct platform_device *pdev) |
2605 | { |
2606 | struct vdec_s *pdata = *(struct vdec_s **)pdev->dev.platform_data; |
2607 | struct vdec_mpeg12_hw_s *hw = NULL; |
2608 | |
2609 | pr_info("ammvdec_mpeg12 probe start.\n"); |
2610 | |
2611 | if (pdata == NULL) { |
2612 | pr_info("ammvdec_mpeg12 platform data undefined.\n"); |
2613 | return -EFAULT; |
2614 | } |
2615 | |
2616 | hw = vzalloc(sizeof(struct vdec_mpeg12_hw_s)); |
2617 | if (hw == NULL) { |
2618 | pr_info("\nammvdec_mpeg12 decoder driver alloc failed\n"); |
2619 | return -ENOMEM; |
2620 | } |
2621 | |
2622 | pdata->private = hw; |
2623 | pdata->dec_status = vmmpeg12_dec_status; |
2624 | pdata->run_ready = run_ready; |
2625 | pdata->run = run; |
2626 | pdata->reset = reset; |
2627 | pdata->irq_handler = vmpeg12_isr; |
2628 | pdata->threaded_irq_handler = vmpeg12_isr_thread_fn; |
2629 | pdata->dump_state = vmpeg2_dump_state; |
2630 | |
2631 | pdata->user_data_read = vmmpeg2_user_data_read; |
2632 | pdata->reset_userdata_fifo = vmmpeg2_reset_userdata_fifo; |
2633 | pdata->wakeup_userdata_poll = vmmpeg2_wakeup_userdata_poll; |
2634 | |
2635 | if (pdata->use_vfm_path) { |
2636 | snprintf(pdata->vf_provider_name, VDEC_PROVIDER_NAME_SIZE, |
2637 | VFM_DEC_PROVIDER_NAME); |
2638 | hw->frameinfo_enable = 1; |
2639 | } |
2640 | else |
2641 | snprintf(pdata->vf_provider_name, VDEC_PROVIDER_NAME_SIZE, |
2642 | PROVIDER_NAME ".%02x", pdev->id & 0xff); |
2643 | if (pdata->parallel_dec == 1) { |
2644 | int i; |
2645 | for (i = 0; i < DECODE_BUFFER_NUM_MAX; i++) |
2646 | hw->canvas_spec[i] = 0xffffff; |
2647 | } |
2648 | vf_provider_init(&pdata->vframe_provider, pdata->vf_provider_name, |
2649 | &vf_provider_ops, pdata); |
2650 | |
2651 | platform_set_drvdata(pdev, pdata); |
2652 | hw->canvas_mode = pdata->canvas_mode; |
2653 | hw->platform_dev = pdev; |
2654 | |
2655 | hw->tvp_flag = vdec_secure(pdata) ? CODEC_MM_FLAGS_TVP : 0; |
2656 | if (pdata->sys_info) |
2657 | hw->vmpeg12_amstream_dec_info = *pdata->sys_info; |
2658 | |
2659 | debug_print(DECODE_ID(hw), 0, |
2660 | "%s, sysinfo: %dx%d, tvp_flag = 0x%x\n", |
2661 | __func__, |
2662 | hw->vmpeg12_amstream_dec_info.width, |
2663 | hw->vmpeg12_amstream_dec_info.height, |
2664 | hw->tvp_flag); |
2665 | |
2666 | if (vmpeg12_init(hw) < 0) { |
2667 | pr_info("ammvdec_mpeg12 init failed.\n"); |
2668 | if (hw) { |
2669 | vfree(hw); |
2670 | hw = NULL; |
2671 | } |
2672 | pdata->dec_status = NULL; |
2673 | return -ENODEV; |
2674 | } |
2675 | if (pdata->parallel_dec == 1) |
2676 | vdec_core_request(pdata, CORE_MASK_VDEC_1); |
2677 | else { |
2678 | vdec_core_request(pdata, CORE_MASK_VDEC_1 | CORE_MASK_HEVC |
2679 | | CORE_MASK_COMBINE); |
2680 | } |
2681 | #ifdef DUMP_USER_DATA |
2682 | amvdec_mmpeg12_init_userdata_dump(hw); |
2683 | reset_user_data_buf(hw); |
2684 | #endif |
2685 | |
2686 | /*INIT_WORK(&userdata_push_work, userdata_push_do_work);*/ |
2687 | return 0; |
2688 | } |
2689 | |
2690 | static int ammvdec_mpeg12_remove(struct platform_device *pdev) |
2691 | |
2692 | { |
2693 | struct vdec_mpeg12_hw_s *hw = |
2694 | (struct vdec_mpeg12_hw_s *) |
2695 | (((struct vdec_s *)(platform_get_drvdata(pdev)))->private); |
2696 | struct vdec_s *vdec = hw_to_vdec(hw); |
2697 | int i; |
2698 | |
2699 | if (hw->stat & STAT_VDEC_RUN) { |
2700 | amvdec_stop(); |
2701 | hw->stat &= ~STAT_VDEC_RUN; |
2702 | } |
2703 | |
2704 | if (hw->stat & STAT_ISR_REG) { |
2705 | vdec_free_irq(VDEC_IRQ_1, (void *)hw); |
2706 | hw->stat &= ~STAT_ISR_REG; |
2707 | } |
2708 | |
2709 | if (hw->stat & STAT_TIMER_ARM) { |
2710 | del_timer_sync(&hw->check_timer); |
2711 | hw->stat &= ~STAT_TIMER_ARM; |
2712 | } |
2713 | cancel_work_sync(&hw->userdata_push_work); |
2714 | cancel_work_sync(&hw->notify_work); |
2715 | cancel_work_sync(&hw->work); |
2716 | cancel_work_sync(&hw->timeout_work); |
2717 | |
2718 | if (hw->mm_blk_handle) { |
2719 | decoder_bmmu_box_free(hw->mm_blk_handle); |
2720 | hw->mm_blk_handle = NULL; |
2721 | } |
2722 | if (vdec->parallel_dec == 1) |
2723 | vdec_core_release(hw_to_vdec(hw), CORE_MASK_VDEC_1); |
2724 | else |
2725 | vdec_core_release(hw_to_vdec(hw), CORE_MASK_VDEC_1 | CORE_MASK_HEVC); |
2726 | vdec_set_status(hw_to_vdec(hw), VDEC_STATUS_DISCONNECTED); |
2727 | |
2728 | if (vdec->parallel_dec == 1) { |
2729 | for (i = 0; i < DECODE_BUFFER_NUM_MAX; i++) { |
2730 | vdec->free_canvas_ex(canvas_y(hw->canvas_spec[i]), vdec->id); |
2731 | vdec->free_canvas_ex(canvas_u(hw->canvas_spec[i]), vdec->id); |
2732 | } |
2733 | } |
2734 | |
2735 | if (hw->ccbuf_phyAddress_is_remaped_nocache) |
2736 | codec_mm_unmap_phyaddr(hw->ccbuf_phyAddress_virt); |
2737 | hw->ccbuf_phyAddress_virt = NULL; |
2738 | hw->ccbuf_phyAddress = 0; |
2739 | hw->ccbuf_phyAddress_is_remaped_nocache = 0; |
2740 | |
2741 | if (hw->user_data_buffer != NULL) { |
2742 | kfree(hw->user_data_buffer); |
2743 | hw->user_data_buffer = NULL; |
2744 | } |
2745 | vmmpeg2_destroy_userdata_manager(hw); |
2746 | |
2747 | #ifdef DUMP_USER_DATA |
2748 | amvdec_mmpeg12_uninit_userdata_dump(hw); |
2749 | #endif |
2750 | |
2751 | if (hw->fw) { |
2752 | vfree(hw->fw); |
2753 | hw->fw = NULL; |
2754 | } |
2755 | if (hw) { |
2756 | vfree(hw); |
2757 | hw = NULL; |
2758 | } |
2759 | pr_info("ammvdec_mpeg12 removed.\n"); |
2760 | memset(&gvs, 0x0, sizeof(gvs)); |
2761 | |
2762 | return 0; |
2763 | } |
2764 | |
2765 | /****************************************/ |
2766 | #ifdef CONFIG_PM |
2767 | static int mmpeg12_suspend(struct device *dev) |
2768 | { |
2769 | amvdec_suspend(to_platform_device(dev), dev->power.power_state); |
2770 | return 0; |
2771 | } |
2772 | |
2773 | static int mmpeg12_resume(struct device *dev) |
2774 | { |
2775 | amvdec_resume(to_platform_device(dev)); |
2776 | return 0; |
2777 | } |
2778 | |
2779 | static const struct dev_pm_ops mmpeg12_pm_ops = { |
2780 | SET_SYSTEM_SLEEP_PM_OPS(mmpeg12_suspend, mmpeg12_resume) |
2781 | }; |
2782 | #endif |
2783 | |
2784 | static struct platform_driver ammvdec_mpeg12_driver = { |
2785 | .probe = ammvdec_mpeg12_probe, |
2786 | .remove = ammvdec_mpeg12_remove, |
2787 | .driver = { |
2788 | .name = DRIVER_NAME, |
2789 | #ifdef CONFIG_PM |
2790 | .pm = &mmpeg12_pm_ops, |
2791 | #endif |
2792 | } |
2793 | }; |
2794 | |
2795 | static struct codec_profile_t ammvdec_mpeg12_profile = { |
2796 | .name = "mmpeg12", |
2797 | .profile = "" |
2798 | }; |
2799 | |
2800 | static struct mconfig mmpeg12_configs[] = { |
2801 | MC_PU32("stat", &stat), |
2802 | MC_PU32("radr", &radr), |
2803 | MC_PU32("rval", &rval), |
2804 | MC_PU32("dec_control", &dec_control), |
2805 | MC_PU32("error_frame_skip_level", &error_frame_skip_level), |
2806 | MC_PU32("decode_timeout_val", &decode_timeout_val), |
2807 | }; |
2808 | static struct mconfig_node mmpeg12_node; |
2809 | |
2810 | static int __init ammvdec_mpeg12_driver_init_module(void) |
2811 | { |
2812 | pr_info("ammvdec_mpeg12 module init\n"); |
2813 | |
2814 | if (platform_driver_register(&ammvdec_mpeg12_driver)) { |
2815 | pr_info("failed to register ammvdec_mpeg12 driver\n"); |
2816 | return -ENODEV; |
2817 | } |
2818 | vcodec_profile_register(&ammvdec_mpeg12_profile); |
2819 | INIT_REG_NODE_CONFIGS("media.decoder", &mmpeg12_node, |
2820 | "mmpeg12", mmpeg12_configs, CONFIG_FOR_RW); |
2821 | return 0; |
2822 | } |
2823 | |
2824 | static void __exit ammvdec_mpeg12_driver_remove_module(void) |
2825 | { |
2826 | pr_info("ammvdec_mpeg12 module exit.\n"); |
2827 | platform_driver_unregister(&ammvdec_mpeg12_driver); |
2828 | } |
2829 | |
2830 | /****************************************/ |
2831 | module_param(dec_control, uint, 0664); |
2832 | MODULE_PARM_DESC(dec_control, "\n ammvdec_mpeg12 decoder control\n"); |
2833 | module_param(error_frame_skip_level, uint, 0664); |
2834 | MODULE_PARM_DESC(error_frame_skip_level, |
2835 | "\n ammvdec_mpeg12 error_frame_skip_level\n"); |
2836 | |
2837 | module_param(radr, uint, 0664); |
2838 | MODULE_PARM_DESC(radr, "\nradr\n"); |
2839 | |
2840 | module_param(rval, uint, 0664); |
2841 | MODULE_PARM_DESC(rval, "\nrval\n"); |
2842 | |
2843 | module_param(debug_enable, uint, 0664); |
2844 | MODULE_PARM_DESC(debug_enable, |
2845 | "\n ammvdec_mpeg12 debug enable\n"); |
2846 | module_param(pre_decode_buf_level, int, 0664); |
2847 | MODULE_PARM_DESC(pre_decode_buf_level, |
2848 | "\n ammvdec_mpeg12 pre_decode_buf_level\n"); |
2849 | module_param(decode_timeout_val, uint, 0664); |
2850 | MODULE_PARM_DESC(decode_timeout_val, "\n ammvdec_mpeg12 decode_timeout_val\n"); |
2851 | |
2852 | module_param_array(max_process_time, uint, &max_decode_instance_num, 0664); |
2853 | |
2854 | module_param(udebug_flag, uint, 0664); |
2855 | MODULE_PARM_DESC(udebug_flag, "\n ammvdec_mpeg12 udebug_flag\n"); |
2856 | |
2857 | |
2858 | #ifdef AGAIN_HAS_THRESHOLD |
2859 | module_param(again_threshold, uint, 0664); |
2860 | MODULE_PARM_DESC(again_threshold, "\n again_threshold\n"); |
2861 | #endif |
2862 | |
2863 | module_param(without_display_mode, uint, 0664); |
2864 | MODULE_PARM_DESC(without_display_mode, "\n ammvdec_mpeg12 without_display_mode\n"); |
2865 | |
2866 | |
2867 | module_init(ammvdec_mpeg12_driver_init_module); |
2868 | module_exit(ammvdec_mpeg12_driver_remove_module); |
2869 | |
2870 | MODULE_DESCRIPTION("AMLOGIC MULTI MPEG1/2 Video Decoder Driver"); |
2871 | MODULE_LICENSE("GPL"); |
2872 | |
2873 | |
2874 |