summaryrefslogtreecommitdiff
path: root/drivers/frame_provider/decoder/h264/vh264.c (plain)
blob: 34701470c35fe579aaaff01590d4d9c6efce206f
1/*
2 * drivers/amlogic/media/frame_provider/decoder/h264/vh264.c
3 *
4 * Copyright (C) 2016 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#define DEBUG
19#include <linux/kernel.h>
20#include <linux/types.h>
21#include <linux/errno.h>
22#include <linux/interrupt.h>
23#include <linux/timer.h>
24#include <linux/kfifo.h>
25#include <linux/platform_device.h>
26
27#include <linux/amlogic/media/utils/amstream.h>
28#include <linux/amlogic/media/frame_sync/ptsserv.h>
29#include <linux/amlogic/media/vfm/vframe.h>
30#include <linux/amlogic/media/vfm/vframe_provider.h>
31#include <linux/amlogic/media/vfm/vframe_receiver.h>
32#include <linux/amlogic/media/utils/vformat.h>
33#include <linux/amlogic/media/frame_sync/tsync.h>
34#include <linux/workqueue.h>
35#include <linux/dma-mapping.h>
36#include <linux/atomic.h>
37#include <linux/module.h>
38#include <linux/slab.h>
39#include "../../../stream_input/amports/amports_priv.h"
40#include <linux/amlogic/media/canvas/canvas.h>
41
42#include "../utils/vdec.h"
43#include <linux/amlogic/media/utils/vdec_reg.h>
44#include "../utils/amvdec.h"
45#include "vh264.h"
46#include "../../../stream_input/parser/streambuf.h"
47#include <linux/delay.h>
48#include <linux/amlogic/media/video_sink/video.h>
49#include <linux/amlogic/tee.h>
50#include <linux/amlogic/media/ge2d/ge2d.h>
51#include "../utils/decoder_mmu_box.h"
52#include "../utils/decoder_bmmu_box.h"
53#include <linux/amlogic/media/codec_mm/codec_mm.h>
54#include <linux/amlogic/media/codec_mm/configs.h>
55#include "../utils/firmware.h"
56#include <linux/amlogic/tee.h>
57#include "../../../common/chips/decoder_cpu_ver_info.h"
58#include <linux/uaccess.h>
59
60
61
62#define DRIVER_NAME "amvdec_h264"
63#define MODULE_NAME "amvdec_h264"
64#define MEM_NAME "codec_264"
65#define HANDLE_H264_IRQ
66
67#if 0
68/* currently, only iptv supports this function*/
69#define SUPPORT_BAD_MACRO_BLOCK_REDUNDANCY
70#endif
71
72/* #define DEBUG_PTS */
73#if 0 /* MESON_CPU_TYPE <= MESON_CPU_TYPE_MESON6TV */
74#define DROP_B_FRAME_FOR_1080P_50_60FPS
75#endif
76#define RATE_MEASURE_NUM 8
77#define RATE_CORRECTION_THRESHOLD 5
78#define RATE_24_FPS 4004 /* 23.97 */
79#define RATE_25_FPS 3840 /* 25 */
80#define DUR2PTS(x) ((x)*90/96)
81#define PTS2DUR(x) ((x)*96/90)
82#define DUR2PTS_REM(x) (x*90 - DUR2PTS(x)*96)
83#define FIX_FRAME_RATE_CHECK_IDRFRAME_NUM 2
84#define VDEC_CLOCK_ADJUST_FRAME 30
85
86static inline bool close_to(int a, int b, int m)
87{
88 return (abs(a - b) < m) ? true : false;
89}
90
91static DEFINE_MUTEX(vh264_mutex);
92#define DEF_BUF_START_ADDR 0x1000000
93#define V_BUF_ADDR_OFFSET_NEW (0x1ee000)
94#define V_BUF_ADDR_OFFSET (0x13e000)
95
96#define PIC_SINGLE_FRAME 0
97#define PIC_TOP_BOT_TOP 1
98#define PIC_BOT_TOP_BOT 2
99#define PIC_DOUBLE_FRAME 3
100#define PIC_TRIPLE_FRAME 4
101#define PIC_TOP_BOT 5
102#define PIC_BOT_TOP 6
103#define PIC_INVALID 7
104
105#define EXTEND_SAR 0xff
106
107#define VF_POOL_SIZE 64
108#define VF_BUF_NUM 24
109#define WORKSPACE_BUF_NUM 2
110#define PUT_INTERVAL (HZ/100)
111#define NO_DISP_WD_COUNT (3 * HZ / PUT_INTERVAL)
112
113#define SWITCHING_STATE_OFF 0
114#define SWITCHING_STATE_ON_CMD3 1
115#define SWITCHING_STATE_ON_CMD1 2
116#define SWITCHING_STATE_ON_CMD1_PENDING 3
117
118
119#define DEC_CONTROL_FLAG_FORCE_2997_1080P_INTERLACE 0x0001
120#define DEC_CONTROL_FLAG_FORCE_2500_576P_INTERLACE 0x0002
121#define DEC_CONTROL_FLAG_DISABLE_FAST_POC 0x0004
122
123#define INCPTR(p) ptr_atomic_wrap_inc(&p)
124
125#define SLICE_TYPE_I 2
126#define SLICE_TYPE_P 5
127#define SLICE_TYPE_B 6
128
129struct buffer_spec_s {
130 unsigned int y_addr;
131 unsigned int u_addr;
132 unsigned int v_addr;
133
134 int y_canvas_index;
135 int u_canvas_index;
136 int v_canvas_index;
137
138 unsigned int y_canvas_width;
139 unsigned int u_canvas_width;
140 unsigned int v_canvas_width;
141
142 unsigned int y_canvas_height;
143 unsigned int u_canvas_height;
144 unsigned int v_canvas_height;
145
146 unsigned long phy_addr;
147 int alloc_count;
148};
149
150#define spec2canvas(x) \
151 (((x)->v_canvas_index << 16) | \
152 ((x)->u_canvas_index << 8) | \
153 ((x)->y_canvas_index << 0))
154
155static struct vframe_s *vh264_vf_peek(void *);
156static struct vframe_s *vh264_vf_get(void *);
157static void vh264_vf_put(struct vframe_s *, void *);
158static int vh264_vf_states(struct vframe_states *states, void *);
159static int vh264_event_cb(int type, void *data, void *private_data);
160
161static void vh264_prot_init(void);
162static int vh264_local_init(void);
163static void vh264_put_timer_func(unsigned long arg);
164static void stream_switching_done(void);
165
166static const char vh264_dec_id[] = "vh264-dev";
167
168#define PROVIDER_NAME "decoder.h264"
169
170static const struct vframe_operations_s vh264_vf_provider_ops = {
171 .peek = vh264_vf_peek,
172 .get = vh264_vf_get,
173 .put = vh264_vf_put,
174 .event_cb = vh264_event_cb,
175 .vf_states = vh264_vf_states,
176};
177
178static struct vframe_provider_s vh264_vf_prov;
179/*TODO irq*/
180#if 1
181static u32 frame_width, frame_height, frame_dur, frame_prog, frame_packing_type,
182 last_duration;
183static u32 saved_resolution;
184static u32 last_mb_width, last_mb_height;
185#else
186static u32 frame_buffer_size;
187static u32 frame_width, frame_height, frame_dur, frame_prog, last_duration;
188static u32 last_mb_width, last_mb_height;
189static u32 frame_packing_type;
190#endif
191static DECLARE_KFIFO(newframe_q, struct vframe_s *, VF_POOL_SIZE);
192static DECLARE_KFIFO(display_q, struct vframe_s *, VF_POOL_SIZE);
193static DECLARE_KFIFO(recycle_q, struct vframe_s *, VF_POOL_SIZE);
194static DECLARE_KFIFO(delay_display_q, struct vframe_s *, VF_POOL_SIZE);
195
196static struct vframe_s vfpool[VF_POOL_SIZE];
197static s32 vfbuf_use[VF_BUF_NUM];
198static struct buffer_spec_s buffer_spec[VF_BUF_NUM];
199static struct buffer_spec_s fense_buffer_spec[2];
200/* disp buf + keep buf+ fense buf + workspace */
201
202#define MAX_BLK_BUFFERS (VF_BUF_NUM + 2 + WORKSPACE_BUF_NUM)
203#define VF_BUFFER_IDX(n) (WORKSPACE_BUF_NUM + n)
204#define FENSE_BUFFER_IDX(n) (WORKSPACE_BUF_NUM + VF_BUF_NUM + n)
205
206#define USER_DATA_RUND_SIZE (USER_DATA_SIZE + 4096)
207static struct vframe_s fense_vf[2];
208
209static struct timer_list recycle_timer;
210static u32 stat;
211static s32 buf_offset;
212static u32 pts_outside;
213static u32 sync_outside;
214static u32 dec_control;
215static u32 vh264_ratio;
216static u32 vh264_rotation;
217static u32 use_idr_framerate;
218static u32 high_bandwidth;
219
220static u32 seq_info;
221static u32 timing_info_present_flag;
222static u32 fixed_frame_rate_flag;
223static u32 fixed_frame_rate_check_count;
224static u32 aspect_ratio_info;
225static u32 num_units_in_tick;
226static u32 time_scale;
227static u32 h264_ar;
228static u32 decoder_debug_flag;
229static u32 dpb_size_adj = 6;
230static u32 fr_hint_status;
231
232#ifdef DROP_B_FRAME_FOR_1080P_50_60FPS
233static u32 last_interlaced;
234#endif
235static bool is_4k;
236static unsigned char h264_first_pts_ready;
237static bool h264_first_valid_pts_ready;
238static u32 h264pts1, h264pts2;
239static u32 h264_pts_count, duration_from_pts_done, duration_on_correcting;
240static u32 vh264_error_count;
241static u32 vh264_no_disp_count;
242static u32 fatal_error_flag;
243static u32 fatal_error_reset;
244static u32 max_refer_buf = 1;
245static u32 decoder_force_reset;
246static unsigned int no_idr_error_count;
247static unsigned int no_idr_error_max = 60;
248static unsigned int canvas_mode;
249
250#ifdef SUPPORT_BAD_MACRO_BLOCK_REDUNDANCY
251/* 0~128*/
252static u32 bad_block_scale;
253#endif
254static u32 enable_userdata_debug;
255
256/* if not define, must clear AV_SCRATCH_J in isr when
257 * ITU_T35 code enabled in ucode, otherwise may fatal
258 * error repeatly.
259 */
260//#define ENABLE_SEI_ITU_T35
261
262
263
264static unsigned int enable_switch_fense = 1;
265#define EN_SWITCH_FENCE() (enable_switch_fense && !is_4k)
266static struct vframe_qos_s s_vframe_qos;
267static int frame_count;
268
269#if 0
270static u32 vh264_no_disp_wd_count;
271#endif
272static u32 vh264_running;
273static s32 vh264_stream_switching_state;
274static s32 vh264_eos;
275static struct vframe_s *p_last_vf;
276static s32 iponly_early_mode;
277static void *mm_blk_handle;
278static int tvp_flag;
279static bool is_reset;
280
281/*TODO irq*/
282#if 1
283static u32 last_pts, last_pts_remainder;
284#else
285static u32 last_pts;
286#endif
287static bool check_pts_discontinue;
288static u32 wait_buffer_counter;
289static u32 video_signal_from_vui;
290
291static uint error_recovery_mode;
292static uint error_recovery_mode_in = 3;
293static uint error_recovery_mode_use = 3;
294
295static uint mb_total = 0, mb_width = 0, mb_height;
296static uint saved_idc_level;
297#define UCODE_IP_ONLY 2
298#define UCODE_IP_ONLY_PARAM 1
299static uint ucode_type;
300
301#ifdef DEBUG_PTS
302static unsigned long pts_missed, pts_hit;
303#endif
304static uint debugfirmware;
305
306static atomic_t vh264_active = ATOMIC_INIT(0);
307static int vh264_reset;
308static struct work_struct error_wd_work;
309static struct work_struct stream_switching_work;
310static struct work_struct set_parameter_work;
311static struct work_struct notify_work;
312static struct work_struct set_clk_work;
313static struct work_struct userdata_push_work;
314
315struct h264_qos_data_node_t {
316 struct list_head list;
317
318 uint32_t b_offset;
319 int poc;
320 /* picture qos infomation*/
321 int max_qp;
322 int avg_qp;
323 int min_qp;
324 int max_skip;
325 int avg_skip;
326 int min_skip;
327 int max_mv;
328 int min_mv;
329 int avg_mv;
330};
331
332/*qos data records list waiting for match with picture that be display*/
333static struct list_head picture_qos_list;
334/*free qos data records list*/
335static struct list_head free_qos_nodes_list;
336#define MAX_FREE_QOS_NODES 64
337static struct h264_qos_data_node_t free_nodes[MAX_FREE_QOS_NODES];
338static struct work_struct qos_work;
339static struct dec_sysinfo vh264_amstream_dec_info;
340static dma_addr_t mc_dma_handle;
341static void *mc_cpu_addr;
342static u32 first_offset;
343static u32 first_pts;
344static u32 first_frame_size;
345static u64 first_pts64;
346static bool first_pts_cached;
347static void *sei_data_buffer;
348static dma_addr_t sei_data_buffer_phys;
349static int clk_adj_frame_count;
350
351#define MC_OFFSET_HEADER 0x0000
352#define MC_OFFSET_DATA 0x1000
353#define MC_OFFSET_MMCO 0x2000
354#define MC_OFFSET_LIST 0x3000
355#define MC_OFFSET_SLICE 0x4000
356
357#define MC_TOTAL_SIZE (20*SZ_1K)
358#define MC_SWAP_SIZE (4*SZ_1K)
359
360#define MODE_ERROR 0
361#define MODE_FULL 1
362
363static DEFINE_SPINLOCK(lock);
364static DEFINE_SPINLOCK(prepare_lock);
365static DEFINE_SPINLOCK(recycle_lock);
366
367static bool block_display_q;
368static int vh264_stop(int mode);
369static s32 vh264_init(void);
370
371
372#define DFS_HIGH_THEASHOLD 3
373
374static bool pts_discontinue;
375
376static struct ge2d_context_s *ge2d_videoh264_context;
377
378static struct vdec_info *gvs;
379
380static struct vdec_s *vdec_h264;
381
382static int ge2d_videoh264task_init(void)
383{
384 if (ge2d_videoh264_context == NULL)
385 ge2d_videoh264_context = create_ge2d_work_queue();
386
387 if (ge2d_videoh264_context == NULL) {
388 pr_info("create_ge2d_work_queue video task failed\n");
389 return -1;
390 }
391 return 0;
392}
393
394static int ge2d_videoh264task_release(void)
395{
396 if (ge2d_videoh264_context) {
397 destroy_ge2d_work_queue(ge2d_videoh264_context);
398 ge2d_videoh264_context = NULL;
399 }
400 return 0;
401}
402
403static int ge2d_canvas_dup(struct canvas_s *srcy, struct canvas_s *srcu,
404 struct canvas_s *des, int format, u32 srcindex,
405 u32 desindex)
406{
407
408 struct config_para_ex_s ge2d_config;
409 /* pr_info("[%s]h264 ADDR srcy[0x%lx] srcu[0x%lx] des[0x%lx]\n",
410 * __func__, srcy->addr, srcu->addr, des->addr);
411 */
412 memset(&ge2d_config, 0, sizeof(struct config_para_ex_s));
413
414 ge2d_config.alu_const_color = 0;
415 ge2d_config.bitmask_en = 0;
416 ge2d_config.src1_gb_alpha = 0;
417
418 ge2d_config.src_planes[0].addr = srcy->addr;
419 ge2d_config.src_planes[0].w = srcy->width;
420 ge2d_config.src_planes[0].h = srcy->height;
421
422 ge2d_config.src_planes[1].addr = srcu->addr;
423 ge2d_config.src_planes[1].w = srcu->width;
424 ge2d_config.src_planes[1].h = srcu->height;
425
426 ge2d_config.dst_planes[0].addr = des->addr;
427 ge2d_config.dst_planes[0].w = des->width;
428 ge2d_config.dst_planes[0].h = des->height;
429
430 ge2d_config.src_para.canvas_index = srcindex;
431 ge2d_config.src_para.mem_type = CANVAS_TYPE_INVALID;
432 ge2d_config.src_para.format = format;
433 ge2d_config.src_para.fill_color_en = 0;
434 ge2d_config.src_para.fill_mode = 0;
435 ge2d_config.src_para.color = 0;
436 ge2d_config.src_para.top = 0;
437 ge2d_config.src_para.left = 0;
438 ge2d_config.src_para.width = srcy->width;
439 ge2d_config.src_para.height = srcy->height;
440
441 ge2d_config.dst_para.canvas_index = desindex;
442 ge2d_config.dst_para.mem_type = CANVAS_TYPE_INVALID;
443 ge2d_config.dst_para.format = format;
444 ge2d_config.dst_para.fill_color_en = 0;
445 ge2d_config.dst_para.fill_mode = 0;
446 ge2d_config.dst_para.color = 0;
447 ge2d_config.dst_para.top = 0;
448 ge2d_config.dst_para.left = 0;
449 ge2d_config.dst_para.width = srcy->width;
450 ge2d_config.dst_para.height = srcy->height;
451
452 if (ge2d_context_config_ex(ge2d_videoh264_context, &ge2d_config) < 0) {
453 pr_info("ge2d_context_config_ex failed\n");
454 return -1;
455 }
456
457 stretchblt_noalpha(ge2d_videoh264_context, 0, 0, srcy->width,
458 srcy->height, 0, 0, srcy->width, srcy->height);
459
460 return 0;
461}
462
463static inline int fifo_level(void)
464{
465 return VF_POOL_SIZE - kfifo_len(&newframe_q);
466}
467
468
469void spec_set_canvas(struct buffer_spec_s *spec,
470 unsigned int width, unsigned int height)
471{
472 int endian;
473
474 endian = (canvas_mode == CANVAS_BLKMODE_LINEAR)?7:0;
475 canvas_config_ex(spec->y_canvas_index,
476 spec->y_addr,
477 width, height,
478 CANVAS_ADDR_NOWRAP, canvas_mode, endian);
479
480 canvas_config_ex(spec->u_canvas_index,
481 spec->u_addr,
482 width, height / 2,
483 CANVAS_ADDR_NOWRAP, canvas_mode, endian);
484
485}
486
487static void vh264_notify_work(struct work_struct *work)
488{
489 pr_info("frame duration changed %d\n", frame_dur);
490 vf_notify_receiver(PROVIDER_NAME, VFRAME_EVENT_PROVIDER_FR_HINT,
491 (void *)((unsigned long)frame_dur));
492
493 return;
494}
495
496static void prepare_display_q(void)
497{
498 unsigned long flags;
499 int count;
500
501 spin_lock_irqsave(&prepare_lock, flags);
502
503 if (block_display_q) {
504 spin_unlock_irqrestore(&prepare_lock, flags);
505 return;
506 }
507
508 spin_unlock_irqrestore(&prepare_lock, flags);
509
510 count = (int)VF_POOL_SIZE -
511 kfifo_len(&delay_display_q) -
512 kfifo_len(&display_q) -
513 kfifo_len(&recycle_q) -
514 kfifo_len(&newframe_q);
515
516 if ((vh264_stream_switching_state != SWITCHING_STATE_OFF)
517 || !EN_SWITCH_FENCE())
518 count = 0;
519 else
520 count = (count < 2) ? 0 : 2;
521
522 while (kfifo_len(&delay_display_q) > count) {
523 struct vframe_s *vf;
524
525 if (kfifo_get(&delay_display_q, &vf)) {
526 kfifo_put(&display_q,
527 (const struct vframe_s *)vf);
528 ATRACE_COUNTER(MODULE_NAME, vf->pts);
529 vf_notify_receiver(PROVIDER_NAME,
530 VFRAME_EVENT_PROVIDER_VFRAME_READY, NULL);
531 }
532 }
533}
534
535static struct vframe_s *vh264_vf_peek(void *op_arg)
536{
537 struct vframe_s *vf;
538
539 if (kfifo_peek(&display_q, &vf))
540 return vf;
541
542 return NULL;
543}
544
545static struct vframe_s *vh264_vf_get(void *op_arg)
546{
547 struct vframe_s *vf;
548
549 if (kfifo_get(&display_q, &vf))
550 return vf;
551
552 return NULL;
553}
554static bool vf_valid_check(struct vframe_s *vf) {
555 int i;
556 for (i = 0; i < VF_POOL_SIZE; i++) {
557 if (vf == &vfpool[i])
558 return true;
559 }
560 pr_info(" invalid vf been put, vf = %p\n", vf);
561 for (i = 0; i < VF_POOL_SIZE; i++) {
562 pr_info("www valid vf[%d]= %p \n", i, &vfpool[i]);
563 }
564 return false;
565}
566
567static void vh264_vf_put(struct vframe_s *vf, void *op_arg)
568{
569 unsigned long flags;
570
571 spin_lock_irqsave(&recycle_lock, flags);
572
573 if ((vf != &fense_vf[0]) && (vf != &fense_vf[1])) {
574 if (vf && (vf_valid_check(vf) == true))
575 kfifo_put(&recycle_q, (const struct vframe_s *)vf);
576 }
577 spin_unlock_irqrestore(&recycle_lock, flags);
578}
579
580static int vh264_event_cb(int type, void *data, void *private_data)
581{
582 if (type & VFRAME_EVENT_RECEIVER_RESET) {
583 unsigned long flags;
584
585 amvdec_stop();
586#ifndef CONFIG_AMLOGIC_POST_PROCESS_MANAGER
587 vf_light_unreg_provider(&vh264_vf_prov);
588#endif
589 spin_lock_irqsave(&lock, flags);
590 vh264_local_init();
591 vh264_prot_init();
592 spin_unlock_irqrestore(&lock, flags);
593#ifndef CONFIG_AMLOGIC_POST_PROCESS_MANAGER
594 vf_reg_provider(&vh264_vf_prov);
595#endif
596 amvdec_start();
597 }
598 return 0;
599}
600
601static int vh264_vf_states(struct vframe_states *states, void *op_arg)
602{
603 unsigned long flags;
604
605 spin_lock_irqsave(&lock, flags);
606
607 states->vf_pool_size = VF_POOL_SIZE;
608 states->buf_free_num = kfifo_len(&newframe_q);
609 states->buf_avail_num = kfifo_len(&display_q) +
610 kfifo_len(&delay_display_q);
611 states->buf_recycle_num = kfifo_len(&recycle_q);
612
613 spin_unlock_irqrestore(&lock, flags);
614
615 return 0;
616}
617
618#if 0
619static tvin_trans_fmt_t convert_3d_format(u32 type)
620{
621 const tvin_trans_fmt_t conv_tab[] = {
622 0, /* checkerboard */
623 0, /* column alternation */
624 TVIN_TFMT_3D_LA, /* row alternation */
625 TVIN_TFMT_3D_LRH_OLER, /* side by side */
626 TVIN_TFMT_3D_FA /* top bottom */
627 };
628
629 return (type <= 4) ? conv_tab[type] : 0;
630}
631#endif
632
633
634
635#define DUMP_CC_AS_ASCII
636
637#ifdef DUMP_CC_AS_ASCII
638static int vbi_to_ascii(int c)
639{
640 if (c < 0)
641 return '?';
642
643 c &= 0x7F;
644
645 if (c < 0x20 || c >= 0x7F)
646 return '.';
647
648 return c;
649}
650
651static void dump_cc_ascii(const uint8_t *buf, unsigned int vpts, int poc)
652{
653 int cc_flag;
654 int cc_count;
655 int i;
656 int szAscii[32];
657 int index = 0;
658
659 cc_flag = buf[1] & 0x40;
660 if (!cc_flag) {
661 pr_info("### cc_flag is invalid\n");
662 return;
663 }
664 cc_count = buf[1] & 0x1f;
665
666 for (i = 0; i < cc_count; ++i) {
667 unsigned int b0;
668 unsigned int cc_valid;
669 unsigned int cc_type;
670 unsigned char cc_data1;
671 unsigned char cc_data2;
672
673 b0 = buf[3 + i * 3];
674 cc_valid = b0 & 4;
675 cc_type = b0 & 3;
676 cc_data1 = buf[4 + i * 3];
677 cc_data2 = buf[5 + i * 3];
678
679
680 if (cc_type == 0) {
681 /* NTSC pair, Line 21 */
682 szAscii[index++] = vbi_to_ascii(cc_data1);
683 szAscii[index++] = vbi_to_ascii(cc_data2);
684 if ((!cc_valid) || (i >= 3))
685 break;
686 }
687 }
688
689 if (index > 0 && index <= 8) {
690 char pr_buf[128];
691 int len;
692
693 sprintf(pr_buf, "push vpts:0x%x, poc:%d :", vpts, poc);
694 len = strlen(pr_buf);
695 for (i=0;i<index;i++)
696 sprintf(pr_buf + len + i*2, "%c ", szAscii[i]);
697 pr_info("%s\n", pr_buf);
698 }
699
700}
701#endif
702
703/*
704#define DUMP_USER_DATA_HEX
705*/
706#ifdef DUMP_USER_DATA_HEX
707static void print_data(unsigned char *pdata, int len)
708{
709 int nLeft;
710 char buf[128];
711
712 nLeft = len;
713 while (nLeft >= 16) {
714 int i;
715
716 for (i=0;i<16;i++)
717 sprintf(buf+i*3, "%02x ", pdata[i]);
718
719 pr_info("%s\n", buf);
720 nLeft -= 16;
721 pdata += 16;
722 }
723
724 while (nLeft >= 8) {
725 int i;
726 for (i=0;i<nLeft;i++)
727 sprintf(buf+i*3, "%02x ", pdata[i]);
728
729 pr_info("%s\n", buf);
730 nLeft -= 8;
731 pdata += 8;
732 }
733}
734#endif
735
736
737
738static void aml_swap_data(uint8_t *user_data, int ud_size)
739{
740 int swap_blocks, i, j, k, m;
741 unsigned char c_temp;
742
743 /* swap byte order */
744 swap_blocks = ud_size / 8;
745 for (i = 0; i < swap_blocks; i++) {
746 j = i * 8;
747 k = j + 7;
748 for (m = 0; m < 4; m++) {
749 c_temp = user_data[j];
750 user_data[j++] = user_data[k];
751 user_data[k--] = c_temp;
752 }
753 }
754}
755
756
757static void udr_dump_data(unsigned int user_data_wp,
758 unsigned int user_data_length,
759 unsigned int pts,
760 int poc)
761{
762 unsigned char *pdata;
763 int user_data_len;
764 int wp_start;
765 int nLeft;
766 unsigned char szBuf[256];
767 int nOffset;
768
769 dma_sync_single_for_cpu(amports_get_dma_device(),
770 sei_data_buffer_phys, USER_DATA_SIZE,
771 DMA_FROM_DEVICE);
772
773 if (user_data_length & 0x07)
774 user_data_len = (user_data_length + 8) & 0xFFFFFFF8;
775 else
776 user_data_len = user_data_length;
777
778 if (user_data_wp >= user_data_len) {
779 wp_start = user_data_wp - user_data_len;
780
781 pdata = (unsigned char *)sei_data_buffer;
782 pdata += wp_start;
783 nLeft = user_data_len;
784
785 memset(szBuf, 0, 256);
786 memcpy(szBuf, pdata, user_data_len);
787 } else {
788 wp_start = user_data_wp +
789 USER_DATA_SIZE - user_data_len;
790
791 pdata = (unsigned char *)sei_data_buffer;
792 pdata += wp_start;
793 nLeft = USER_DATA_SIZE - wp_start;
794
795 memset(szBuf, 0, 256);
796 memcpy(szBuf, pdata, nLeft);
797 nOffset = nLeft;
798
799 pdata = (unsigned char *)sei_data_buffer;
800 nLeft = user_data_wp;
801 memcpy(szBuf+nOffset, pdata, nLeft);
802 }
803
804 aml_swap_data(szBuf, user_data_len);
805
806#ifdef DUMP_USER_DATA_HEX
807 print_data(szBuf, user_data_len);
808#endif
809
810#ifdef DUMP_CC_AS_ASCII
811 dump_cc_ascii(szBuf+7, pts, poc);
812#endif
813}
814
815
816struct vh264_userdata_recored_t {
817 struct userdata_meta_info_t meta_info;
818 u32 rec_start;
819 u32 rec_len;
820};
821
822#define USERDATA_FIFO_NUM 256
823
824struct vh264_userdata_info_t {
825 struct vh264_userdata_recored_t records[USERDATA_FIFO_NUM];
826 u8 *data_buf;
827 u8 *data_buf_end;
828 u32 buf_len;
829 u32 read_index;
830 u32 write_index;
831 u32 last_wp;
832};
833
834static struct vh264_userdata_info_t *p_userdata_mgr;
835
836static DEFINE_MUTEX(userdata_mutex);
837
838
839void vh264_crate_userdata_manager(u8 *userdata_buf, int buf_len)
840{
841 p_userdata_mgr = (struct vh264_userdata_info_t *)
842 vmalloc(sizeof(struct vh264_userdata_info_t));
843 if (p_userdata_mgr) {
844 memset(p_userdata_mgr, 0,
845 sizeof(struct vh264_userdata_info_t));
846 p_userdata_mgr->data_buf = userdata_buf;
847 p_userdata_mgr->buf_len = buf_len;
848 p_userdata_mgr->data_buf_end = userdata_buf + buf_len;
849 }
850}
851
852void vh264_destroy_userdata_manager(void)
853{
854 if (p_userdata_mgr) {
855 vfree(p_userdata_mgr);
856 p_userdata_mgr = NULL;
857 }
858}
859
860/*
861#define DUMP_USER_DATA
862*/
863#ifdef DUMP_USER_DATA
864
865#define MAX_USER_DATA_SIZE 3145728
866static void *user_data_buf;
867static unsigned char *pbuf_start;
868static int total_len;
869static int bskip;
870static int n_userdata_id;
871
872
873static void print_mem_data(unsigned char *pdata,
874 int len,
875 unsigned int flag,
876 unsigned int duration,
877 unsigned int vpts,
878 unsigned int vpts_valid,
879 int rec_id)
880{
881 int nLeft;
882
883 nLeft = len;
884#if 0
885 pr_info("%d len = %d, flag = %d, duration = %d, vpts = 0x%x, vpts_valid = %d\n",
886 rec_id, len, flag,
887 duration, vpts, vpts_valid);
888#endif
889 pr_info("%d len = %d, flag = %d, vpts = 0x%x\n",
890 rec_id, len, flag, vpts);
891
892
893 while (nLeft >= 16) {
894 pr_info("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
895 pdata[0], pdata[1], pdata[2], pdata[3],
896 pdata[4], pdata[5], pdata[6], pdata[7],
897 pdata[8], pdata[9], pdata[10], pdata[11],
898 pdata[12], pdata[13], pdata[14], pdata[15]);
899 nLeft -= 16;
900 pdata += 16;
901 }
902
903
904 while (nLeft > 0) {
905 pr_info("%02x %02x %02x %02x %02x %02x %02x %02x\n",
906 pdata[0], pdata[1], pdata[2], pdata[3],
907 pdata[4], pdata[5], pdata[6], pdata[7]);
908 nLeft -= 8;
909 pdata += 8;
910 }
911}
912
913
914static void dump_data(u8 *pdata,
915 unsigned int user_data_length,
916 unsigned int flag,
917 unsigned int duration,
918 unsigned int vpts,
919 unsigned int vpts_valid,
920 int rec_id)
921{
922 unsigned char szBuf[256];
923
924
925 memset(szBuf, 0, 256);
926 memcpy(szBuf, pdata, user_data_length);
927/*
928 aml_swap_data(szBuf, user_data_length);
929*/
930
931 print_mem_data(szBuf, user_data_length,
932 flag, duration, vpts,
933 vpts_valid, rec_id);
934
935#ifdef DEBUG_CC_DUMP_ASCII
936 dump_cc_ascii(szBuf+7);
937#endif
938}
939
940static void push_to_buf(u8 *pdata, int len, struct userdata_meta_info_t *pmeta)
941{
942 u32 *pLen;
943 int info_cnt;
944 u8 *pbuf_end;
945
946 if (!user_data_buf)
947 return;
948
949 if (bskip) {
950 pr_info("over size, skip\n");
951 return;
952 }
953 info_cnt = 0;
954 pLen = (u32 *)pbuf_start;
955
956 *pLen = len;
957 pbuf_start += sizeof(u32);
958 info_cnt++;
959 pLen++;
960
961 *pLen = pmeta->duration;
962 pbuf_start += sizeof(u32);
963 info_cnt++;
964 pLen++;
965
966 *pLen = pmeta->flags;
967 pbuf_start += sizeof(u32);
968 info_cnt++;
969 pLen++;
970
971 *pLen = pmeta->vpts;
972 pbuf_start += sizeof(u32);
973 info_cnt++;
974 pLen++;
975
976 *pLen = pmeta->vpts_valid;
977 pbuf_start += sizeof(u32);
978 info_cnt++;
979 pLen++;
980
981
982 *pLen = n_userdata_id;
983 pbuf_start += sizeof(u32);
984 info_cnt++;
985 pLen++;
986
987
988
989 pbuf_end = (u8 *)sei_data_buffer + USER_DATA_SIZE;
990 if (pdata + len > pbuf_end) {
991 int first_section_len;
992
993 first_section_len = pbuf_end - pdata;
994 memcpy(pbuf_start, pdata, first_section_len);
995 pdata = (u8 *)sei_data_buffer;
996 pbuf_start += first_section_len;
997 memcpy(pbuf_start, pdata, len - first_section_len);
998 pbuf_start += len - first_section_len;
999 } else {
1000 memcpy(pbuf_start, pdata, len);
1001 pbuf_start += len;
1002 }
1003
1004 total_len += len + info_cnt * sizeof(u32);
1005 if (total_len >= MAX_USER_DATA_SIZE-4096)
1006 bskip = 1;
1007}
1008
1009
1010static void dump_userdata_info(
1011 void *puser_data,
1012 int len,
1013 struct userdata_meta_info_t *pmeta)
1014{
1015 u8 *pstart;
1016
1017 pstart = (u8 *)puser_data;
1018
1019
1020 push_to_buf(pstart, len, pmeta);
1021}
1022
1023static void show_user_data_buf(void)
1024{
1025 u8 *pbuf;
1026 int len;
1027 unsigned int flag;
1028 unsigned int duration;
1029 unsigned int vpts;
1030 unsigned int vpts_valid;
1031 int rec_id;
1032
1033 pr_info("show user data buf\n");
1034 pbuf = user_data_buf;
1035
1036 while (pbuf < pbuf_start) {
1037 u32 *pLen;
1038
1039 pLen = (u32 *)pbuf;
1040
1041 len = *pLen;
1042 pLen++;
1043 pbuf += sizeof(u32);
1044
1045 duration = *pLen;
1046 pLen++;
1047 pbuf += sizeof(u32);
1048
1049 flag = *pLen;
1050 pLen++;
1051 pbuf += sizeof(u32);
1052
1053 vpts = *pLen;
1054 pLen++;
1055 pbuf += sizeof(u32);
1056
1057 vpts_valid = *pLen;
1058 pLen++;
1059 pbuf += sizeof(u32);
1060
1061 rec_id = *pLen;
1062 pLen++;
1063 pbuf += sizeof(u32);
1064
1065 dump_data(pbuf, len, flag, duration, vpts, vpts_valid, rec_id);
1066 pbuf += len;
1067 msleep(30);
1068 }
1069}
1070
1071static int vh264_init_userdata_dump(void)
1072{
1073 user_data_buf = kmalloc(MAX_USER_DATA_SIZE, GFP_KERNEL);
1074 if (user_data_buf)
1075 return 1;
1076 else
1077 return 0;
1078}
1079
1080static void vh264_dump_userdata(void)
1081{
1082 if (user_data_buf) {
1083 show_user_data_buf();
1084 kfree(user_data_buf);
1085 user_data_buf = NULL;
1086 }
1087}
1088
1089static void vh264_reset_user_data_buf(void)
1090{
1091 total_len = 0;
1092 pbuf_start = user_data_buf;
1093 bskip = 0;
1094 n_userdata_id = 0;
1095}
1096#endif
1097
1098static void vh264_add_userdata(struct userdata_meta_info_t meta_info, int wp)
1099{
1100 struct vh264_userdata_recored_t *p_userdata_rec;
1101 int data_length;
1102
1103 mutex_lock(&userdata_mutex);
1104
1105 if (p_userdata_mgr) {
1106 if (wp > p_userdata_mgr->last_wp)
1107 data_length = wp - p_userdata_mgr->last_wp;
1108 else
1109 data_length = wp + p_userdata_mgr->buf_len -
1110 p_userdata_mgr->last_wp;
1111
1112 if (data_length & 0x7)
1113 data_length = (((data_length + 8) >> 3) << 3);
1114#if 0
1115 pr_info("wakeup_push: ri:%d, wi:%d, data_len:%d, last_wp:%d, wp:%d, id = %d\n",
1116 p_userdata_mgr->read_index,
1117 p_userdata_mgr->write_index,
1118 data_length,
1119 p_userdata_mgr->last_wp,
1120 wp,
1121 n_userdata_id);
1122#endif
1123 p_userdata_rec = p_userdata_mgr->records +
1124 p_userdata_mgr->write_index;
1125 p_userdata_rec->meta_info = meta_info;
1126 p_userdata_rec->rec_start = p_userdata_mgr->last_wp;
1127 p_userdata_rec->rec_len = data_length;
1128 p_userdata_mgr->last_wp = wp;
1129
1130#ifdef DUMP_USER_DATA
1131 dump_userdata_info(p_userdata_mgr->data_buf +
1132 p_userdata_rec->rec_start,
1133 data_length,
1134 &meta_info);
1135 n_userdata_id++;
1136#endif
1137
1138 p_userdata_mgr->write_index++;
1139 if (p_userdata_mgr->write_index >= USERDATA_FIFO_NUM)
1140 p_userdata_mgr->write_index = 0;
1141 }
1142 mutex_unlock(&userdata_mutex);
1143
1144 vdec_wakeup_userdata_poll(vdec_h264);
1145}
1146
1147static int vh264_user_data_read(struct vdec_s *vdec,
1148 struct userdata_param_t *puserdata_para)
1149{
1150 int rec_ri, rec_wi;
1151 int rec_len;
1152 u8 *rec_data_start;
1153 u8 *pdest_buf;
1154 struct vh264_userdata_recored_t *p_userdata_rec;
1155 u32 data_size;
1156 u32 res;
1157 int copy_ok = 1;
1158
1159
1160 pdest_buf = puserdata_para->pbuf_addr;
1161
1162
1163 mutex_lock(&userdata_mutex);
1164
1165 if (!p_userdata_mgr) {
1166 mutex_unlock(&userdata_mutex);
1167 return 0;
1168 }
1169/*
1170 pr_info("ri = %d, wi = %d\n",
1171 p_userdata_mgr->read_index,
1172 p_userdata_mgr->write_index);
1173*/
1174 rec_ri = p_userdata_mgr->read_index;
1175 rec_wi = p_userdata_mgr->write_index;
1176
1177 if (rec_ri == rec_wi) {
1178 mutex_unlock(&userdata_mutex);
1179 return 0;
1180 }
1181
1182 p_userdata_rec = p_userdata_mgr->records + rec_ri;
1183
1184 rec_len = p_userdata_rec->rec_len;
1185 rec_data_start = p_userdata_rec->rec_start + p_userdata_mgr->data_buf;
1186/*
1187 pr_info("rec_len:%d, rec_start:%d, buf_len:%d\n",
1188 p_userdata_rec->rec_len,
1189 p_userdata_rec->rec_start,
1190 puserdata_para->buf_len);
1191*/
1192 if (rec_len <= puserdata_para->buf_len) {
1193 /* dvb user data buffer is enought to copy the whole recored. */
1194 data_size = rec_len;
1195 if (rec_data_start + data_size
1196 > p_userdata_mgr->data_buf_end) {
1197 int first_section_len;
1198
1199 first_section_len = p_userdata_mgr->buf_len -
1200 p_userdata_rec->rec_start;
1201 res = (u32)copy_to_user((void *)pdest_buf,
1202 (void *)rec_data_start,
1203 first_section_len);
1204 if (res) {
1205 pr_info("p1 read not end res=%d, request=%d\n",
1206 res, first_section_len);
1207 copy_ok = 0;
1208
1209 p_userdata_rec->rec_len -=
1210 first_section_len - res;
1211 p_userdata_rec->rec_start +=
1212 first_section_len - res;
1213 puserdata_para->data_size =
1214 first_section_len - res;
1215 } else {
1216 res = (u32)copy_to_user(
1217 (void *)(pdest_buf+first_section_len),
1218 (void *)p_userdata_mgr->data_buf,
1219 data_size - first_section_len);
1220 if (res) {
1221 pr_info("p2 read not end res=%d, request=%d\n",
1222 res, data_size);
1223 copy_ok = 0;
1224 }
1225 p_userdata_rec->rec_len -=
1226 data_size - res;
1227 p_userdata_rec->rec_start =
1228 data_size - first_section_len - res;
1229 puserdata_para->data_size =
1230 data_size - res;
1231 }
1232 } else {
1233 res = (u32)copy_to_user((void *)pdest_buf,
1234 (void *)rec_data_start,
1235 data_size);
1236 if (res) {
1237 pr_info("p3 read not end res=%d, request=%d\n",
1238 res, data_size);
1239 copy_ok = 0;
1240 }
1241 p_userdata_rec->rec_len -= data_size - res;
1242 p_userdata_rec->rec_start += data_size - res;
1243 puserdata_para->data_size = data_size - res;
1244 }
1245
1246 if (copy_ok) {
1247 p_userdata_mgr->read_index++;
1248 if (p_userdata_mgr->read_index >= USERDATA_FIFO_NUM)
1249 p_userdata_mgr->read_index = 0;
1250 }
1251 } else {
1252 /* dvb user data buffer is not enought
1253 to copy the whole recored. */
1254 data_size = puserdata_para->buf_len;
1255 if (rec_data_start + data_size
1256 > p_userdata_mgr->data_buf_end) {
1257 int first_section_len;
1258
1259 first_section_len = p_userdata_mgr->buf_len
1260 - p_userdata_rec->rec_start;
1261 res = (u32)copy_to_user((void *)pdest_buf,
1262 (void *)rec_data_start,
1263 first_section_len);
1264 if (res) {
1265 pr_info("p4 read not end res=%d, request=%d\n",
1266 res, first_section_len);
1267 copy_ok = 0;
1268 p_userdata_rec->rec_len -=
1269 first_section_len - res;
1270 p_userdata_rec->rec_start +=
1271 first_section_len - res;
1272 puserdata_para->data_size =
1273 first_section_len - res;
1274 } else {
1275 /* first secton copy is ok*/
1276 res = (u32)copy_to_user(
1277 (void *)(pdest_buf+first_section_len),
1278 (void *)p_userdata_mgr->data_buf,
1279 data_size - first_section_len);
1280 if (res) {
1281 pr_info("p5 read not end res=%d, request=%d\n",
1282 res,
1283 data_size - first_section_len);
1284 copy_ok = 0;
1285 }
1286
1287 p_userdata_rec->rec_len -= data_size - res;
1288 p_userdata_rec->rec_start =
1289 data_size - first_section_len - res;
1290 puserdata_para->data_size = data_size - res;
1291 }
1292 } else {
1293 res = (u32)copy_to_user((void *)pdest_buf,
1294 (void *)rec_data_start,
1295 data_size);
1296 if (res) {
1297 pr_info("p6 read not end res=%d, request=%d\n",
1298 res, data_size);
1299 copy_ok = 0;
1300 }
1301
1302 p_userdata_rec->rec_len -= data_size - res;
1303 p_userdata_rec->rec_start += data_size - res;
1304 puserdata_para->data_size = data_size - res;
1305 }
1306
1307 if (copy_ok) {
1308 p_userdata_mgr->read_index++;
1309 if (p_userdata_mgr->read_index
1310 >= USERDATA_FIFO_NUM)
1311 p_userdata_mgr->read_index = 0;
1312 }
1313
1314 }
1315 puserdata_para->meta_info = p_userdata_rec->meta_info;
1316
1317 if (p_userdata_mgr->read_index <= p_userdata_mgr->write_index)
1318 puserdata_para->meta_info.records_in_que =
1319 p_userdata_mgr->write_index -
1320 p_userdata_mgr->read_index;
1321 else
1322 puserdata_para->meta_info.records_in_que =
1323 p_userdata_mgr->write_index +
1324 USERDATA_FIFO_NUM -
1325 p_userdata_mgr->read_index;
1326
1327 puserdata_para->version = (0<<24|0<<16|0<<8|1);
1328
1329 mutex_unlock(&userdata_mutex);
1330
1331 return 1;
1332}
1333
1334static void vh264_wakeup_userdata_poll(struct vdec_s *vdec)
1335{
1336 amstream_wakeup_userdata_poll(vdec);
1337}
1338
1339static void vh264_reset_userdata_fifo(struct vdec_s *vdec, int bInit)
1340{
1341 mutex_lock(&userdata_mutex);
1342
1343 if (p_userdata_mgr) {
1344 pr_info("h264_reset_userdata_fifo: bInit: %d, ri: %d, wi: %d\n",
1345 bInit, p_userdata_mgr->read_index,
1346 p_userdata_mgr->write_index);
1347 p_userdata_mgr->read_index = 0;
1348 p_userdata_mgr->write_index = 0;
1349
1350 if (bInit)
1351 p_userdata_mgr->last_wp = 0;
1352 }
1353
1354 mutex_unlock(&userdata_mutex);
1355}
1356
1357static void h264_reset_qos_mgr(void)
1358{
1359 int i;
1360
1361 pr_info("h264_reset_qos_mgr\n");
1362
1363 INIT_LIST_HEAD(&free_qos_nodes_list);
1364 INIT_LIST_HEAD(&picture_qos_list);
1365
1366 for (i = 0; i < MAX_FREE_QOS_NODES; i++) {
1367 free_nodes[i].b_offset = 0xFFFFFFFF;
1368
1369 list_add_tail(&free_nodes[i].list,
1370 &free_qos_nodes_list);
1371 }
1372}
1373
1374
1375static void load_qos_data(int pic_number, uint32_t b_offset)
1376{
1377 uint32_t blk88_y_count;
1378 uint32_t blk88_c_count;
1379 uint32_t blk22_mv_count;
1380 uint32_t rdata32;
1381 int32_t mv_hi;
1382 int32_t mv_lo;
1383 uint32_t rdata32_l;
1384 uint32_t mvx_L0_hi;
1385 uint32_t mvy_L0_hi;
1386 uint32_t mvx_L1_hi;
1387 uint32_t mvy_L1_hi;
1388 int64_t value;
1389 uint64_t temp_value;
1390/*
1391#define DEBUG_QOS
1392*/
1393#define SUPPORT_NODE
1394
1395#ifdef SUPPORT_NODE
1396 struct h264_qos_data_node_t *node;
1397 struct h264_qos_data_node_t *tmp;
1398 int bFoundNode = 0;
1399
1400 node = NULL;
1401 if (!list_empty(&picture_qos_list)) {
1402 list_for_each_entry_safe(node, tmp, &picture_qos_list, list) {
1403 if (node->b_offset == b_offset) {
1404 bFoundNode = 1;
1405 break;
1406 }
1407 }
1408 }
1409 /*
1410 pr_info("bFoundNode = %d, node:0x%p\n", bFoundNode, node);
1411 */
1412 if (!bFoundNode) {
1413 if (!list_empty(&free_qos_nodes_list)) {
1414 node = list_entry(
1415 free_qos_nodes_list.next,
1416 struct h264_qos_data_node_t,
1417 list);
1418 /*
1419 pr_info("get a node:0x%p\n", node);
1420 */
1421 } else {
1422 pr_info("there is no qos data node avaible\n");
1423
1424 return;
1425 }
1426 }
1427
1428 node->b_offset = b_offset;
1429 node->poc = pic_number;
1430
1431 node->max_mv = 0;
1432 node->avg_mv = 0;
1433 node->min_mv = 0;
1434
1435 node->max_skip = 0;
1436 node->avg_skip = 0;
1437 node->min_skip = 0;
1438
1439 node->max_qp = 0;
1440 node->avg_qp = 0;
1441 node->min_qp = 0;
1442#endif
1443
1444
1445
1446
1447
1448
1449 /* set rd_idx to 0 */
1450 WRITE_VREG(VDEC_PIC_QUALITY_CTRL, 0);
1451 blk88_y_count = READ_VREG(VDEC_PIC_QUALITY_DATA);
1452 if (blk88_y_count == 0) {
1453#ifdef DEBUG_QOS
1454 pr_info(" [Picture %d Quality] NO Data yet.\n",
1455 pic_number);
1456#endif
1457 /* reset all counts */
1458 WRITE_VREG(VDEC_PIC_QUALITY_CTRL, (1<<8));
1459
1460#ifdef SUPPORT_NODE
1461 list_move(&node->list, &picture_qos_list);
1462#endif
1463 return;
1464 }
1465 /* qp_y_sum */
1466 rdata32 = READ_VREG(VDEC_PIC_QUALITY_DATA);
1467#ifdef DEBUG_QOS
1468 pr_info(" [Picture %d Quality] Y QP AVG : %d (%d/%d)\n",
1469 pic_number, rdata32/blk88_y_count,
1470 rdata32, blk88_y_count);
1471#endif
1472#ifdef SUPPORT_NODE
1473 node->avg_qp = rdata32/blk88_y_count;
1474#endif
1475
1476 /* intra_y_count */
1477 rdata32 = READ_VREG(VDEC_PIC_QUALITY_DATA);
1478#ifdef DEBUG_QOS
1479 pr_info(" [Picture %d Quality] Y intra rate : %d%c (%d)\n",
1480 pic_number, rdata32*100/blk88_y_count,
1481 '%', rdata32);
1482#endif
1483 /* skipped_y_count */
1484 rdata32 = READ_VREG(VDEC_PIC_QUALITY_DATA);
1485#ifdef DEBUG_QOS
1486 pr_info(" [Picture %d Quality] Y skipped rate : %d%c (%d)\n",
1487 pic_number, rdata32*100/blk88_y_count,
1488 '%', rdata32);
1489#endif
1490#ifdef SUPPORT_NODE
1491 node->avg_skip = rdata32*100/blk88_y_count;
1492#endif
1493 /* coeff_non_zero_y_count */
1494 rdata32 = READ_VREG(VDEC_PIC_QUALITY_DATA);
1495#ifdef DEBUG_QOS
1496 pr_info(" [Picture %d Quality] Y ZERO_Coeff rate : %d%c (%d)\n",
1497 pic_number, (100 - rdata32*100/(blk88_y_count*1)),
1498 '%', rdata32);
1499#endif
1500 /* blk66_c_count */
1501 blk88_c_count = READ_VREG(VDEC_PIC_QUALITY_DATA);
1502 if (blk88_c_count == 0) {
1503#ifdef DEBUG_QOS
1504 pr_info(" [Picture %d Quality] NO Data yet.\n",
1505 pic_number);
1506#endif
1507 /* reset all counts */
1508 WRITE_VREG(VDEC_PIC_QUALITY_CTRL, (1<<8));
1509
1510#ifdef SUPPORT_NODE
1511 list_move(&node->list, &picture_qos_list);
1512#endif
1513 return;
1514 }
1515 /* qp_c_sum */
1516 rdata32 = READ_VREG(VDEC_PIC_QUALITY_DATA);
1517#ifdef DEBUG_QOS
1518 pr_info(" [Picture %d Quality] C QP AVG : %d (%d/%d)\n",
1519 pic_number, rdata32/blk88_c_count,
1520 rdata32, blk88_c_count);
1521#endif
1522 /* intra_c_count */
1523 rdata32 = READ_VREG(VDEC_PIC_QUALITY_DATA);
1524#ifdef DEBUG_QOS
1525 pr_info(" [Picture %d Quality] C intra rate : %d%c (%d)\n",
1526 pic_number, rdata32*100/blk88_c_count,
1527 '%', rdata32);
1528#endif
1529 /* skipped_cu_c_count */
1530 rdata32 = READ_VREG(VDEC_PIC_QUALITY_DATA);
1531#ifdef DEBUG_QOS
1532 pr_info(" [Picture %d Quality] C skipped rate : %d%c (%d)\n",
1533 pic_number, rdata32*100/blk88_c_count,
1534 '%', rdata32);
1535#endif
1536 /* coeff_non_zero_c_count */
1537 rdata32 = READ_VREG(VDEC_PIC_QUALITY_DATA);
1538#ifdef DEBUG_QOS
1539 pr_info(" [Picture %d Quality] C ZERO_Coeff rate : %d%c (%d)\n",
1540 pic_number, (100 - rdata32*100/(blk88_c_count*1)),
1541 '%', rdata32);
1542#endif
1543
1544 /* 1'h0, qp_c_max[6:0], 1'h0, qp_c_min[6:0],
1545 1'h0, qp_y_max[6:0], 1'h0, qp_y_min[6:0] */
1546 rdata32 = READ_VREG(VDEC_PIC_QUALITY_DATA);
1547#ifdef DEBUG_QOS
1548 pr_info(" [Picture %d Quality] Y QP min : %d\n",
1549 pic_number, (rdata32>>0)&0xff);
1550#endif
1551#ifdef SUPPORT_NODE
1552 node->min_qp = (rdata32>>0)&0xff;
1553#endif
1554
1555#ifdef DEBUG_QOS
1556 pr_info(" [Picture %d Quality] Y QP max : %d\n",
1557 pic_number, (rdata32>>8)&0xff);
1558#endif
1559#ifdef SUPPORT_NODE
1560 node->max_qp = (rdata32>>8)&0xff;
1561#endif
1562
1563#ifdef DEBUG_QOS
1564 pr_info(" [Picture %d Quality] C QP min : %d\n",
1565 pic_number, (rdata32>>16)&0xff);
1566 pr_info(" [Picture %d Quality] C QP max : %d\n",
1567 pic_number, (rdata32>>24)&0xff);
1568#endif
1569
1570 /* blk22_mv_count */
1571 blk22_mv_count = READ_VREG(VDEC_PIC_QUALITY_DATA);
1572 if (blk22_mv_count == 0) {
1573#ifdef DEBUG_QOS
1574 pr_info(" [Picture %d Quality] NO MV Data yet.\n",
1575 pic_number);
1576#endif
1577 /* reset all counts */
1578 WRITE_VREG(VDEC_PIC_QUALITY_CTRL, (1<<8));
1579#ifdef SUPPORT_NODE
1580 list_move(&node->list, &picture_qos_list);
1581#endif
1582 return;
1583 }
1584 /* mvy_L1_count[39:32], mvx_L1_count[39:32],
1585 mvy_L0_count[39:32], mvx_L0_count[39:32] */
1586 rdata32 = READ_VREG(VDEC_PIC_QUALITY_DATA);
1587 /* should all be 0x00 or 0xff */
1588#ifdef DEBUG_QOS
1589 pr_info(" [Picture %d Quality] MV AVG High Bits: 0x%X\n",
1590 pic_number, rdata32);
1591#endif
1592 mvx_L0_hi = ((rdata32>>0)&0xff);
1593 mvy_L0_hi = ((rdata32>>8)&0xff);
1594 mvx_L1_hi = ((rdata32>>16)&0xff);
1595 mvy_L1_hi = ((rdata32>>24)&0xff);
1596
1597 /* mvx_L0_count[31:0] */
1598 rdata32_l = READ_VREG(VDEC_PIC_QUALITY_DATA);
1599 temp_value = mvx_L0_hi;
1600 temp_value = (temp_value << 32) | rdata32_l;
1601
1602 if (mvx_L0_hi & 0x80)
1603 value = 0xFFFFFFF000000000 | temp_value;
1604 else
1605 value = temp_value;
1606 value = div_s64(value, blk22_mv_count);
1607#ifdef DEBUG_QOS
1608 pr_info(" [Picture %d Quality] MVX_L0 AVG : %d (%lld/%d)\n",
1609 pic_number, (int)(value),
1610 value, blk22_mv_count);
1611#endif
1612#ifdef SUPPORT_NODE
1613 node->avg_mv = value;
1614#endif
1615
1616 /* mvy_L0_count[31:0] */
1617 rdata32_l = READ_VREG(VDEC_PIC_QUALITY_DATA);
1618 temp_value = mvy_L0_hi;
1619 temp_value = (temp_value << 32) | rdata32_l;
1620
1621 if (mvy_L0_hi & 0x80)
1622 value = 0xFFFFFFF000000000 | temp_value;
1623 else
1624 value = temp_value;
1625#ifdef DEBUG_QOS
1626 pr_info(" [Picture %d Quality] MVY_L0 AVG : %d (%lld/%d)\n",
1627 pic_number, rdata32_l/blk22_mv_count,
1628 value, blk22_mv_count);
1629#endif
1630
1631 /* mvx_L1_count[31:0] */
1632 rdata32_l = READ_VREG(VDEC_PIC_QUALITY_DATA);
1633 temp_value = mvx_L1_hi;
1634 temp_value = (temp_value << 32) | rdata32_l;
1635 if (mvx_L1_hi & 0x80)
1636 value = 0xFFFFFFF000000000 | temp_value;
1637 else
1638 value = temp_value;
1639#ifdef DEBUG_QOS
1640 pr_info(" [Picture %d Quality] MVX_L1 AVG : %d (%lld/%d)\n",
1641 pic_number, rdata32_l/blk22_mv_count,
1642 value, blk22_mv_count);
1643#endif
1644
1645 /* mvy_L1_count[31:0] */
1646 rdata32_l = READ_VREG(VDEC_PIC_QUALITY_DATA);
1647 temp_value = mvy_L1_hi;
1648 temp_value = (temp_value << 32) | rdata32_l;
1649 if (mvy_L1_hi & 0x80)
1650 value = 0xFFFFFFF000000000 | temp_value;
1651 else
1652 value = temp_value;
1653#ifdef DEBUG_QOS
1654 pr_info(" [Picture %d Quality] MVY_L1 AVG : %d (%lld/%d)\n",
1655 pic_number, rdata32_l/blk22_mv_count,
1656 value, blk22_mv_count);
1657#endif
1658
1659 /* {mvx_L0_max, mvx_L0_min} // format : {sign, abs[14:0]} */
1660 rdata32 = READ_VREG(VDEC_PIC_QUALITY_DATA);
1661 mv_hi = (rdata32>>16)&0xffff;
1662 if (mv_hi & 0x8000)
1663 mv_hi = 0x8000 - mv_hi;
1664#ifdef DEBUG_QOS
1665 pr_info(" [Picture %d Quality] MVX_L0 MAX : %d\n",
1666 pic_number, mv_hi);
1667#endif
1668#ifdef SUPPORT_NODE
1669 node->max_mv = mv_hi;
1670#endif
1671
1672 mv_lo = (rdata32>>0)&0xffff;
1673 if (mv_lo & 0x8000)
1674 mv_lo = 0x8000 - mv_lo;
1675#ifdef DEBUG_QOS
1676 pr_info(" [Picture %d Quality] MVX_L0 MIN : %d\n",
1677 pic_number, mv_lo);
1678#endif
1679#ifdef SUPPORT_NODE
1680 node->min_mv = mv_lo;
1681#endif
1682
1683#ifdef DEBUG_QOS
1684 /* {mvy_L0_max, mvy_L0_min} */
1685 rdata32 = READ_VREG(VDEC_PIC_QUALITY_DATA);
1686 mv_hi = (rdata32>>16)&0xffff;
1687 if (mv_hi & 0x8000)
1688 mv_hi = 0x8000 - mv_hi;
1689 pr_info(" [Picture %d Quality] MVY_L0 MAX : %d\n",
1690 pic_number, mv_hi);
1691
1692
1693 mv_lo = (rdata32>>0)&0xffff;
1694 if (mv_lo & 0x8000)
1695 mv_lo = 0x8000 - mv_lo;
1696
1697 pr_info(" [Picture %d Quality] MVY_L0 MIN : %d\n",
1698 pic_number, mv_lo);
1699
1700
1701 /* {mvx_L1_max, mvx_L1_min} */
1702 rdata32 = READ_VREG(VDEC_PIC_QUALITY_DATA);
1703 mv_hi = (rdata32>>16)&0xffff;
1704 if (mv_hi & 0x8000)
1705 mv_hi = 0x8000 - mv_hi;
1706
1707 pr_info(" [Picture %d Quality] MVX_L1 MAX : %d\n",
1708 pic_number, mv_hi);
1709
1710
1711 mv_lo = (rdata32>>0)&0xffff;
1712 if (mv_lo & 0x8000)
1713 mv_lo = 0x8000 - mv_lo;
1714
1715 pr_info(" [Picture %d Quality] MVX_L1 MIN : %d\n",
1716 pic_number, mv_lo);
1717
1718
1719 /* {mvy_L1_max, mvy_L1_min} */
1720 rdata32 = READ_VREG(VDEC_PIC_QUALITY_DATA);
1721 mv_hi = (rdata32>>16)&0xffff;
1722 if (mv_hi & 0x8000)
1723 mv_hi = 0x8000 - mv_hi;
1724
1725 pr_info(" [Picture %d Quality] MVY_L1 MAX : %d\n",
1726 pic_number, mv_hi);
1727
1728 mv_lo = (rdata32>>0)&0xffff;
1729 if (mv_lo & 0x8000)
1730 mv_lo = 0x8000 - mv_lo;
1731
1732 pr_info(" [Picture %d Quality] MVY_L1 MIN : %d\n",
1733 pic_number, mv_lo);
1734#endif
1735
1736 rdata32 = READ_VREG(VDEC_PIC_QUALITY_CTRL);
1737#ifdef DEBUG_QOS
1738 pr_info(" [Picture %d Quality] After Read : VDEC_PIC_QUALITY_CTRL : 0x%x\n",
1739 pic_number, rdata32);
1740#endif
1741 /* reset all counts */
1742 WRITE_VREG(VDEC_PIC_QUALITY_CTRL, (1<<8));
1743#ifdef SUPPORT_NODE
1744 list_move(&node->list, &picture_qos_list);
1745#endif
1746}
1747
1748void search_qos_node(struct vframe_qos_s *picture_qos, uint32_t b_offset)
1749{
1750 struct h264_qos_data_node_t *node;
1751 struct h264_qos_data_node_t *tmp;
1752
1753 if (!list_empty(&picture_qos_list)) {
1754 list_for_each_entry_safe(node, tmp, &picture_qos_list, list) {
1755 if (node->b_offset == b_offset) {
1756
1757 picture_qos->avg_mv = node->avg_mv;
1758 picture_qos->min_mv = node->min_mv;
1759 picture_qos->max_mv = node->max_mv;
1760
1761 picture_qos->avg_skip = node->avg_skip;
1762 picture_qos->min_skip = node->min_skip;
1763 picture_qos->max_skip = node->max_skip;
1764
1765 picture_qos->avg_qp = node->avg_qp;
1766 picture_qos->min_qp = node->min_qp;
1767 picture_qos->max_qp = node->max_qp;
1768
1769#if 0
1770 pr_info("POC:%d, mv: max:%d, avg:%d, min:%d\n"
1771 "qp: max:%d, avg:%d, min:%d\n"
1772 "skip: max:%d, avg:%d, min:%d\n",
1773 node->poc,
1774 picture_qos->max_mv,
1775 picture_qos->avg_mv,
1776 picture_qos->min_mv,
1777 picture_qos->max_qp,
1778 picture_qos->avg_qp,
1779 picture_qos->min_qp,
1780 picture_qos->max_skip,
1781 picture_qos->avg_skip,
1782 picture_qos->min_skip);
1783#endif
1784 node->b_offset = 0xFFFFFFFF;
1785 list_move(&node->list, &free_qos_nodes_list);
1786
1787 break;
1788 }
1789 }
1790 }
1791}
1792
1793static void qos_do_work(struct work_struct *work)
1794{
1795 uint32_t poc;
1796 uint32_t bOffset;
1797
1798
1799 poc = READ_VREG(AV_SCRATCH_M);
1800 bOffset = READ_VREG(AV_SCRATCH_L);
1801/*
1802 pr_info("poc:%d, bOffset:0x%x\n", poc, bOffset);
1803*/
1804 load_qos_data(poc, bOffset);
1805
1806
1807 WRITE_VREG(AV_SCRATCH_0, 0);
1808}
1809
1810static void userdata_push_do_work(struct work_struct *work)
1811{
1812 unsigned int sei_itu35_flags;
1813 unsigned int sei_itu35_wp;
1814 unsigned int sei_itu35_data_length;
1815
1816 struct userdata_meta_info_t meta_info;
1817 u32 offset, pts;
1818 u64 pts_us64 = 0;
1819 u32 slice_type;
1820 u32 reg;
1821 u32 poc_number;
1822 u32 picture_struct;
1823
1824 memset(&meta_info, 0, sizeof(meta_info));
1825
1826 meta_info.duration = frame_dur;
1827
1828 reg = READ_VREG(AV_SCRATCH_M);
1829 poc_number = reg & 0x7FFFFFF;
1830 if ((poc_number >> 16) == 0x7FF)
1831 poc_number = (reg & 0x7FFFFFF) - 0x8000000;
1832
1833 slice_type = (reg >> 29) & 0x7;
1834 switch (slice_type) {
1835 case SLICE_TYPE_I:
1836 meta_info.flags |= 1<<7;
1837 break;
1838 case SLICE_TYPE_P:
1839 meta_info.flags |= 3<<7;
1840 break;
1841 case SLICE_TYPE_B:
1842 meta_info.flags |= 2<<7;
1843 break;
1844 }
1845 meta_info.poc_number = poc_number;
1846 picture_struct = (reg >> 27) & 0x3;
1847
1848 meta_info.flags |= (VFORMAT_H264 << 3) | (picture_struct << 12);
1849
1850
1851 offset = READ_VREG(AV_SCRATCH_L);
1852
1853 if (pts_pickout_offset_us64
1854 (PTS_TYPE_VIDEO, offset, &pts, 0, &pts_us64) != 0) {
1855 pr_info("pts pick outfailed, offset:0x%x\n", offset);
1856 pts = -1;
1857 meta_info.vpts_valid = 0;
1858 } else
1859 meta_info.vpts_valid = 1;
1860 meta_info.vpts = pts;
1861/*
1862 pr_info("offset:0x%x, vpts:0x%x, slice:%d, poc:%d\n",
1863 offset, pts, slice_type,
1864 poc_number);
1865*/
1866 sei_itu35_flags = READ_VREG(AV_SCRATCH_J);
1867 sei_itu35_wp = (sei_itu35_flags >> 16) & 0xffff;
1868 sei_itu35_data_length = sei_itu35_flags & 0x7fff;
1869
1870 if (enable_userdata_debug)
1871 udr_dump_data(sei_itu35_wp,
1872 sei_itu35_data_length,
1873 pts, poc_number);
1874
1875
1876 vh264_add_userdata(meta_info, sei_itu35_wp);
1877
1878 WRITE_VREG(AV_SCRATCH_J, 0);
1879}
1880
1881
1882static void set_frame_info(struct vframe_s *vf)
1883{
1884 vf->width = frame_width;
1885 vf->height = frame_height;
1886 vf->duration = frame_dur;
1887 vf->ratio_control =
1888 (min(h264_ar, (u32) DISP_RATIO_ASPECT_RATIO_MAX)) <<
1889 DISP_RATIO_ASPECT_RATIO_BIT;
1890 vf->orientation = vh264_rotation;
1891 vf->flag = 0;
1892
1893#ifdef CONFIG_AMLOGIC_POST_PROCESS_MANAGER_3D_PROCESS
1894 vf->trans_fmt = 0;
1895 if ((vf->trans_fmt == TVIN_TFMT_3D_LRF) ||
1896 (vf->trans_fmt == TVIN_TFMT_3D_LA)) {
1897 vf->left_eye.start_x = 0;
1898 vf->left_eye.start_y = 0;
1899 vf->left_eye.width = frame_width / 2;
1900 vf->left_eye.height = frame_height;
1901
1902 vf->right_eye.start_x = 0;
1903 vf->right_eye.start_y = 0;
1904 vf->right_eye.width = frame_width / 2;
1905 vf->right_eye.height = frame_height;
1906 } else if ((vf->trans_fmt == TVIN_TFMT_3D_LRH_OLER) ||
1907 (vf->trans_fmt == TVIN_TFMT_3D_TB)) {
1908 vf->left_eye.start_x = 0;
1909 vf->left_eye.start_y = 0;
1910 vf->left_eye.width = frame_width / 2;
1911 vf->left_eye.height = frame_height;
1912
1913 vf->right_eye.start_x = 0;
1914 vf->right_eye.start_y = 0;
1915 vf->right_eye.width = frame_width / 2;
1916 vf->right_eye.height = frame_height;
1917 }
1918#endif
1919
1920}
1921
1922#ifdef CONFIG_AMLOGIC_POST_PROCESS_MANAGER
1923static void vh264_ppmgr_reset(void)
1924{
1925 vf_notify_receiver(PROVIDER_NAME, VFRAME_EVENT_PROVIDER_RESET, NULL);
1926
1927 vh264_local_init();
1928
1929 pr_info("vh264dec: vf_ppmgr_reset\n");
1930}
1931#endif
1932
1933static int get_max_dpb_size(int level_idc, int mb_width, int mb_height)
1934{
1935 int size, r;
1936
1937 switch (level_idc) {
1938 case 10:
1939 r = 1485;
1940 break;
1941 case 11:
1942 r = 3375;
1943 break;
1944 case 12:
1945 case 13:
1946 case 20:
1947 r = 8910;
1948 break;
1949 case 21:
1950 r = 17820;
1951 break;
1952 case 22:
1953 case 30:
1954 r = 30375;
1955 break;
1956 case 31:
1957 r = 67500;
1958 break;
1959 case 32:
1960 r = 76800;
1961 break;
1962 case 40:
1963 case 41:
1964 case 42:
1965 r = 122880;
1966 break;
1967 case 50:
1968 r = 414000;
1969 break;
1970 case 51:
1971 case 52:
1972 r = 691200;
1973 break;
1974 default:
1975 return 0;
1976 }
1977 size = (mb_width * mb_height +
1978 (mb_width * mb_height / 2)) * 256 * 10;
1979 r = (r * 1024 + size-1) / size;
1980 r = min(r, 16);
1981 /*pr_info("max_dpb %d size:%d\n", r, size);*/
1982 return r;
1983}
1984static void vh264_set_params(struct work_struct *work)
1985{
1986 int aspect_ratio_info_present_flag, aspect_ratio_idc;
1987 int max_dpb_size, actual_dpb_size, max_reference_size;
1988 int i, mb_mv_byte, ret;
1989 unsigned long addr;
1990 unsigned int post_canvas, buf_size, endian;
1991 unsigned int frame_mbs_only_flag;
1992 unsigned int chroma_format_idc, chroma444, video_signal;
1993 unsigned int crop_infor, crop_bottom, crop_right, level_idc;
1994 if (!atomic_read(&vh264_active))
1995 return;
1996 mutex_lock(&vh264_mutex);
1997 if (vh264_stream_switching_state == SWITCHING_STATE_ON_CMD1)
1998 vh264_stream_switching_state = SWITCHING_STATE_ON_CMD1_PENDING;
1999 post_canvas = get_post_canvas();
2000 clk_adj_frame_count = 0;
2001 /* set to max decoder clock rate at the beginning */
2002
2003 if (vdec_is_support_4k())
2004 vdec_source_changed(VFORMAT_H264, 3840, 2160, 60);
2005 else
2006 vdec_source_changed(VFORMAT_H264, 1920, 1080, 29);
2007
2008 timing_info_present_flag = 0;
2009 mb_width = READ_VREG(AV_SCRATCH_1);
2010 seq_info = READ_VREG(AV_SCRATCH_2);
2011 aspect_ratio_info = READ_VREG(AV_SCRATCH_3);
2012 num_units_in_tick = READ_VREG(AV_SCRATCH_4);
2013 time_scale = READ_VREG(AV_SCRATCH_5);
2014 level_idc = READ_VREG(AV_SCRATCH_A);
2015 if (level_idc > 0)
2016 saved_idc_level = level_idc;
2017 else if (saved_idc_level > 0)
2018 level_idc = saved_idc_level;
2019 video_signal = READ_VREG(AV_SCRATCH_H);
2020 video_signal_from_vui =
2021 ((video_signal & 0xffff) << 8) |
2022 ((video_signal & 0xff0000) >> 16) |
2023 ((video_signal & 0x3f000000));
2024/*
2025 * pr_info("video_signal_type_present_flag 0x%x\n",
2026 * (video_signal_from_vui >> 29) & 1);
2027 * pr_info("video_format 0x%x\n",
2028 * (video_signal_from_vui >> 26) & 7);
2029 * pr_info("video_full_range_flag 0x%x\n",
2030 * (video_signal_from_vui >> 25) & 1);
2031 * pr_info("color_description_present_flag 0x%x\n",
2032 * (video_signal_from_vui >> 24) & 1);
2033 * pr_info("color_primaries 0x%x\n",
2034 * (video_signal_from_vui >> 16) & 0xff);
2035 * pr_info("transfer_characteristic 0x%x\n",
2036 * (video_signal_from_vui >> 8) & 0xff);
2037 * pr_info("matrix_coefficient 0x%x\n",
2038 * video_signal_from_vui & 0xff);
2039 */
2040
2041 mb_total = (mb_width >> 8) & 0xffff;
2042 max_reference_size = (mb_width >> 24) & 0x7f;
2043 mb_mv_byte = (mb_width & 0x80000000) ? 24 : 96;
2044 if (ucode_type == UCODE_IP_ONLY_PARAM)
2045 mb_mv_byte = 96;
2046 mb_width = mb_width & 0xff;
2047 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_GXTVBB) {
2048 if (!mb_width && mb_total)
2049 mb_width = 256;
2050 }
2051 if (mb_width)
2052 mb_height = mb_total / mb_width;
2053 last_duration = 0;
2054 /* AV_SCRATCH_2
2055 * bit 15: frame_mbs_only_flag
2056 * bit 13-14: chroma_format_idc
2057 */
2058 frame_mbs_only_flag = (seq_info >> 15) & 0x01;
2059 chroma_format_idc = (seq_info >> 13) & 0x03;
2060 chroma444 = (chroma_format_idc == 3) ? 1 : 0;
2061
2062 /* @AV_SCRATCH_6.31-16 = (left << 8 | right ) << 1
2063 * @AV_SCRATCH_6.15-0 = (top << 8 | bottom ) <<
2064 * (2 - frame_mbs_only_flag)
2065 */
2066 crop_infor = READ_VREG(AV_SCRATCH_6);
2067 crop_bottom = (crop_infor & 0xff) >> (2 - frame_mbs_only_flag);
2068 crop_right = ((crop_infor >> 16) & 0xff) >> (2 - frame_mbs_only_flag);
2069
2070 /* if width or height from outside is not equal to mb, then use mb */
2071 /* add: for seeking stream with other resolution */
2072 if ((last_mb_width && (last_mb_width != mb_width))
2073 || (mb_width != ((frame_width + 15) >> 4)))
2074 frame_width = 0;
2075 if ((last_mb_height && (last_mb_height != mb_height))
2076 || (mb_height != ((frame_height + 15) >> 4)))
2077 frame_height = 0;
2078 last_mb_width = mb_width;
2079 last_mb_height = mb_height;
2080
2081 if ((frame_width == 0) || (frame_height == 0) || crop_infor) {
2082 frame_width = mb_width << 4;
2083 frame_height = mb_height << 4;
2084 if (frame_mbs_only_flag) {
2085 frame_height =
2086 frame_height - (2 >> chroma444) *
2087 min(crop_bottom,
2088 (unsigned int)((8 << chroma444) - 1));
2089 frame_width =
2090 frame_width - (2 >> chroma444) * min(crop_right,
2091 (unsigned
2092 int)((8 << chroma444) - 1));
2093 } else {
2094 frame_height =
2095 frame_height - (4 >> chroma444) *
2096 min(crop_bottom,
2097 (unsigned int)((8 << chroma444)
2098 - 1));
2099 frame_width =
2100 frame_width - (4 >> chroma444) * min(crop_right,
2101 (unsigned
2102 int)((8 <<
2103 chroma444)
2104 - 1));
2105 }
2106#if 0
2107 pr_info
2108 ("frame_mbs_only_flag %d, crop_bottom %d, frame_height %d, ",
2109 frame_mbs_only_flag, crop_bottom, frame_height);
2110 pr_info
2111 ("mb_height %d,crop_right %d, frame_width %d, mb_width %d\n",
2112 mb_height, crop_right, frame_width, mb_width);
2113#endif
2114 if (frame_height == 1088)
2115 frame_height = 1080;
2116 }
2117
2118 mb_width = (mb_width + 3) & 0xfffffffc;
2119 mb_height = (mb_height + 3) & 0xfffffffc;
2120 mb_total = mb_width * mb_height;
2121
2122 /*max_reference_size <= max_dpb_size <= actual_dpb_size*/
2123 is_4k = (mb_total > 8160) ? true:false;
2124
2125
2126 max_dpb_size = get_max_dpb_size(level_idc, mb_width, mb_height);
2127 if (max_dpb_size < max_reference_size)
2128 max_dpb_size = max_reference_size;
2129 if (max_dpb_size > 15
2130 && get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_GXTVBB
2131 && (codec_mm_get_total_size() < 80 * SZ_1M)) {
2132 actual_dpb_size
2133 = max_reference_size + dpb_size_adj;
2134 if (actual_dpb_size > VF_BUF_NUM)
2135 actual_dpb_size = VF_BUF_NUM;
2136 } else {
2137 actual_dpb_size = max_dpb_size + dpb_size_adj;
2138 actual_dpb_size = min(actual_dpb_size, VF_BUF_NUM);
2139 }
2140 max_reference_size++;
2141 pr_info("actual_dpb_size %d max_dpb_size %d max_ref %d\n",
2142 actual_dpb_size, max_dpb_size,
2143 max_reference_size);
2144 buf_size = mb_total * mb_mv_byte * max_reference_size;
2145
2146 ret = decoder_bmmu_box_alloc_buf_phy(mm_blk_handle, 1,
2147 buf_size, DRIVER_NAME, &addr);
2148
2149 if (ret < 0) {
2150 fatal_error_flag =
2151 DECODER_FATAL_ERROR_NO_MEM;
2152 vh264_running = 0;
2153 mutex_unlock(&vh264_mutex);
2154 return;
2155 }
2156
2157 WRITE_VREG(AV_SCRATCH_1, addr);
2158 WRITE_VREG(AV_SCRATCH_3, post_canvas);
2159 WRITE_VREG(AV_SCRATCH_4, addr + buf_size);
2160
2161 if (!(READ_VREG(AV_SCRATCH_F) & 0x1)) {
2162 for (i = 0; i < actual_dpb_size; i++) {
2163#ifdef DOUBLE_WRITE
2164 int page_count =
2165 PAGE_ALIGN((mb_total << 8) + (mb_total
2166 << 7) + (mb_total << 6) +
2167 (mb_total << 5)) / PAGE_SIZE;
2168#else
2169 int page_count =
2170 PAGE_ALIGN((mb_total << 8) +
2171 (mb_total << 7)) / PAGE_SIZE;
2172#endif
2173
2174 ret = decoder_bmmu_box_alloc_buf_phy(mm_blk_handle,
2175 VF_BUFFER_IDX(i),
2176 page_count << PAGE_SHIFT,
2177 DRIVER_NAME, &buffer_spec[i].phy_addr);
2178
2179 if (ret < 0) {
2180 buffer_spec[i].alloc_count = 0;
2181 fatal_error_flag =
2182 DECODER_FATAL_ERROR_NO_MEM;
2183 vh264_running = 0;
2184 mutex_unlock(&vh264_mutex);
2185 return;
2186 }
2187
2188 addr = buffer_spec[i].phy_addr;
2189 buffer_spec[i].alloc_count = page_count;
2190
2191 if (i <= 21) {
2192 buffer_spec[i].y_addr = addr;
2193 addr += mb_total << 8;
2194 buffer_spec[i].u_addr = addr;
2195 buffer_spec[i].v_addr = addr;
2196 addr += mb_total << 7;
2197 vfbuf_use[i] = 0;
2198
2199 buffer_spec[i].y_canvas_index = 128 + i * 2;
2200 buffer_spec[i].u_canvas_index = 128 + i * 2 + 1;
2201 buffer_spec[i].v_canvas_index = 128 + i * 2 + 1;
2202
2203 buffer_spec[i].y_canvas_width = mb_width << 4;
2204 buffer_spec[i].y_canvas_height = mb_height << 4;
2205 buffer_spec[i].u_canvas_width = mb_width << 4;
2206 buffer_spec[i].u_canvas_height = mb_height << 4;
2207 buffer_spec[i].v_canvas_width = mb_width << 4;
2208 buffer_spec[i].v_canvas_height = mb_height << 4;
2209
2210 endian = (canvas_mode == CANVAS_BLKMODE_LINEAR)?7:0;
2211 canvas_config_ex(128 + i * 2,
2212 buffer_spec[i].y_addr,
2213 mb_width << 4, mb_height << 4,
2214 CANVAS_ADDR_NOWRAP,
2215 canvas_mode, endian);
2216 canvas_config_ex(128 + i * 2 + 1,
2217 buffer_spec[i].u_addr,
2218 mb_width << 4, mb_height << 3,
2219 CANVAS_ADDR_NOWRAP,
2220 canvas_mode, endian);
2221 WRITE_VREG(ANC0_CANVAS_ADDR + i,
2222 spec2canvas(&buffer_spec[i]));
2223 } else {
2224 buffer_spec[i].y_canvas_index =
2225 2 * (i - 21) + 4;
2226 buffer_spec[i].y_addr = addr;
2227 addr += mb_total << 8;
2228 buffer_spec[i].u_canvas_index =
2229 2 * (i - 21) + 5;
2230 buffer_spec[i].v_canvas_index =
2231 2 * (i - 21) + 5;
2232 buffer_spec[i].u_addr = addr;
2233 addr += mb_total << 7;
2234 vfbuf_use[i] = 0;
2235
2236 buffer_spec[i].y_canvas_width = mb_width << 4;
2237 buffer_spec[i].y_canvas_height = mb_height << 4;
2238 buffer_spec[i].u_canvas_width = mb_width << 4;
2239 buffer_spec[i].u_canvas_height = mb_height << 4;
2240 buffer_spec[i].v_canvas_width = mb_width << 4;
2241 buffer_spec[i].v_canvas_height = mb_height << 4;
2242
2243 spec_set_canvas(&buffer_spec[i]
2244 , mb_width << 4, mb_height << 4);
2245 WRITE_VREG(ANC0_CANVAS_ADDR + i
2246 , spec2canvas(&buffer_spec[i]));
2247 }
2248 }
2249 } else {
2250 fatal_error_flag =
2251 DECODER_FATAL_ERROR_NO_MEM;
2252 vh264_running = 0;
2253 mutex_unlock(&vh264_mutex);
2254 pr_err("never be here!!\n");
2255 return;
2256 }
2257
2258 timing_info_present_flag = seq_info & 0x2;
2259 fixed_frame_rate_flag = 0;
2260 aspect_ratio_info_present_flag = seq_info & 0x1;
2261 aspect_ratio_idc = (seq_info >> 16) & 0xff;
2262
2263 if (timing_info_present_flag) {
2264 fixed_frame_rate_flag = seq_info & 0x40;
2265
2266 if (((num_units_in_tick * 120) >= time_scale
2267 && ((!sync_outside) || (!frame_dur))) &&
2268 num_units_in_tick
2269 && time_scale) {
2270 if (use_idr_framerate || !frame_dur
2271 || !duration_from_pts_done || vh264_running) {
2272 u32 frame_dur_es =
2273 div_u64(96000ULL * 2 *
2274 num_units_in_tick,
2275 time_scale);
2276
2277 /* hack to avoid use ES frame duration
2278 * when it's half of the rate from
2279 * system info
2280 */
2281 /* sometimes the encoder is given a wrong
2282 * frame rate but the system side information
2283 *is more reliable
2284 */
2285 if ((frame_dur * 2) != frame_dur_es) {
2286 frame_dur = frame_dur_es;
2287 if (fr_hint_status == VDEC_NEED_HINT) {
2288 schedule_work(&notify_work);
2289 fr_hint_status = VDEC_HINTED;
2290 }
2291 }
2292 }
2293 }
2294 } else
2295 pr_info("H.264: timing_info not present\n");
2296
2297 if (aspect_ratio_info_present_flag) {
2298 if (aspect_ratio_idc == EXTEND_SAR) {
2299 h264_ar =
2300 div_u64(256ULL * (aspect_ratio_info >> 16) *
2301 frame_height,
2302 (aspect_ratio_info & 0xffff) *
2303 frame_width);
2304 } else {
2305 /* pr_info("v264dec: aspect_ratio_idc = %d\n",
2306 * aspect_ratio_idc);
2307 */
2308
2309 switch (aspect_ratio_idc) {
2310 case 1:
2311 h264_ar = 0x100 * frame_height / frame_width;
2312 break;
2313 case 2:
2314 h264_ar = 0x100 * frame_height * 11 /
2315 (frame_width * 12);
2316 break;
2317 case 3:
2318 h264_ar = 0x100 * frame_height * 11 /
2319 (frame_width * 10);
2320 break;
2321 case 4:
2322 h264_ar = 0x100 * frame_height * 11 /
2323 (frame_width * 16);
2324 break;
2325 case 5:
2326 h264_ar = 0x100 * frame_height * 33 /
2327 (frame_width * 40);
2328 break;
2329 case 6:
2330 h264_ar = 0x100 * frame_height * 11 /
2331 (frame_width * 24);
2332 break;
2333 case 7:
2334 h264_ar = 0x100 * frame_height * 11 /
2335 (frame_width * 20);
2336 break;
2337 case 8:
2338 h264_ar = 0x100 * frame_height * 11 /
2339 (frame_width * 32);
2340 break;
2341 case 9:
2342 h264_ar = 0x100 * frame_height * 33 /
2343 (frame_width * 80);
2344 break;
2345 case 10:
2346 h264_ar = 0x100 * frame_height * 11 /
2347 (frame_width * 18);
2348 break;
2349 case 11:
2350 h264_ar = 0x100 * frame_height * 11 /
2351 (frame_width * 15);
2352 break;
2353 case 12:
2354 h264_ar = 0x100 * frame_height * 33 /
2355 (frame_width * 64);
2356 break;
2357 case 13:
2358 h264_ar = 0x100 * frame_height * 99 /
2359 (frame_width * 160);
2360 break;
2361 case 14:
2362 h264_ar = 0x100 * frame_height * 3 /
2363 (frame_width * 4);
2364 break;
2365 case 15:
2366 h264_ar = 0x100 * frame_height * 2 /
2367 (frame_width * 3);
2368 break;
2369 case 16:
2370 h264_ar = 0x100 * frame_height * 1 /
2371 (frame_width * 2);
2372 break;
2373 default:
2374 if (vh264_ratio >> 16) {
2375 h264_ar = (frame_height *
2376 (vh264_ratio & 0xffff) *
2377 0x100 +
2378 ((vh264_ratio >> 16) *
2379 frame_width / 2)) /
2380 ((vh264_ratio >> 16) *
2381 frame_width);
2382 } else {
2383 h264_ar = frame_height * 0x100 /
2384 frame_width;
2385 }
2386 break;
2387 }
2388 }
2389 } else {
2390 pr_info("v264dec: aspect_ratio not available from source\n");
2391 if (vh264_ratio >> 16) {
2392 /* high 16 bit is width, low 16 bit is height */
2393 h264_ar =
2394 ((vh264_ratio & 0xffff) * frame_height * 0x100 +
2395 (vh264_ratio >> 16) * frame_width / 2) /
2396 ((vh264_ratio >> 16) * frame_width);
2397 } else
2398 h264_ar = frame_height * 0x100 / frame_width;
2399 }
2400
2401 WRITE_VREG(AV_SCRATCH_0,
2402 (max_reference_size << 24) | (actual_dpb_size << 16) |
2403 (max_dpb_size << 8));
2404 if (vh264_stream_switching_state != SWITCHING_STATE_OFF) {
2405 vh264_stream_switching_state = SWITCHING_STATE_OFF;
2406 pr_info("Leaving switching mode.\n");
2407 }
2408 mutex_unlock(&vh264_mutex);
2409}
2410
2411static unsigned int pts_inc_by_duration(
2412 unsigned int *new_pts, unsigned int *new_pts_rem)
2413{
2414 unsigned int r, rem;
2415
2416 r = last_pts + DUR2PTS(frame_dur);
2417 rem = last_pts_remainder + DUR2PTS_REM(frame_dur);
2418
2419 if (rem >= 96) {
2420 r++;
2421 rem -= 96;
2422 }
2423
2424 if (new_pts)
2425 *new_pts = r;
2426 if (new_pts_rem)
2427 *new_pts_rem = rem;
2428
2429 return r;
2430}
2431static inline bool vh264_isr_parser(struct vframe_s *vf,
2432 unsigned int pts_valid, unsigned int buffer_index,
2433 unsigned int pts)
2434{
2435 unsigned int pts_duration = 0;
2436
2437 if (h264_first_pts_ready == 0) {
2438 if (pts_valid == 0) {
2439 vfbuf_use[buffer_index]++;
2440 vf->index = buffer_index;
2441 kfifo_put(&recycle_q,
2442 (const struct vframe_s *)vf);
2443 return false;
2444 }
2445
2446 h264pts1 = pts;
2447 h264_pts_count = 0;
2448 h264_first_pts_ready = 1;
2449 } else {
2450 if (pts < h264pts1) {
2451 if (h264_pts_count > 24) {
2452 pr_info("invalid h264pts1, reset\n");
2453 h264pts1 = pts;
2454 h264_pts_count = 0;
2455 }
2456 }
2457 if (pts_valid && (pts > h264pts1) && (h264_pts_count > 24)
2458 && (duration_from_pts_done == 0)) {
2459 unsigned int
2460 old_duration = frame_dur;
2461 h264pts2 = pts;
2462
2463 pts_duration = (h264pts2 - h264pts1) * 16 /
2464 (h264_pts_count * 15);
2465
2466 if ((pts_duration != frame_dur)
2467 && (!pts_outside)) {
2468 if (use_idr_framerate) {
2469 bool pts_c_24 = close_to(pts_duration,
2470 RATE_24_FPS,
2471 RATE_CORRECTION_THRESHOLD);
2472 bool frm_c_25 = close_to(frame_dur,
2473 RATE_25_FPS,
2474 RATE_CORRECTION_THRESHOLD);
2475 bool pts_c_25 = close_to(pts_duration,
2476 RATE_25_FPS,
2477 RATE_CORRECTION_THRESHOLD);
2478 bool frm_c_24 = close_to(frame_dur,
2479 RATE_24_FPS,
2480 RATE_CORRECTION_THRESHOLD);
2481 if ((pts_c_24 && frm_c_25)
2482 || (pts_c_25 && frm_c_24)) {
2483 pr_info
2484 ("H.264:Correct frame dur ");
2485 pr_info
2486 (" from %d to duration based ",
2487 frame_dur);
2488 pr_info
2489 ("on PTS %d ---\n",
2490 pts_duration);
2491 frame_dur = pts_duration;
2492 duration_from_pts_done = 1;
2493 } else if (((frame_dur < 96000 / 240)
2494 && (pts_duration > 96000 / 240))
2495 || (!duration_on_correcting &&
2496 !frm_c_25 && !frm_c_24)) {
2497 /* fft: if the frame rate is
2498 * not regular, use the
2499 * calculate rate insteadof.
2500 */
2501 pr_info
2502 ("H.264:Correct frame dur ");
2503 pr_info
2504 (" from %d to duration based ",
2505 frame_dur);
2506 pr_info
2507 ("on PTS %d ---\n",
2508 pts_duration);
2509 frame_dur = pts_duration;
2510 duration_on_correcting = 1;
2511 }
2512 } else {
2513 if (close_to(pts_duration,
2514 frame_dur, 2000)) {
2515 frame_dur = pts_duration;
2516 pr_info
2517 ("used calculate frame rate,");
2518 pr_info("on duration =%d\n",
2519 frame_dur);
2520 } else {
2521 pr_info
2522 ("don't use calculate frame ");
2523 pr_info
2524 ("rate pts_duration =%d\n",
2525 pts_duration);
2526 }
2527 }
2528 }
2529
2530 if (duration_from_pts_done == 0) {
2531 if (close_to
2532 (pts_duration,
2533 old_duration,
2534 RATE_CORRECTION_THRESHOLD)) {
2535 pr_info
2536 ("finished correct frame dur");
2537 pr_info
2538 (" new=%d,old_duration=%d,cnt=%d\n",
2539 pts_duration,
2540 old_duration,
2541 h264_pts_count);
2542 duration_from_pts_done = 1;
2543 } else { /*not the same,redo it. */
2544 if (!close_to(pts_duration,
2545 old_duration, 1000) &&
2546 !close_to(pts_duration,
2547 frame_dur, 1000) &&
2548 close_to(pts_duration,
2549 last_duration, 200)) {
2550 /* yangle: frame_dur must
2551 * wrong,recover it.
2552 */
2553 frame_dur = pts_duration;
2554 }
2555
2556 pr_info
2557 ("restart correct frame duration ");
2558 pr_info
2559 ("new=%d,old_duration=%d,cnt=%d\n",
2560 pts_duration,
2561 old_duration,
2562 h264_pts_count);
2563 h264pts1 = h264pts2;
2564 h264_pts_count = 0;
2565 duration_from_pts_done = 0;
2566 }
2567 }
2568 last_duration = pts_duration;
2569 }
2570 }
2571 return true;
2572}
2573
2574static inline void h264_update_gvs(void)
2575{
2576 u32 ratio_control;
2577 u32 ar;
2578
2579 if (gvs->frame_height != frame_height) {
2580 gvs->frame_width = frame_width;
2581 gvs->frame_height = frame_height;
2582 }
2583 if (gvs->frame_dur != frame_dur) {
2584 gvs->frame_dur = frame_dur;
2585 if (frame_dur != 0)
2586 gvs->frame_rate = 96000 / frame_dur;
2587 else
2588 gvs->frame_rate = -1;
2589 }
2590 gvs->error_count = READ_VREG(AV_SCRATCH_D);
2591 gvs->status = stat;
2592 if (fatal_error_reset)
2593 gvs->status |= fatal_error_flag;
2594 ar = min_t(u32,
2595 h264_ar,
2596 DISP_RATIO_ASPECT_RATIO_MAX);
2597 ratio_control =
2598 ar << DISP_RATIO_ASPECT_RATIO_BIT;
2599 gvs->ratio_control = ratio_control;
2600}
2601
2602
2603#ifdef HANDLE_H264_IRQ
2604static irqreturn_t vh264_isr(int irq, void *dev_id)
2605#else
2606static void vh264_isr(void)
2607#endif
2608{
2609 unsigned int buffer_index;
2610 struct vframe_s *vf;
2611 unsigned int cpu_cmd;
2612 unsigned int pts, pts_lookup_save, pts_valid_save, pts_valid = 0;
2613 unsigned int pts_us64_valid = 0;
2614 unsigned int framesize;
2615 u64 pts_us64;
2616 bool force_interlaced_frame = false;
2617 unsigned int sei_itu35_flags;
2618
2619 static const unsigned int idr_num =
2620 FIX_FRAME_RATE_CHECK_IDRFRAME_NUM;
2621 static const unsigned int flg_1080_itl =
2622 DEC_CONTROL_FLAG_FORCE_2997_1080P_INTERLACE;
2623 static const unsigned int flg_576_itl =
2624 DEC_CONTROL_FLAG_FORCE_2500_576P_INTERLACE;
2625
2626 WRITE_VREG(ASSIST_MBOX1_CLR_REG, 1);
2627
2628 if (0 == (stat & STAT_VDEC_RUN)) {
2629 pr_info("decoder is not running\n");
2630#ifdef HANDLE_H264_IRQ
2631 return IRQ_HANDLED;
2632#else
2633 return;
2634#endif
2635 }
2636
2637 cpu_cmd = READ_VREG(AV_SCRATCH_0);
2638
2639#ifdef DROP_B_FRAME_FOR_1080P_50_60FPS
2640 if ((frame_dur < 2004) &&
2641 (frame_width >= 1400) &&
2642 (frame_height >= 1000) && (last_interlaced == 0))
2643 SET_VREG_MASK(AV_SCRATCH_F, 0x8);
2644#endif
2645 if ((decoder_force_reset == 1)
2646 || ((error_recovery_mode != 1)
2647 && (no_idr_error_count >= no_idr_error_max)
2648 && (ucode_type != UCODE_IP_ONLY_PARAM))) {
2649 vh264_running = 0;
2650 pr_info("force reset decoder %d!!!\n", no_idr_error_count);
2651 schedule_work(&error_wd_work);
2652 decoder_force_reset = 0;
2653 no_idr_error_count = 0;
2654 } else if ((cpu_cmd & 0xff) == 1) {
2655 if (unlikely
2656 (vh264_running
2657 && (kfifo_len(&newframe_q) != VF_POOL_SIZE))) {
2658 /* a cmd 1 sent during decoding w/o getting a cmd 3. */
2659 /* should not happen but the original code has such
2660 * case, do the same process
2661 */
2662 if ((READ_VREG(AV_SCRATCH_1) & 0xff)
2663 == 1) {/*invalid mb_width*/
2664 vh264_running = 0;
2665 fatal_error_flag = DECODER_FATAL_ERROR_UNKNOWN;
2666 /* this is fatal error, need restart */
2667 pr_info("cmd 1 fatal error happened\n");
2668 schedule_work(&error_wd_work);
2669 } else {
2670 vh264_stream_switching_state = SWITCHING_STATE_ON_CMD1;
2671 pr_info("Enter switching mode cmd1.\n");
2672 schedule_work(&stream_switching_work);
2673 }
2674 return IRQ_HANDLED;
2675 }
2676 pr_info("Enter set parameter cmd1.\n");
2677 schedule_work(&set_parameter_work);
2678 return IRQ_HANDLED;
2679 } else if ((cpu_cmd & 0xff) == 2) {
2680 int frame_mb_only, pic_struct_present, pic_struct, prog_frame,
2681 poc_sel, idr_flag, eos, error;
2682 int i, status, num_frame, b_offset;
2683 int current_error_count, slice_type;
2684
2685 vh264_running = 1;
2686 vh264_no_disp_count = 0;
2687 num_frame = (cpu_cmd >> 8) & 0xff;
2688 frame_mb_only = seq_info & 0x8000;
2689 pic_struct_present = seq_info & 0x10;
2690
2691 current_error_count = READ_VREG(AV_SCRATCH_D);
2692 if (vh264_error_count != current_error_count) {
2693 /* pr_info("decoder error happened, count %d\n",
2694 * current_error_count);
2695 */
2696 vh264_error_count = current_error_count;
2697 }
2698
2699 for (i = 0; (i < num_frame) && (!vh264_eos); i++) {
2700 status = READ_VREG(AV_SCRATCH_1 + i);
2701 buffer_index = status & 0x1f;
2702 error = status & 0x200;
2703 slice_type = (READ_VREG(AV_SCRATCH_H) >> (i * 4)) & 0xf;
2704
2705 if ((error_recovery_mode_use & 2) && error)
2706 check_pts_discontinue = true;
2707 if (ucode_type == UCODE_IP_ONLY_PARAM
2708 && iponly_early_mode)
2709 continue;
2710 if ((p_last_vf != NULL)
2711 && (p_last_vf->index == buffer_index))
2712 continue;
2713
2714 if (buffer_index >= VF_BUF_NUM)
2715 continue;
2716
2717 pic_struct = (status >> 5) & 0x7;
2718 prog_frame = status & 0x100;
2719 poc_sel = status & 0x200;
2720 idr_flag = status & 0x400;
2721 frame_packing_type = (status >> 12) & 0x7;
2722 eos = (status >> 15) & 1;
2723
2724 if (eos)
2725 vh264_eos = 1;
2726
2727 b_offset = (status >> 16) & 0xffff;
2728
2729 if (error)
2730 no_idr_error_count++;
2731 if (idr_flag ||
2732 (!error && (slice_type != SLICE_TYPE_I)))
2733 no_idr_error_count = 0;
2734
2735 if (decoder_debug_flag) {
2736 pr_info
2737 ("slice_type %x idr %x error %x count %d",
2738 slice_type, idr_flag, error,
2739 no_idr_error_count);
2740 pr_info(" prog %x pic_struct %x offset %x\n",
2741 prog_frame, pic_struct, b_offset);
2742 }
2743#ifdef DROP_B_FRAME_FOR_1080P_50_60FPS
2744 last_interlaced = prog_frame ? 0 : 1;
2745#endif
2746 if (kfifo_get(&newframe_q, &vf) == 0) {
2747 pr_info
2748 ("fatal error, no available buffer slot.");
2749 return IRQ_HANDLED;
2750 }
2751
2752 if (clk_adj_frame_count < (VDEC_CLOCK_ADJUST_FRAME + 1))
2753 clk_adj_frame_count++;
2754
2755 set_frame_info(vf);
2756
2757 switch (i) {
2758 case 0:
2759 b_offset |=
2760 (READ_VREG(AV_SCRATCH_A) & 0xffff)
2761 << 16;
2762 break;
2763 case 1:
2764 b_offset |=
2765 READ_VREG(AV_SCRATCH_A) & 0xffff0000;
2766 break;
2767 case 2:
2768 b_offset |=
2769 (READ_VREG(AV_SCRATCH_B) & 0xffff)
2770 << 16;
2771 break;
2772 case 3:
2773 b_offset |=
2774 READ_VREG(AV_SCRATCH_B) & 0xffff0000;
2775 break;
2776 case 4:
2777 b_offset |=
2778 (READ_VREG(AV_SCRATCH_C) & 0xffff)
2779 << 16;
2780 break;
2781 case 5:
2782 b_offset |=
2783 READ_VREG(AV_SCRATCH_C) & 0xffff0000;
2784 break;
2785 default:
2786 break;
2787 }
2788
2789 if (error)
2790 gvs->drop_frame_count++;
2791
2792 /* add 64bit pts us ; */
2793 if (unlikely
2794 ((b_offset == first_offset)
2795 && (first_pts_cached))) {
2796 pts = first_pts;
2797 pts_us64 = first_pts64;
2798 framesize = first_frame_size;
2799 first_pts_cached = false;
2800 pts_valid = 1;
2801 pts_us64_valid = 1;
2802#ifdef DEBUG_PTS
2803 pts_hit++;
2804#endif
2805 } else if (pts_lookup_offset_us64
2806 (PTS_TYPE_VIDEO, b_offset, &pts,
2807 &framesize, 0, &pts_us64) == 0) {
2808 pts_valid = 1;
2809 pts_us64_valid = 1;
2810#ifdef DEBUG_PTS
2811 pts_hit++;
2812#endif
2813 } else {
2814 pts_valid = 0;
2815 pts_us64_valid = 0;
2816 framesize = 0;
2817#ifdef DEBUG_PTS
2818 pts_missed++;
2819#endif
2820 }
2821
2822 if (idr_flag)
2823 s_vframe_qos.type = 4;
2824 else if (slice_type == SLICE_TYPE_I)
2825 s_vframe_qos.type = 1;
2826 else if (slice_type == SLICE_TYPE_P)
2827 s_vframe_qos.type = 2;
2828 else if (slice_type == SLICE_TYPE_B || slice_type == 8)
2829 s_vframe_qos.type = 3;
2830
2831 s_vframe_qos.size = framesize;
2832
2833 if (pts_valid)
2834 s_vframe_qos.pts = pts;
2835 else
2836 s_vframe_qos.pts = last_pts + DUR2PTS(frame_dur);
2837#ifndef ENABLE_SEI_ITU_T35
2838 if (get_cpu_major_id() < AM_MESON_CPU_MAJOR_ID_G12A) {
2839 u32 reg_data;
2840 if (i) {
2841 reg_data = READ_VREG(AV_SCRATCH_N);
2842 s_vframe_qos.max_mv
2843 = (reg_data >> 16) & 0xffff;
2844 s_vframe_qos.avg_mv
2845 = (reg_data >> 8) & 0xff;
2846 s_vframe_qos.min_mv
2847 = reg_data & 0xff;
2848 reg_data = READ_VREG(AV_SCRATCH_L);
2849 s_vframe_qos.max_qp
2850 = (reg_data >> 16) & 0xff;
2851 s_vframe_qos.avg_qp
2852 = (reg_data >> 8) & 0xff;
2853 s_vframe_qos.min_qp
2854 = reg_data & 0xff;
2855 reg_data = READ_VREG(AV_SCRATCH_M);
2856 s_vframe_qos.max_skip
2857 = (reg_data >> 16) & 0xff;
2858 s_vframe_qos.avg_skip
2859 = (reg_data >> 8) & 0xff;
2860 s_vframe_qos.min_skip
2861 = reg_data & 0xff;
2862 } else {
2863 reg_data = READ_VREG(AV_SCRATCH_J);
2864 s_vframe_qos.max_mv
2865 = (reg_data >> 16) & 0xffff;
2866 s_vframe_qos.avg_mv
2867 = (reg_data >> 8) & 0xff;
2868 s_vframe_qos.min_mv
2869 = reg_data & 0xff;
2870 reg_data = READ_VREG(AV_SCRATCH_I);
2871 s_vframe_qos.max_qp
2872 = (reg_data >> 16) & 0xff;
2873 s_vframe_qos.avg_qp
2874 = (reg_data >> 8) & 0xff;
2875 s_vframe_qos.min_qp
2876 = reg_data & 0xff;
2877 reg_data = READ_VREG(AV_SCRATCH_K);
2878 s_vframe_qos.max_skip
2879 = (reg_data >> 16) & 0xff;
2880 s_vframe_qos.avg_skip
2881 = (reg_data >> 8) & 0xff;
2882 s_vframe_qos.min_skip
2883 = reg_data & 0xff;
2884 }
2885 if (decoder_debug_flag&0x2) {
2886 pr_info("max_mv %d avg_mv %d min_mv %d slice_type %d offset %x i = %d\n",
2887 s_vframe_qos.max_mv,
2888 s_vframe_qos.avg_mv,
2889 s_vframe_qos.min_mv,
2890 slice_type,
2891 b_offset,
2892 i);
2893 pr_info("max_qp %d avg_qp %d min_qp %d\n",
2894 s_vframe_qos.max_qp,
2895 s_vframe_qos.avg_qp,
2896 s_vframe_qos.min_qp);
2897 pr_info("max_skip %d avg_skip %d min_skip %d\n",
2898 s_vframe_qos.max_skip,
2899 s_vframe_qos.avg_skip,
2900 s_vframe_qos.min_skip);
2901 }
2902 } else
2903 search_qos_node(&s_vframe_qos, b_offset);
2904#endif
2905 frame_count++;
2906
2907 s_vframe_qos.num = frame_count;
2908 //vdec_fill_frame_info(&s_vframe_qos, 1);
2909
2910 /* on second IDR frame,check the diff between pts
2911 * compute from duration and pts from lookup ,
2912 * if large than frame_dur,we think it is uncorrect.
2913 */
2914 pts_lookup_save = pts;
2915 pts_valid_save = pts_valid;
2916 if (fixed_frame_rate_flag
2917 && (fixed_frame_rate_check_count <=
2918 idr_num)) {
2919 if (idr_flag && pts_valid) {
2920 fixed_frame_rate_check_count++;
2921 /* pr_info("diff:%d\n",
2922 * last_pts - pts_lookup_save);
2923 */
2924 if ((fixed_frame_rate_check_count ==
2925 idr_num) &&
2926 (abs(pts - (last_pts +
2927 DUR2PTS(frame_dur))) >
2928 DUR2PTS(frame_dur))) {
2929 fixed_frame_rate_flag = 0;
2930 pr_info("pts sync mode play\n");
2931 }
2932
2933 if (fixed_frame_rate_flag
2934 && (fixed_frame_rate_check_count
2935 > idr_num)) {
2936 pr_info
2937 ("fix_frame_rate mode play\n");
2938 }
2939 }
2940 }
2941
2942 if (READ_VREG(AV_SCRATCH_F) & 2) {
2943 /* for I only mode, ignore the PTS information
2944 * and only uses frame duration for each I
2945 * frame decoded
2946 */
2947 if (p_last_vf)
2948 pts_valid = 0;
2949 /* also skip frame duration calculation
2950 * based on PTS
2951 */
2952 duration_from_pts_done = 1;
2953 /* and add a default duration for 1/30 second
2954 * if there is no valid frame
2955 * duration available
2956 */
2957 if (frame_dur == 0)
2958 frame_dur = 96000 / 30;
2959 }
2960
2961 if (sync_outside == 0) {
2962 if (!vh264_isr_parser(vf,
2963 pts_valid, buffer_index, pts))
2964 continue;
2965
2966 h264_pts_count++;
2967 } else {
2968 if (!idr_flag)
2969 pts_valid = 0;
2970 }
2971
2972 if (pts_valid && !pts_discontinue) {
2973 pts_discontinue =
2974 (abs(last_pts - pts) >=
2975 tsync_vpts_discontinuity_margin());
2976 }
2977 /* if use_idr_framerate or fixed frame rate, only
2978 * use PTS for IDR frames except for pts discontinue
2979 */
2980 if (timing_info_present_flag &&
2981 frame_dur &&
2982 (use_idr_framerate ||
2983 (fixed_frame_rate_flag != 0))
2984 && pts_valid && h264_first_valid_pts_ready
2985 && (!pts_discontinue)) {
2986 pts_valid =
2987 (slice_type == SLICE_TYPE_I) ? 1 : 0;
2988 }
2989
2990 if (!h264_first_valid_pts_ready && pts_valid) {
2991 h264_first_valid_pts_ready = true;
2992 last_pts = pts - DUR2PTS(frame_dur);
2993 last_pts_remainder = 0;
2994 }
2995 /* calculate PTS of next frame and smooth
2996 * PTS for fixed rate source
2997 */
2998 if (pts_valid) {
2999 if ((fixed_frame_rate_flag) &&
3000 (!pts_discontinue) &&
3001 (abs(pts_inc_by_duration(NULL, NULL)
3002 - pts)
3003 < DUR2PTS(frame_dur))) {
3004 pts = pts_inc_by_duration(&pts,
3005 &last_pts_remainder);
3006 } else
3007 last_pts_remainder = 0;
3008
3009 } else {
3010 if (fixed_frame_rate_flag && !pts_discontinue &&
3011 (fixed_frame_rate_check_count > idr_num) &&
3012 pts_valid_save && (sync_outside == 0) &&
3013 (abs(pts_inc_by_duration(NULL, NULL) - pts)
3014 > DUR2PTS(frame_dur))) {
3015 duration_from_pts_done = 0;
3016 pr_info("recalc frame_dur\n");
3017 } else
3018 pts = pts_inc_by_duration(&pts,
3019 &last_pts_remainder);
3020 pts_valid = 1;
3021 }
3022
3023 if ((dec_control &
3024 flg_1080_itl)
3025 && (frame_width == 1920)
3026 && (frame_height >= 1080)
3027 && (vf->duration == 3203))
3028 force_interlaced_frame = true;
3029 else if ((dec_control &
3030 flg_576_itl)
3031 && (frame_width == 720)
3032 && (frame_height == 576)
3033 && (vf->duration == 3840))
3034 force_interlaced_frame = true;
3035
3036 /* for frames with PTS, check if there is PTS
3037 * discontinue based on previous frames
3038 * (including error frames),
3039 * force no VPTS discontinue reporting if we saw
3040 *errors earlier but only once.
3041 */
3042
3043 /*count info*/
3044 h264_update_gvs();
3045 vdec_count_info(gvs, error, b_offset);
3046 vdec_fill_vdec_frame(vdec_h264, &s_vframe_qos, gvs, vf, 0);
3047
3048 if ((pts_valid) && (check_pts_discontinue)
3049 && (!error)) {
3050 if (pts_discontinue) {
3051 vf->flag = 0;
3052 check_pts_discontinue = false;
3053 } else if ((pts - last_pts) < 90000) {
3054 vf->flag = VFRAME_FLAG_NO_DISCONTINUE;
3055 check_pts_discontinue = false;
3056 }
3057 }
3058
3059 last_pts = pts;
3060
3061 if (fixed_frame_rate_flag
3062 && (fixed_frame_rate_check_count <=
3063 idr_num)
3064 && (sync_outside == 0)
3065 && pts_valid_save)
3066 pts = pts_lookup_save;
3067
3068 if (pic_struct_present) {
3069 if ((pic_struct == PIC_TOP_BOT)
3070 || (pic_struct == PIC_BOT_TOP))
3071 prog_frame = 0;
3072 }
3073
3074 if ((!force_interlaced_frame)
3075 && (prog_frame
3076 || (pic_struct_present
3077 && pic_struct
3078 <= PIC_TRIPLE_FRAME))) {
3079 if (pic_struct_present) {
3080 if (pic_struct == PIC_TOP_BOT_TOP
3081 || pic_struct
3082 == PIC_BOT_TOP_BOT) {
3083 vf->duration +=
3084 vf->duration >> 1;
3085 } else if (pic_struct ==
3086 PIC_DOUBLE_FRAME)
3087 vf->duration += vf->duration;
3088 else if (pic_struct ==
3089 PIC_TRIPLE_FRAME) {
3090 vf->duration +=
3091 vf->duration << 1;
3092 }
3093 }
3094
3095 last_pts =
3096 last_pts + DUR2PTS(vf->duration -
3097 frame_dur);
3098
3099 vf->index = buffer_index;
3100 vf->type =
3101 VIDTYPE_PROGRESSIVE |
3102 VIDTYPE_VIU_FIELD |
3103 VIDTYPE_VIU_NV21;
3104 vf->duration_pulldown = 0;
3105 vf->signal_type = video_signal_from_vui;
3106 vf->index = buffer_index;
3107 vf->pts = (pts_valid) ? pts : 0;
3108 if (pts_us64_valid == 1)
3109 vf->pts_us64 = pts_us64;
3110 else
3111 vf->pts_us64 = div64_u64(((u64)vf->pts)*100, 9);
3112 vf->canvas0Addr = vf->canvas1Addr =
3113 spec2canvas(&buffer_spec[buffer_index]);
3114 vf->type_original = vf->type;
3115 vfbuf_use[buffer_index]++;
3116 vf->mem_handle =
3117 decoder_bmmu_box_get_mem_handle(
3118 mm_blk_handle,
3119 VF_BUFFER_IDX(buffer_index));
3120 decoder_do_frame_check(NULL, vf);
3121 if ((error_recovery_mode_use & 2) && error) {
3122 kfifo_put(&recycle_q,
3123 (const struct vframe_s *)vf);
3124 } else {
3125 p_last_vf = vf;
3126 pts_discontinue = false;
3127 kfifo_put(&delay_display_q,
3128 (const struct vframe_s *)vf);
3129 }
3130 } else {
3131 if (pic_struct_present
3132 && pic_struct == PIC_TOP_BOT)
3133 vf->type = VIDTYPE_INTERLACE_TOP;
3134 else if (pic_struct_present
3135 && pic_struct == PIC_BOT_TOP)
3136 vf->type = VIDTYPE_INTERLACE_BOTTOM;
3137 else {
3138 vf->type =
3139 poc_sel ?
3140 VIDTYPE_INTERLACE_BOTTOM :
3141 VIDTYPE_INTERLACE_TOP;
3142 }
3143 vf->type |= VIDTYPE_VIU_NV21;
3144 vf->type |= VIDTYPE_INTERLACE_FIRST;
3145
3146 high_bandwidth |=
3147 ((codec_mm_get_total_size() < 80 * SZ_1M)
3148 & ((READ_VREG(AV_SCRATCH_N) & 0xf) == 3)
3149 & ((frame_width * frame_height) >= 1920*1080));
3150 if (high_bandwidth)
3151 vf->flag |= VFRAME_FLAG_HIGH_BANDWIDTH;
3152
3153 vf->duration >>= 1;
3154 vf->duration_pulldown = 0;
3155 vf->signal_type = video_signal_from_vui;
3156 vf->index = buffer_index;
3157 vf->pts = (pts_valid) ? pts : 0;
3158 if (pts_us64_valid == 1)
3159 vf->pts_us64 = pts_us64;
3160 else
3161 vf->pts_us64 = div64_u64(((u64)vf->pts)*100, 9);
3162 vf->canvas0Addr = vf->canvas1Addr =
3163 spec2canvas(&buffer_spec[buffer_index]);
3164 vf->type_original = vf->type;
3165 vfbuf_use[buffer_index]++;
3166 vf->ready_jiffies64 = jiffies_64;
3167 vf->mem_handle =
3168 decoder_bmmu_box_get_mem_handle(
3169 mm_blk_handle,
3170 VF_BUFFER_IDX(buffer_index));
3171 decoder_do_frame_check(NULL, vf);
3172 if ((error_recovery_mode_use & 2) && error) {
3173 kfifo_put(&recycle_q,
3174 (const struct vframe_s *)vf);
3175 continue;
3176 } else {
3177 pts_discontinue = false;
3178 kfifo_put(&delay_display_q,
3179 (const struct vframe_s *)vf);
3180 }
3181
3182 if (READ_VREG(AV_SCRATCH_F) & 2)
3183 continue;
3184
3185 if (kfifo_get(&newframe_q, &vf) == 0) {
3186 pr_info
3187 ("fatal error, no avail buffer slot.");
3188 return IRQ_HANDLED;
3189 }
3190
3191 set_frame_info(vf);
3192
3193 if (pic_struct_present
3194 && pic_struct == PIC_TOP_BOT)
3195 vf->type = VIDTYPE_INTERLACE_BOTTOM;
3196 else if (pic_struct_present
3197 && pic_struct == PIC_BOT_TOP)
3198 vf->type = VIDTYPE_INTERLACE_TOP;
3199 else {
3200 vf->type =
3201 poc_sel ?
3202 VIDTYPE_INTERLACE_TOP :
3203 VIDTYPE_INTERLACE_BOTTOM;
3204 }
3205
3206 vf->type |= VIDTYPE_VIU_NV21;
3207 vf->duration >>= 1;
3208 vf->duration_pulldown = 0;
3209 vf->signal_type = video_signal_from_vui;
3210 vf->index = buffer_index;
3211 vf->pts = 0;
3212 vf->pts_us64 = 0;
3213 vf->canvas0Addr = vf->canvas1Addr =
3214 spec2canvas(&buffer_spec[buffer_index]);
3215 vf->type_original = vf->type;
3216 vfbuf_use[buffer_index]++;
3217 if (high_bandwidth)
3218 vf->flag |= VFRAME_FLAG_HIGH_BANDWIDTH;
3219
3220 p_last_vf = vf;
3221 vf->ready_jiffies64 = jiffies_64;
3222 vf->mem_handle =
3223 decoder_bmmu_box_get_mem_handle(
3224 mm_blk_handle,
3225 VF_BUFFER_IDX(buffer_index));
3226 kfifo_put(&delay_display_q,
3227 (const struct vframe_s *)vf);
3228 }
3229 }
3230
3231 WRITE_VREG(AV_SCRATCH_0, 0);
3232 } else if ((cpu_cmd & 0xff) == 3) {
3233 vh264_running = 1;
3234 vh264_stream_switching_state = SWITCHING_STATE_ON_CMD3;
3235
3236 pr_info("Enter switching mode cmd3.\n");
3237 schedule_work(&stream_switching_work);
3238
3239 } else if ((cpu_cmd & 0xff) == 4) {
3240 vh264_running = 1;
3241 /* reserved for slice group */
3242 WRITE_VREG(AV_SCRATCH_0, 0);
3243 } else if ((cpu_cmd & 0xff) == 5) {
3244 vh264_running = 1;
3245 /* reserved for slice group */
3246 WRITE_VREG(AV_SCRATCH_0, 0);
3247 } else if ((cpu_cmd & 0xff) == 6) {
3248 vh264_running = 0;
3249 fatal_error_flag = DECODER_FATAL_ERROR_UNKNOWN;
3250 /* this is fatal error, need restart */
3251 pr_info("fatal error happend\n");
3252 amvdec_stop();
3253 if (!fatal_error_reset)
3254 schedule_work(&error_wd_work);
3255 } else if ((cpu_cmd & 0xff) == 7) {
3256 vh264_running = 0;
3257 frame_width = (READ_VREG(AV_SCRATCH_1) + 1) * 16;
3258 pr_info("Over decoder supported size, width = %d\n",
3259 frame_width);
3260 fatal_error_flag = DECODER_FATAL_ERROR_SIZE_OVERFLOW;
3261 } else if ((cpu_cmd & 0xff) == 8) {
3262 vh264_running = 0;
3263 frame_height = (READ_VREG(AV_SCRATCH_1) + 1) * 16;
3264 pr_info("Over decoder supported size, height = %d\n",
3265 frame_height);
3266 fatal_error_flag = DECODER_FATAL_ERROR_SIZE_OVERFLOW;
3267 } else if ((cpu_cmd & 0xff) == 9) {
3268 first_offset = READ_VREG(AV_SCRATCH_1);
3269 if (pts_lookup_offset_us64
3270 (PTS_TYPE_VIDEO, first_offset, &first_pts,
3271 &first_frame_size, 0,
3272 &first_pts64) == 0)
3273 first_pts_cached = true;
3274 WRITE_VREG(AV_SCRATCH_0, 0);
3275 } else if ((cpu_cmd & 0xff) == 0xa) {
3276 int b_offset;
3277 unsigned int frame_size;
3278
3279 b_offset = READ_VREG(AV_SCRATCH_2);
3280 buffer_index = READ_VREG(AV_SCRATCH_1);
3281 /*pr_info("iponly output %d b_offset %x\n",
3282 * buffer_index,b_offset);
3283 */
3284 if (kfifo_get(&newframe_q, &vf) == 0) {
3285 WRITE_VREG(AV_SCRATCH_0, 0);
3286 pr_info
3287 ("fatal error, no available buffer slot.");
3288 return IRQ_HANDLED;
3289 }
3290 if (pts_lookup_offset_us64 (PTS_TYPE_VIDEO, b_offset,
3291 &pts, &frame_size,
3292 0, &pts_us64) != 0)
3293 vf->pts_us64 = vf->pts = 0;
3294 else {
3295 vf->pts_us64 = pts_us64;
3296 vf->pts = pts;
3297 }
3298 set_frame_info(vf);
3299 vf->type = VIDTYPE_PROGRESSIVE |
3300 VIDTYPE_VIU_FIELD |
3301 VIDTYPE_VIU_NV21;
3302 vf->duration_pulldown = 0;
3303 vf->signal_type = video_signal_from_vui;
3304 vf->index = buffer_index;
3305 vf->canvas0Addr = vf->canvas1Addr =
3306 spec2canvas(&buffer_spec[buffer_index]);
3307 vf->type_original = vf->type;
3308 vf->mem_handle = decoder_bmmu_box_get_mem_handle(
3309 mm_blk_handle,
3310 VF_BUFFER_IDX(buffer_index));
3311 vfbuf_use[buffer_index]++;
3312 p_last_vf = vf;
3313 pts_discontinue = false;
3314 iponly_early_mode = 1;
3315 decoder_do_frame_check(NULL, vf);
3316 kfifo_put(&delay_display_q,
3317 (const struct vframe_s *)vf);
3318 WRITE_VREG(AV_SCRATCH_0, 0);
3319 } else if ((cpu_cmd & 0xff) == 0xB) {
3320 schedule_work(&qos_work);
3321 }
3322
3323 sei_itu35_flags = READ_VREG(AV_SCRATCH_J);
3324 if (sei_itu35_flags & (1 << 15)) { /* data ready */
3325#ifdef ENABLE_SEI_ITU_T35
3326 schedule_work(&userdata_push_work);
3327#else
3328 /* necessary if enabled itu_t35 in ucode*/
3329 WRITE_VREG(AV_SCRATCH_J, 0);
3330#endif
3331 }
3332
3333#ifdef HANDLE_H264_IRQ
3334 return IRQ_HANDLED;
3335#else
3336 return;
3337#endif
3338}
3339
3340static void vh264_set_clk(struct work_struct *work)
3341{
3342 int fps = 96000 / frame_dur;
3343
3344 if (frame_dur < 10) /*dur is too small ,think it errors fps*/
3345 fps = 60;
3346 saved_resolution = frame_width * frame_height * fps;
3347 vdec_source_changed(VFORMAT_H264,
3348 frame_width, frame_height, fps);
3349}
3350
3351static void vh264_put_timer_func(unsigned long arg)
3352{
3353 struct timer_list *timer = (struct timer_list *)arg;
3354 unsigned int wait_buffer_status;
3355 unsigned int wait_i_pass_frames;
3356 unsigned int reg_val;
3357
3358 enum receviver_start_e state = RECEIVER_INACTIVE;
3359
3360 if (vh264_reset) {
3361 pr_info("operation forbidden in timer !\n");
3362 goto exit;
3363 }
3364
3365 prepare_display_q();
3366
3367 if (vf_get_receiver(PROVIDER_NAME)) {
3368 state =
3369 vf_notify_receiver(PROVIDER_NAME,
3370 VFRAME_EVENT_PROVIDER_QUREY_STATE,
3371 NULL);
3372 if ((state == RECEIVER_STATE_NULL)
3373 || (state == RECEIVER_STATE_NONE)) {
3374 /* receiver has no event_cb or receiver's
3375 * event_cb does not process this event
3376 */
3377 state = RECEIVER_INACTIVE;
3378 }
3379 } else
3380 state = RECEIVER_INACTIVE;
3381#ifndef HANDLE_H264_IRQ
3382 vh264_isr();
3383#endif
3384
3385 if (vh264_stream_switching_state != SWITCHING_STATE_OFF)
3386 wait_buffer_counter = 0;
3387 else {
3388 reg_val = READ_VREG(AV_SCRATCH_9);
3389 wait_buffer_status = reg_val & (1 << 31);
3390 wait_i_pass_frames = reg_val & 0xff;
3391 if (wait_buffer_status) {
3392 if (kfifo_is_empty(&display_q) &&
3393 kfifo_is_empty(&delay_display_q) &&
3394 kfifo_is_empty(&recycle_q) &&
3395 (state == RECEIVER_INACTIVE)) {
3396 pr_info("$$$$decoder is waiting for buffer\n");
3397 if (++wait_buffer_counter > 4) {
3398 amvdec_stop();
3399 schedule_work(&error_wd_work);
3400 }
3401 } else
3402 wait_buffer_counter = 0;
3403 } else if (wait_i_pass_frames > 1000) {
3404 pr_info("i passed frames > 1000\n");
3405 amvdec_stop();
3406 schedule_work(&error_wd_work);
3407 }
3408 }
3409
3410#if 0
3411 if (!wait_buffer_status) {
3412 if (vh264_no_disp_count++ > NO_DISP_WD_COUNT) {
3413 pr_info("$$$decoder did not send frame out\n");
3414 amvdec_stop();
3415#ifdef CONFIG_AMLOGIC_POST_PROCESS_MANAGER
3416 vh264_ppmgr_reset();
3417#else
3418 vf_light_unreg_provider(PROVIDER_NAME);
3419 vh264_local_init();
3420 vf_reg_provider(vh264_vf_prov);
3421#endif
3422 vh264_prot_init();
3423 amvdec_start();
3424
3425 vh264_no_disp_count = 0;
3426 vh264_no_disp_wd_count++;
3427 }
3428 }
3429#endif
3430
3431 while (!kfifo_is_empty(&recycle_q) &&
3432 ((READ_VREG(AV_SCRATCH_7) == 0)
3433 || (READ_VREG(AV_SCRATCH_8) == 0))
3434 && (vh264_stream_switching_state == SWITCHING_STATE_OFF)) {
3435 struct vframe_s *vf;
3436
3437 if (kfifo_get(&recycle_q, &vf)) {
3438 if (vf->index < VF_BUF_NUM) {
3439 if (--vfbuf_use[vf->index] == 0) {
3440 if (READ_VREG(AV_SCRATCH_7) == 0) {
3441 WRITE_VREG(AV_SCRATCH_7,
3442 vf->index + 1);
3443 } else {
3444 WRITE_VREG(AV_SCRATCH_8,
3445 vf->index + 1);
3446 }
3447 }
3448
3449 vf->index = VF_BUF_NUM;
3450 kfifo_put(&newframe_q,
3451 (const struct vframe_s *)vf);
3452 }
3453 }
3454 }
3455
3456 if (vh264_stream_switching_state != SWITCHING_STATE_OFF) {
3457 while (!kfifo_is_empty(&recycle_q)) {
3458 struct vframe_s *vf;
3459
3460 if (kfifo_get(&recycle_q, &vf)) {
3461 if (vf->index < VF_BUF_NUM) {
3462 vf->index = VF_BUF_NUM;
3463 kfifo_put(&newframe_q,
3464 (const struct vframe_s *)vf);
3465 }
3466 }
3467 }
3468
3469 WRITE_VREG(AV_SCRATCH_7, 0);
3470 WRITE_VREG(AV_SCRATCH_8, 0);
3471
3472 if (kfifo_len(&newframe_q) == VF_POOL_SIZE)
3473 stream_switching_done();
3474 }
3475
3476 if (ucode_type != UCODE_IP_ONLY_PARAM &&
3477 (clk_adj_frame_count > VDEC_CLOCK_ADJUST_FRAME) &&
3478 frame_dur > 0 && saved_resolution !=
3479 frame_width * frame_height * (96000 / frame_dur))
3480 schedule_work(&set_clk_work);
3481
3482exit:
3483 timer->expires = jiffies + PUT_INTERVAL;
3484
3485 add_timer(timer);
3486}
3487
3488int vh264_dec_status(struct vdec_s *vdec, struct vdec_info *vstatus)
3489{
3490 u32 ratio_control;
3491 u32 ar;
3492
3493 if (!(stat & STAT_VDEC_RUN))
3494 return -1;
3495
3496 vstatus->frame_width = frame_width;
3497 vstatus->frame_height = frame_height;
3498 if (frame_dur != 0)
3499 vstatus->frame_rate = 96000 / frame_dur;
3500 else
3501 vstatus->frame_rate = -1;
3502 vstatus->error_count = READ_VREG(AV_SCRATCH_D);
3503 vstatus->status = stat;
3504 if (fatal_error_reset)
3505 vstatus->status |= fatal_error_flag;
3506 vstatus->bit_rate = gvs->bit_rate;
3507 vstatus->frame_dur = frame_dur;
3508 vstatus->frame_data = gvs->frame_data;
3509 vstatus->total_data = gvs->total_data;
3510 vstatus->frame_count = gvs->frame_count;
3511 vstatus->error_frame_count = gvs->error_frame_count;
3512 vstatus->drop_frame_count = gvs->drop_frame_count;
3513 vstatus->total_data = gvs->total_data;
3514 vstatus->samp_cnt = gvs->samp_cnt;
3515 vstatus->offset = gvs->offset;
3516 ar = min_t(u32,
3517 h264_ar,
3518 DISP_RATIO_ASPECT_RATIO_MAX);
3519 ratio_control =
3520 ar << DISP_RATIO_ASPECT_RATIO_BIT;
3521 vstatus->ratio_control = ratio_control;
3522
3523 snprintf(vstatus->vdec_name, sizeof(vstatus->vdec_name),
3524 "%s", DRIVER_NAME);
3525
3526 return 0;
3527}
3528
3529static int vh264_vdec_info_init(void)
3530{
3531 gvs = kzalloc(sizeof(struct vdec_info), GFP_KERNEL);
3532 if (NULL == gvs) {
3533 pr_info("the struct of vdec status malloc failed.\n");
3534 return -ENOMEM;
3535 }
3536 return 0;
3537}
3538
3539int vh264_set_trickmode(struct vdec_s *vdec, unsigned long trickmode)
3540{
3541 if (trickmode == TRICKMODE_I) {
3542 WRITE_VREG(AV_SCRATCH_F,
3543 (READ_VREG(AV_SCRATCH_F) & 0xfffffffc) | 2);
3544 trickmode_i = 1;
3545 } else if (trickmode == TRICKMODE_NONE) {
3546 WRITE_VREG(AV_SCRATCH_F, READ_VREG(AV_SCRATCH_F) & 0xfffffffc);
3547 trickmode_i = 0;
3548 }
3549
3550 return 0;
3551}
3552
3553int vh264_set_isreset(struct vdec_s *vdec, int isreset)
3554{
3555 is_reset = isreset;
3556 return 0;
3557}
3558
3559static void vh264_prot_init(void)
3560{
3561 ulong timeout = jiffies + HZ;
3562
3563 while (READ_VREG(DCAC_DMA_CTRL) & 0x8000) {
3564 if (time_after(jiffies, timeout)) {
3565 pr_info("%s DCAC_DMA_CTRL time out\n", __func__);
3566 break;
3567 }
3568 }
3569
3570 timeout = jiffies + HZ;
3571 while (READ_VREG(LMEM_DMA_CTRL) & 0x8000) {
3572 if (time_after(jiffies, timeout)) {
3573 pr_info("%s LMEM_DMA_CTRL time out\n", __func__);
3574 break;
3575 }
3576 }
3577
3578#if 1 /* MESON_CPU_TYPE >= MESON_CPU_TYPE_MESON6 */
3579 WRITE_VREG(DOS_SW_RESET0, (1 << 7) | (1 << 6) | (1 << 4));
3580 WRITE_VREG(DOS_SW_RESET0, 0);
3581
3582 READ_VREG(DOS_SW_RESET0);
3583 READ_VREG(DOS_SW_RESET0);
3584 READ_VREG(DOS_SW_RESET0);
3585
3586 WRITE_VREG(DOS_SW_RESET0, (1 << 7) | (1 << 6) | (1 << 4));
3587 WRITE_VREG(DOS_SW_RESET0, 0);
3588
3589 WRITE_VREG(DOS_SW_RESET0, (1 << 9) | (1 << 8));
3590 WRITE_VREG(DOS_SW_RESET0, 0);
3591
3592 READ_VREG(DOS_SW_RESET0);
3593 READ_VREG(DOS_SW_RESET0);
3594 READ_VREG(DOS_SW_RESET0);
3595
3596#else
3597 WRITE_RESET_REG(RESET0_REGISTER,
3598 RESET_IQIDCT | RESET_MC | RESET_VLD_PART);
3599 READ_RESET_REG(RESET0_REGISTER);
3600 WRITE_RESET_REG(RESET0_REGISTER,
3601 RESET_IQIDCT | RESET_MC | RESET_VLD_PART);
3602
3603 WRITE_RESET_REG(RESET2_REGISTER, RESET_PIC_DC | RESET_DBLK);
3604#endif
3605
3606 WRITE_VREG(POWER_CTL_VLD,
3607 READ_VREG(POWER_CTL_VLD) |
3608 (0 << 10) | (1 << 9) | (1 << 6));
3609
3610 /* disable PSCALE for hardware sharing */
3611 WRITE_VREG(PSCALE_CTRL, 0);
3612
3613 WRITE_VREG(AV_SCRATCH_0, 0);
3614 WRITE_VREG(AV_SCRATCH_1, buf_offset);
3615 if (!tee_enabled())
3616 WRITE_VREG(AV_SCRATCH_G, mc_dma_handle);
3617 WRITE_VREG(AV_SCRATCH_7, 0);
3618 WRITE_VREG(AV_SCRATCH_8, 0);
3619 WRITE_VREG(AV_SCRATCH_9, 0);
3620 WRITE_VREG(AV_SCRATCH_N, 0);
3621
3622#ifdef SUPPORT_BAD_MACRO_BLOCK_REDUNDANCY
3623 if (bad_block_scale > 128)
3624 bad_block_scale = 128;
3625 WRITE_VREG(AV_SCRATCH_A, bad_block_scale);
3626#endif
3627
3628 error_recovery_mode_use =
3629 (error_recovery_mode !=
3630 0) ? error_recovery_mode : error_recovery_mode_in;
3631 WRITE_VREG(AV_SCRATCH_F,
3632 (READ_VREG(AV_SCRATCH_F) & 0xffffffc3) |
3633 (READ_VREG(AV_SCRATCH_F) & 0xffffff43) |
3634 ((error_recovery_mode_use & 0x1) << 4));
3635 if (dec_control & DEC_CONTROL_FLAG_DISABLE_FAST_POC)
3636 SET_VREG_MASK(AV_SCRATCH_F, 1 << 7);
3637 /* clear mailbox interrupt */
3638 WRITE_VREG(ASSIST_MBOX1_CLR_REG, 1);
3639
3640 /* enable mailbox interrupt */
3641 WRITE_VREG(ASSIST_MBOX1_MASK, 1);
3642
3643 SET_VREG_MASK(MDEC_PIC_DC_CTRL, 1 << 17);
3644 if (ucode_type == UCODE_IP_ONLY_PARAM)
3645 SET_VREG_MASK(AV_SCRATCH_F, 1 << 6);
3646 else
3647 CLEAR_VREG_MASK(AV_SCRATCH_F, 1 << 6);
3648
3649 WRITE_VREG(AV_SCRATCH_I, (u32)(sei_data_buffer_phys - buf_offset));
3650 WRITE_VREG(AV_SCRATCH_J, 0);
3651 /* #if MESON_CPU_TYPE >= MESON_CPU_TYPE_MESON8 */
3652 if ((get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_M8) && !is_meson_mtvd_cpu()) {
3653 /* pr_info("vh264 meson8 prot init\n"); */
3654 WRITE_VREG(MDEC_PIC_DC_THRESH, 0x404038aa);
3655 }
3656 /* #endif */
3657}
3658
3659static int vh264_local_init(void)
3660{
3661 int i, ret;
3662 u32 size;
3663 unsigned long buf_start;
3664 vh264_ratio = vh264_amstream_dec_info.ratio;
3665 /* vh264_ratio = 0x100; */
3666
3667 vh264_rotation = (((unsigned long) vh264_amstream_dec_info.param)
3668 >> 16) & 0xffff;
3669
3670 frame_prog = 0;
3671 frame_width = vh264_amstream_dec_info.width;
3672 frame_height = vh264_amstream_dec_info.height;
3673 frame_dur = vh264_amstream_dec_info.rate;
3674 pts_outside = ((unsigned long) vh264_amstream_dec_info.param) & 0x01;
3675 sync_outside = ((unsigned long) vh264_amstream_dec_info.param & 0x02)
3676 >> 1;
3677 use_idr_framerate = ((unsigned long) vh264_amstream_dec_info.param
3678 & 0x04) >> 2;
3679 max_refer_buf = !(((unsigned long) vh264_amstream_dec_info.param
3680 & 0x10) >> 4);
3681 if (!vh264_reset) {
3682 if (mm_blk_handle) {
3683 decoder_bmmu_box_free(mm_blk_handle);
3684 mm_blk_handle = NULL;
3685 }
3686
3687 mm_blk_handle = decoder_bmmu_box_alloc_box(
3688 DRIVER_NAME,
3689 0,
3690 MAX_BLK_BUFFERS,
3691 4 + PAGE_SHIFT,
3692 CODEC_MM_FLAGS_CMA_CLEAR |
3693 CODEC_MM_FLAGS_FOR_VDECODER |
3694 tvp_flag);
3695 }
3696 pr_info
3697 ("H264 sysinfo: %dx%d duration=%d, pts_outside=%d \n",
3698 frame_width, frame_height, frame_dur, pts_outside);
3699 pr_debug("sync_outside=%d, use_idr_framerate=%d\n",
3700 sync_outside, use_idr_framerate);
3701
3702 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_GXTVBB)
3703 size = V_BUF_ADDR_OFFSET_NEW;
3704 else
3705 size = V_BUF_ADDR_OFFSET;
3706
3707 ret = decoder_bmmu_box_alloc_buf_phy(mm_blk_handle, 0,
3708 size, DRIVER_NAME, &buf_start);
3709 if (ret < 0)
3710 return ret;
3711
3712 buf_offset = buf_start - DEF_BUF_START_ADDR;
3713
3714 if ((unsigned long) vh264_amstream_dec_info.param & 0x08)
3715 ucode_type = UCODE_IP_ONLY_PARAM;
3716 else
3717 ucode_type = 0;
3718
3719 if ((unsigned long) vh264_amstream_dec_info.param & 0x20)
3720 error_recovery_mode_in = 1;
3721 else
3722 error_recovery_mode_in = 3;
3723
3724 if (!vh264_running) {
3725 last_mb_width = 0;
3726 last_mb_height = 0;
3727 }
3728
3729 for (i = 0; i < VF_BUF_NUM; i++)
3730 vfbuf_use[i] = 0;
3731
3732 INIT_KFIFO(display_q);
3733 INIT_KFIFO(delay_display_q);
3734 INIT_KFIFO(recycle_q);
3735 INIT_KFIFO(newframe_q);
3736
3737 for (i = 0; i < VF_POOL_SIZE; i++) {
3738 const struct vframe_s *vf = &vfpool[i];
3739
3740 vfpool[i].index = VF_BUF_NUM;
3741 vfpool[i].bufWidth = 1920;
3742 kfifo_put(&newframe_q, vf);
3743 }
3744
3745#ifdef DROP_B_FRAME_FOR_1080P_50_60FPS
3746 last_interlaced = 1;
3747#endif
3748 h264_first_pts_ready = 0;
3749 h264_first_valid_pts_ready = false;
3750 h264pts1 = 0;
3751 h264pts2 = 0;
3752 h264_pts_count = 0;
3753 duration_from_pts_done = 0;
3754 vh264_error_count = READ_VREG(AV_SCRATCH_D);
3755
3756 p_last_vf = NULL;
3757 check_pts_discontinue = false;
3758 last_pts = 0;
3759 wait_buffer_counter = 0;
3760 vh264_no_disp_count = 0;
3761 fatal_error_flag = 0;
3762 high_bandwidth = 0;
3763 vh264_stream_switching_state = SWITCHING_STATE_OFF;
3764#ifdef DEBUG_PTS
3765 pts_missed = 0;
3766 pts_hit = 0;
3767#endif
3768 pts_discontinue = false;
3769 no_idr_error_count = 0;
3770
3771 vh264_reset_userdata_fifo(vdec_h264, 1);
3772 h264_reset_qos_mgr();
3773
3774 if (enable_switch_fense) {
3775 for (i = 0; i < ARRAY_SIZE(fense_buffer_spec); i++) {
3776 struct buffer_spec_s *s = &fense_buffer_spec[i];
3777 s->alloc_count = 3 * SZ_1M / PAGE_SIZE;
3778 ret = decoder_bmmu_box_alloc_buf_phy(mm_blk_handle,
3779 FENSE_BUFFER_IDX(i),
3780 3 * SZ_1M, DRIVER_NAME, &s->phy_addr);
3781
3782 if (ret < 0) {
3783 fatal_error_flag =
3784 DECODER_FATAL_ERROR_NO_MEM;
3785 vh264_running = 0;
3786 return ret;
3787 }
3788 s->y_canvas_index = 2 * i;
3789 s->u_canvas_index = 2 * i + 1;
3790 s->v_canvas_index = 2 * i + 1;
3791 }
3792 }
3793 return 0;
3794}
3795
3796static s32 vh264_init(void)
3797{
3798 int ret = 0;
3799 int trickmode_fffb = 0;
3800 int firmwareloaded = 0;
3801
3802 /* pr_info("\nvh264_init\n"); */
3803 init_timer(&recycle_timer);
3804
3805 stat |= STAT_TIMER_INIT;
3806
3807 vh264_running = 0;/* init here to reset last_mb_width&last_mb_height */
3808 vh264_eos = 0;
3809 duration_on_correcting = 0;
3810 first_pts = 0;
3811 first_pts64 = 0;
3812 first_offset = 0;
3813 first_pts_cached = false;
3814 fixed_frame_rate_check_count = 0;
3815 fr_hint_status = VDEC_NO_NEED_HINT;
3816 saved_resolution = 0;
3817 iponly_early_mode = 0;
3818 saved_idc_level = 0;
3819
3820 frame_count = 0;
3821 memset(&s_vframe_qos, 0, sizeof(s_vframe_qos));
3822 /*init vdec status*/
3823 ret = vh264_vdec_info_init();
3824 if (0 != ret)
3825 return -ret;
3826
3827 ret = vh264_local_init();
3828 if (ret < 0)
3829 return ret;
3830 query_video_status(0, &trickmode_fffb);
3831
3832 amvdec_enable();
3833 if (!firmwareloaded && tee_enabled()) {
3834 ret = amvdec_loadmc_ex(VFORMAT_H264, NULL, NULL);
3835 if (ret < 0) {
3836 amvdec_disable();
3837 pr_err("H264: the %s fw loading failed, err: %x\n",
3838 tee_enabled() ? "TEE" : "local", ret);
3839 return ret;
3840 }
3841 } else {
3842 /* -- ucode loading (amrisc and swap code) */
3843 mc_cpu_addr =
3844 dma_alloc_coherent(amports_get_dma_device(), MC_TOTAL_SIZE,
3845 &mc_dma_handle, GFP_KERNEL);
3846 if (!mc_cpu_addr) {
3847 amvdec_disable();
3848 del_timer_sync(&recycle_timer);
3849 pr_err("vh264_init: Can not allocate mc memory.\n");
3850 return -ENOMEM;
3851 }
3852
3853 pr_debug("264 ucode swap area: phyaddr %p, cpu vaddr %p\n",
3854 (void *)mc_dma_handle, mc_cpu_addr);
3855 if (debugfirmware) {
3856 int r0, r1, r2, r3, r4, r5;
3857 char firmwarename[32];
3858
3859 pr_debug("start load debug %d firmware ...\n", debugfirmware);
3860
3861 snprintf(firmwarename, 32, "%s%d", "vh264_mc", debugfirmware);
3862 r0 = amvdec_loadmc_ex(VFORMAT_H264, firmwarename, NULL);
3863
3864#define DEBUGGET_FW(t, name, buf, size, ret)\
3865 do {\
3866 snprintf(firmwarename, 32, "%s%d", name,\
3867 debugfirmware);\
3868 ret = get_decoder_firmware_data(t,\
3869 firmwarename, buf, size);\
3870 } while (0)
3871 /*memcpy((u8 *) mc_cpu_addr + MC_OFFSET_HEADER, vh264_header_mc,
3872 *MC_SWAP_SIZE);
3873 */
3874 DEBUGGET_FW(VFORMAT_H264, "vh264_header_mc",
3875 (u8 *) mc_cpu_addr + MC_OFFSET_HEADER,
3876 MC_SWAP_SIZE, r1);
3877
3878 /*memcpy((u8 *) mc_cpu_addr + MC_OFFSET_DATA, vh264_data_mc,
3879 *MC_SWAP_SIZE);
3880 */
3881 DEBUGGET_FW(VFORMAT_H264, "vh264_data_mc",
3882 (u8 *) mc_cpu_addr + MC_OFFSET_DATA, MC_SWAP_SIZE, r2);
3883 /*memcpy((u8 *) mc_cpu_addr + MC_OFFSET_MMCO, vh264_mmco_mc,
3884 *MC_SWAP_SIZE);
3885 */
3886 DEBUGGET_FW(VFORMAT_H264, "vh264_mmco_mc",
3887 (u8 *) mc_cpu_addr + MC_OFFSET_MMCO, MC_SWAP_SIZE, r3);
3888 /*memcpy((u8 *) mc_cpu_addr + MC_OFFSET_LIST, vh264_list_mc,
3889 *MC_SWAP_SIZE);
3890 */
3891 DEBUGGET_FW(VFORMAT_H264, "vh264_list_mc",
3892 (u8 *) mc_cpu_addr + MC_OFFSET_LIST, MC_SWAP_SIZE, r4);
3893 /*memcpy((u8 *) mc_cpu_addr + MC_OFFSET_SLICE, vh264_slice_mc,
3894 *MC_SWAP_SIZE);
3895 */
3896 DEBUGGET_FW(VFORMAT_H264, "vh264_slice_mc",
3897 (u8 *) mc_cpu_addr + MC_OFFSET_SLICE, MC_SWAP_SIZE, r5);
3898
3899 if (r0 < 0 || r1 < 0 || r2 < 0 || r3 < 0 || r4 < 0 || r5 < 0) {
3900 pr_err("264 load debugfirmware err %d,%d,%d,%d,%d,%d\n",
3901 r0, r1, r2, r3, r4, r5);
3902 amvdec_disable();
3903 if (mc_cpu_addr) {
3904 dma_free_coherent(amports_get_dma_device(),
3905 MC_TOTAL_SIZE, mc_cpu_addr,
3906 mc_dma_handle);
3907 mc_cpu_addr = NULL;
3908 }
3909 return -EBUSY;
3910 }
3911 firmwareloaded = 1;
3912 } else {
3913 int ret = -1;
3914 char *buf = vmalloc(0x1000 * 16);
3915
3916 if (IS_ERR_OR_NULL(buf))
3917 return -ENOMEM;
3918
3919 if (get_firmware_data(VIDEO_DEC_H264, buf) < 0) {
3920 pr_err("get firmware fail.");
3921 vfree(buf);
3922 return -1;
3923 }
3924
3925 ret = amvdec_loadmc_ex(VFORMAT_H264, NULL, buf);
3926 memcpy((u8 *) mc_cpu_addr + MC_OFFSET_HEADER,
3927 buf + 0x4000, MC_SWAP_SIZE);
3928 memcpy((u8 *) mc_cpu_addr + MC_OFFSET_DATA,
3929 buf + 0x2000, MC_SWAP_SIZE);
3930 memcpy((u8 *) mc_cpu_addr + MC_OFFSET_MMCO,
3931 buf + 0x6000, MC_SWAP_SIZE);
3932 memcpy((u8 *) mc_cpu_addr + MC_OFFSET_LIST,
3933 buf + 0x3000, MC_SWAP_SIZE);
3934 memcpy((u8 *) mc_cpu_addr + MC_OFFSET_SLICE,
3935 buf + 0x5000, MC_SWAP_SIZE);
3936
3937 vfree(buf);
3938
3939 if (ret < 0) {
3940 amvdec_disable();
3941 if (mc_cpu_addr) {
3942 dma_free_coherent(amports_get_dma_device(),
3943 MC_TOTAL_SIZE, mc_cpu_addr,
3944 mc_dma_handle);
3945 mc_cpu_addr = NULL;
3946 }
3947 pr_err("H264: the %s fw loading failed, err: %x\n",
3948 tee_enabled() ? "TEE" : "local", ret);
3949 return -EBUSY;
3950 }
3951 }
3952 }
3953
3954 stat |= STAT_MC_LOAD;
3955
3956 /* enable AMRISC side protocol */
3957 vh264_prot_init();
3958
3959#ifdef HANDLE_H264_IRQ
3960 /*TODO irq */
3961
3962 if (vdec_request_irq(VDEC_IRQ_1, vh264_isr,
3963 "vh264-irq", (void *)vh264_dec_id)) {
3964 pr_err("vh264 irq register error.\n");
3965 amvdec_disable();
3966 return -ENOENT;
3967 }
3968#endif
3969
3970 stat |= STAT_ISR_REG;
3971
3972#ifdef CONFIG_AMLOGIC_POST_PROCESS_MANAGER
3973 vf_provider_init(&vh264_vf_prov, PROVIDER_NAME, &vh264_vf_provider_ops,
3974 NULL);
3975 vf_reg_provider(&vh264_vf_prov);
3976 vf_notify_receiver(PROVIDER_NAME, VFRAME_EVENT_PROVIDER_START, NULL);
3977#else
3978 vf_provider_init(&vh264_vf_prov, PROVIDER_NAME, &vh264_vf_provider_ops,
3979 NULL);
3980 vf_reg_provider(&vh264_vf_prov);
3981#endif
3982
3983 if (frame_dur != 0) {
3984 if (!is_reset) {
3985 vf_notify_receiver(PROVIDER_NAME,
3986 VFRAME_EVENT_PROVIDER_FR_HINT,
3987 (void *)((unsigned long)frame_dur));
3988 fr_hint_status = VDEC_HINTED;
3989 }
3990 } else
3991 fr_hint_status = VDEC_NEED_HINT;
3992
3993 stat |= STAT_VF_HOOK;
3994
3995 recycle_timer.data = (ulong) &recycle_timer;
3996 recycle_timer.function = vh264_put_timer_func;
3997 recycle_timer.expires = jiffies + PUT_INTERVAL;
3998
3999 add_timer(&recycle_timer);
4000
4001 stat |= STAT_TIMER_ARM;
4002
4003 vh264_stream_switching_state = SWITCHING_STATE_OFF;
4004
4005 stat |= STAT_VDEC_RUN;
4006 wmb(); /* Ensure fetchbuf contents visible */
4007
4008 /* -- start decoder */
4009 amvdec_start();
4010
4011 init_userdata_fifo();
4012
4013 return 0;
4014}
4015
4016static int vh264_stop(int mode)
4017{
4018
4019
4020 if (stat & STAT_VDEC_RUN) {
4021 amvdec_stop();
4022 stat &= ~STAT_VDEC_RUN;
4023 }
4024
4025 if (stat & STAT_ISR_REG) {
4026 WRITE_VREG(ASSIST_MBOX1_MASK, 0);
4027 /*TODO irq */
4028
4029 vdec_free_irq(VDEC_IRQ_1, (void *)vh264_dec_id);
4030
4031 stat &= ~STAT_ISR_REG;
4032 }
4033
4034 if (stat & STAT_TIMER_ARM) {
4035 del_timer_sync(&recycle_timer);
4036 stat &= ~STAT_TIMER_ARM;
4037 }
4038
4039 if (stat & STAT_VF_HOOK) {
4040 if (mode == MODE_FULL) {
4041 if (fr_hint_status == VDEC_HINTED)
4042 vf_notify_receiver(PROVIDER_NAME,
4043 VFRAME_EVENT_PROVIDER_FR_END_HINT,
4044 NULL);
4045 fr_hint_status = VDEC_NO_NEED_HINT;
4046 }
4047
4048 vf_unreg_provider(&vh264_vf_prov);
4049 stat &= ~STAT_VF_HOOK;
4050 }
4051
4052 if (stat & STAT_MC_LOAD) {
4053 if (mc_cpu_addr != NULL) {
4054 dma_free_coherent(amports_get_dma_device(),
4055 MC_TOTAL_SIZE, mc_cpu_addr,
4056 mc_dma_handle);
4057 mc_cpu_addr = NULL;
4058 }
4059 }
4060 if (sei_data_buffer != NULL) {
4061 dma_free_coherent(
4062 amports_get_dma_device(),
4063 USER_DATA_RUND_SIZE,
4064 sei_data_buffer,
4065 sei_data_buffer_phys);
4066 sei_data_buffer = NULL;
4067 sei_data_buffer_phys = 0;
4068 }
4069 amvdec_disable();
4070 if (mm_blk_handle) {
4071 decoder_bmmu_box_free(mm_blk_handle);
4072 mm_blk_handle = NULL;
4073 }
4074 memset(&fense_buffer_spec, 0, sizeof(fense_buffer_spec));
4075 memset(&buffer_spec, 0, sizeof(buffer_spec));
4076 return 0;
4077}
4078
4079static void wait_vh264_search_done(void)
4080{
4081 u32 vld_rp = READ_VREG(VLD_MEM_VIFIFO_RP);
4082 int count = 0;
4083 do {
4084 usleep_range(100, 500);
4085 if (vld_rp == READ_VREG(VLD_MEM_VIFIFO_RP))
4086 break;
4087 if (count > 2000) {
4088 pr_info("%s, timeout count %d vld_rp 0x%x VLD_MEM_VIFIFO_RP 0x%x\n",
4089 __func__, count, vld_rp, READ_VREG(VLD_MEM_VIFIFO_RP));
4090 break;
4091 } else
4092 vld_rp = READ_VREG(VLD_MEM_VIFIFO_RP);
4093 count++;
4094 } while (1);
4095}
4096
4097
4098static void error_do_work(struct work_struct *work)
4099{
4100
4101 /*
4102 * we need to lock vh264_stop/vh264_init.
4103 * because we will call amvdec_h264_remove on this step;
4104 * then we may call more than once on
4105 * free_irq/deltimer/..and some other.
4106 */
4107 if (atomic_read(&vh264_active)) {
4108 amvdec_stop();
4109 do {
4110 msleep(50);
4111 } while (vh264_stream_switching_state != SWITCHING_STATE_OFF);
4112 wait_vh264_search_done();
4113 vh264_reset = 1;
4114#ifdef CONFIG_AMLOGIC_POST_PROCESS_MANAGER
4115 vh264_ppmgr_reset();
4116#else
4117 vf_light_unreg_provider(&vh264_vf_prov);
4118
4119 vh264_local_init();
4120
4121 vf_reg_provider(&vh264_vf_prov);
4122#endif
4123 vh264_prot_init();
4124 amvdec_start();
4125 vh264_reset = 0;
4126 }
4127}
4128
4129static void stream_switching_done(void)
4130{
4131 int state = vh264_stream_switching_state;
4132
4133 WRITE_VREG(AV_SCRATCH_7, 0);
4134 WRITE_VREG(AV_SCRATCH_8, 0);
4135 WRITE_VREG(AV_SCRATCH_9, 0);
4136
4137 if (state == SWITCHING_STATE_ON_CMD1) {
4138 pr_info("Enter set parameter cmd1 switching_state %x.\n",
4139 vh264_stream_switching_state);
4140 schedule_work(&set_parameter_work);
4141 return;
4142 } else if (state == SWITCHING_STATE_ON_CMD1_PENDING)
4143 return;
4144
4145 vh264_stream_switching_state = SWITCHING_STATE_OFF;
4146
4147 wmb(); /* Ensure fetchbuf contents visible */
4148
4149 if (state == SWITCHING_STATE_ON_CMD3)
4150 WRITE_VREG(AV_SCRATCH_0, 0);
4151
4152 pr_info("Leaving switching mode.\n");
4153}
4154
4155/* construt a new frame as a copy of last frame so frame receiver can
4156 * release all buffer resources to decoder.
4157 */
4158static void stream_switching_do(struct work_struct *work)
4159{
4160 int mb_total_num, mb_width_num, mb_height_num, i = 0;
4161 struct vframe_s *vf = NULL;
4162 u32 y_index, u_index, src_index, des_index, y_desindex, u_desindex;
4163 struct canvas_s csy, csu, cyd;
4164 unsigned long flags;
4165 bool delay = true;
4166
4167 if (!atomic_read(&vh264_active))
4168 return;
4169
4170 if (vh264_stream_switching_state == SWITCHING_STATE_OFF)
4171 return;
4172
4173 spin_lock_irqsave(&prepare_lock, flags);
4174
4175 block_display_q = true;
4176
4177 spin_unlock_irqrestore(&prepare_lock, flags);
4178
4179 mb_total_num = mb_total;
4180 mb_width_num = mb_width;
4181 mb_height_num = mb_height;
4182
4183 while (is_4k || kfifo_len(&delay_display_q) > 2) {
4184 if (kfifo_get(&delay_display_q, &vf)) {
4185 kfifo_put(&display_q,
4186 (const struct vframe_s *)vf);
4187 ATRACE_COUNTER(MODULE_NAME, vf->pts);
4188 vf_notify_receiver(PROVIDER_NAME,
4189 VFRAME_EVENT_PROVIDER_VFRAME_READY, NULL);
4190 } else
4191 break;
4192 }
4193
4194 if (!kfifo_get(&delay_display_q, &vf)) {
4195 vf = p_last_vf;
4196 delay = false;
4197 }
4198
4199 while (vf) {
4200 int buffer_index;
4201
4202 buffer_index = vf->index & 0xff;
4203
4204 /* construct a clone of the frame from last frame */
4205
4206#if 0
4207
4208 pr_info("src yaddr[0x%x] index[%d] width[%d] heigth[%d]\n",
4209 buffer_spec[buffer_index].y_addr,
4210 buffer_spec[buffer_index].y_canvas_index,
4211 buffer_spec[buffer_index].y_canvas_width,
4212 buffer_spec[buffer_index].y_canvas_height);
4213
4214 pr_info("src uaddr[0x%x] index[%d] width[%d] heigth[%d]\n",
4215 buffer_spec[buffer_index].u_addr,
4216 buffer_spec[buffer_index].u_canvas_index,
4217 buffer_spec[buffer_index].u_canvas_width,
4218 buffer_spec[buffer_index].u_canvas_height);
4219#endif
4220 if (EN_SWITCH_FENCE()) {
4221 y_index = buffer_spec[buffer_index].y_canvas_index;
4222 u_index = buffer_spec[buffer_index].u_canvas_index;
4223
4224 canvas_read(y_index, &csy);
4225 canvas_read(u_index, &csu);
4226
4227 canvas_config(fense_buffer_spec[i].y_canvas_index,
4228 fense_buffer_spec[i].phy_addr,
4229 mb_width_num << 4, mb_height_num << 4,
4230 CANVAS_ADDR_NOWRAP,
4231 CANVAS_BLKMODE_LINEAR);
4232 canvas_config(fense_buffer_spec[i].u_canvas_index,
4233 fense_buffer_spec[i].phy_addr +
4234 (mb_total_num << 8),
4235 mb_width_num << 4, mb_height_num << 3,
4236 CANVAS_ADDR_NOWRAP,
4237 CANVAS_BLKMODE_LINEAR);
4238
4239 y_desindex = fense_buffer_spec[i].y_canvas_index;
4240 u_desindex = fense_buffer_spec[i].u_canvas_index;
4241
4242 canvas_read(y_desindex, &cyd);
4243
4244 src_index = ((y_index & 0xff) |
4245 ((u_index << 8) & 0x0000ff00));
4246 des_index = ((y_desindex & 0xff) |
4247 ((u_desindex << 8) & 0x0000ff00));
4248
4249 ge2d_canvas_dup(&csy, &csu, &cyd,
4250 GE2D_FORMAT_M24_NV21,
4251 src_index,
4252 des_index);
4253 }
4254 vf->mem_handle = decoder_bmmu_box_get_mem_handle(
4255 mm_blk_handle,
4256 FENSE_BUFFER_IDX(i));
4257 fense_vf[i] = *vf;
4258 fense_vf[i].index = -1;
4259
4260 if (EN_SWITCH_FENCE())
4261 fense_vf[i].canvas0Addr =
4262 spec2canvas(&fense_buffer_spec[i]);
4263 else
4264 fense_vf[i].flag |= VFRAME_FLAG_SWITCHING_FENSE;
4265
4266 /* send clone to receiver */
4267 kfifo_put(&display_q,
4268 (const struct vframe_s *)&fense_vf[i]);
4269 ATRACE_COUNTER(MODULE_NAME, fense_vf[i].pts);
4270 /* early recycle frames for last session */
4271 if (delay)
4272 vh264_vf_put(vf, NULL);
4273
4274 vf_notify_receiver(PROVIDER_NAME,
4275 VFRAME_EVENT_PROVIDER_VFRAME_READY, NULL);
4276
4277 i++;
4278
4279 if (!kfifo_get(&delay_display_q, &vf))
4280 break;
4281 }
4282
4283 block_display_q = false;
4284
4285 pr_info("Switching fense frame post\n");
4286}
4287
4288static int amvdec_h264_probe(struct platform_device *pdev)
4289{
4290 struct vdec_s *pdata = *(struct vdec_s **)pdev->dev.platform_data;
4291
4292 mutex_lock(&vh264_mutex);
4293
4294 if (pdata == NULL) {
4295 pr_info("\namvdec_h264 memory resource undefined.\n");
4296 mutex_unlock(&vh264_mutex);
4297 return -EFAULT;
4298 }
4299 canvas_mode = pdata->canvas_mode;
4300 tvp_flag = vdec_secure(pdata) ? CODEC_MM_FLAGS_TVP : 0;
4301 if (pdata->sys_info)
4302 vh264_amstream_dec_info = *pdata->sys_info;
4303 if (sei_data_buffer == NULL) {
4304 sei_data_buffer =
4305 dma_alloc_coherent(amports_get_dma_device(),
4306 USER_DATA_RUND_SIZE,
4307 &sei_data_buffer_phys, GFP_KERNEL);
4308 if (!sei_data_buffer) {
4309 pr_info("%s: Can not allocate sei_data_buffer\n",
4310 __func__);
4311 mutex_unlock(&vh264_mutex);
4312 return -ENOMEM;
4313 }
4314 /* pr_info("buffer 0x%x, phys 0x%x, remap 0x%x\n",
4315 * sei_data_buffer, sei_data_buffer_phys,
4316 * (u32)sei_data_buffer_remap);
4317 */
4318 }
4319 pdata->dec_status = vh264_dec_status;
4320 pdata->set_trickmode = vh264_set_trickmode;
4321 pdata->set_isreset = vh264_set_isreset;
4322
4323 pdata->user_data_read = vh264_user_data_read;
4324 pdata->reset_userdata_fifo = vh264_reset_userdata_fifo;
4325 pdata->wakeup_userdata_poll = vh264_wakeup_userdata_poll;
4326
4327 is_reset = 0;
4328 clk_adj_frame_count = 0;
4329 if (vh264_init() < 0) {
4330 pr_info("\namvdec_h264 init failed.\n");
4331 kfree(gvs);
4332 gvs = NULL;
4333 pdata->dec_status = NULL;
4334 mutex_unlock(&vh264_mutex);
4335 return -ENODEV;
4336 }
4337 vdec_h264 = pdata;
4338 vh264_crate_userdata_manager(sei_data_buffer, USER_DATA_SIZE);
4339 vh264_reset_userdata_fifo(vdec_h264, 1);
4340
4341#ifdef DUMP_USER_DATA
4342 vh264_init_userdata_dump();
4343 vh264_reset_user_data_buf();
4344#endif
4345
4346 INIT_WORK(&error_wd_work, error_do_work);
4347 INIT_WORK(&stream_switching_work, stream_switching_do);
4348 INIT_WORK(&set_parameter_work, vh264_set_params);
4349 INIT_WORK(&notify_work, vh264_notify_work);
4350 INIT_WORK(&set_clk_work, vh264_set_clk);
4351 INIT_WORK(&userdata_push_work, userdata_push_do_work);
4352 INIT_WORK(&qos_work, qos_do_work);
4353
4354
4355
4356 atomic_set(&vh264_active, 1);
4357
4358 mutex_unlock(&vh264_mutex);
4359 vdec_set_vframe_comm(pdata, DRIVER_NAME);
4360
4361 return 0;
4362}
4363
4364static int amvdec_h264_remove(struct platform_device *pdev)
4365{
4366 atomic_set(&vh264_active, 0);
4367 cancel_work_sync(&set_parameter_work);
4368 cancel_work_sync(&error_wd_work);
4369 cancel_work_sync(&stream_switching_work);
4370 cancel_work_sync(&notify_work);
4371 cancel_work_sync(&userdata_push_work);
4372 cancel_work_sync(&qos_work);
4373
4374
4375 vh264_stop(MODE_FULL);
4376 wait_vh264_search_done();
4377 vdec_source_changed(VFORMAT_H264, 0, 0, 0);
4378#ifdef DUMP_USER_DATA
4379 vh264_dump_userdata();
4380#endif
4381 vh264_destroy_userdata_manager();
4382 atomic_set(&vh264_active, 0);
4383#ifdef DEBUG_PTS
4384 pr_info
4385 ("pts missed %ld, pts hit %ld, pts_outside %d, duration %d, ",
4386 pts_missed, pts_hit, pts_outside, frame_dur);
4387 pr_info("sync_outside %d, use_idr_framerate %d\n",
4388 sync_outside, use_idr_framerate);
4389#endif
4390 kfree(gvs);
4391 gvs = NULL;
4392 cancel_work_sync(&set_clk_work);
4393 mutex_unlock(&vh264_mutex);
4394 return 0;
4395}
4396
4397/****************************************/
4398#ifdef CONFIG_PM
4399static int h264_suspend(struct device *dev)
4400{
4401 amvdec_suspend(to_platform_device(dev), dev->power.power_state);
4402 return 0;
4403}
4404
4405static int h264_resume(struct device *dev)
4406{
4407 amvdec_resume(to_platform_device(dev));
4408 return 0;
4409}
4410
4411static const struct dev_pm_ops h264_pm_ops = {
4412 SET_SYSTEM_SLEEP_PM_OPS(h264_suspend, h264_resume)
4413};
4414#endif
4415
4416static struct platform_driver amvdec_h264_driver = {
4417 .probe = amvdec_h264_probe,
4418 .remove = amvdec_h264_remove,
4419 .driver = {
4420 .name = DRIVER_NAME,
4421#ifdef CONFIG_PM
4422 .pm = &h264_pm_ops,
4423#endif
4424 }
4425};
4426
4427static struct codec_profile_t amvdec_h264_profile = {
4428 .name = "h264",
4429 .profile = ""
4430};
4431
4432
4433static struct mconfig h264_configs[] = {
4434 MC_PU32("stat", &stat),
4435 MC_PU32("error_recovery_mode", &error_recovery_mode),
4436 MC_PU32("sync_outside", &sync_outside),
4437 MC_PU32("dec_control", &dec_control),
4438 MC_PU32("fatal_error_reset", &fatal_error_reset),
4439 MC_PU32("max_refer_buf", &max_refer_buf),
4440 MC_PU32("ucode_type", &ucode_type),
4441 MC_PU32("debugfirmware", &debugfirmware),
4442 MC_PU32("fixed_frame_rate_flag", &fixed_frame_rate_flag),
4443 MC_PU32("decoder_debug_flag", &decoder_debug_flag),
4444 MC_PU32("dpb_size_adj", &dpb_size_adj),
4445 MC_PU32("decoder_force_reset", &decoder_force_reset),
4446 MC_PU32("no_idr_error_max", &no_idr_error_max),
4447 MC_PU32("enable_switch_fense", &enable_switch_fense),
4448};
4449static struct mconfig_node h264_node;
4450
4451
4452static int __init amvdec_h264_driver_init_module(void)
4453{
4454 pr_debug("amvdec_h264 module init\n");
4455
4456 ge2d_videoh264task_init();
4457
4458 if (platform_driver_register(&amvdec_h264_driver)) {
4459 pr_err("failed to register amvdec_h264 driver\n");
4460 return -ENODEV;
4461 }
4462 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_GXTVBB
4463 && (codec_mm_get_total_size() > 80 * SZ_1M)) {
4464 amvdec_h264_profile.profile = "4k";
4465 }
4466 vcodec_profile_register(&amvdec_h264_profile);
4467 INIT_REG_NODE_CONFIGS("media.decoder", &h264_node,
4468 "h264", h264_configs, CONFIG_FOR_RW);
4469 return 0;
4470}
4471
4472static void __exit amvdec_h264_driver_remove_module(void)
4473{
4474 pr_debug("amvdec_h264 module remove.\n");
4475
4476 platform_driver_unregister(&amvdec_h264_driver);
4477
4478 ge2d_videoh264task_release();
4479}
4480
4481/****************************************/
4482
4483module_param(stat, uint, 0664);
4484MODULE_PARM_DESC(stat, "\n amvdec_h264 stat\n");
4485module_param(error_recovery_mode, uint, 0664);
4486MODULE_PARM_DESC(error_recovery_mode, "\n amvdec_h264 error_recovery_mode\n");
4487module_param(sync_outside, uint, 0664);
4488MODULE_PARM_DESC(sync_outside, "\n amvdec_h264 sync_outside\n");
4489module_param(dec_control, uint, 0664);
4490MODULE_PARM_DESC(dec_control, "\n amvdec_h264 decoder control\n");
4491module_param(frame_count, uint, 0664);
4492MODULE_PARM_DESC(frame_count,
4493 "\n amvdec_h264 decoded total count\n");
4494module_param(fatal_error_reset, uint, 0664);
4495MODULE_PARM_DESC(fatal_error_reset,
4496 "\n amvdec_h264 decoder reset when fatal error happens\n");
4497module_param(max_refer_buf, uint, 0664);
4498MODULE_PARM_DESC(max_refer_buf,
4499 "\n amvdec_h264 dec buffering or not for reference frame\n");
4500module_param(ucode_type, uint, 0664);
4501MODULE_PARM_DESC(ucode_type,
4502 "\n amvdec_h264 dec buffering or not for reference frame\n");
4503module_param(debugfirmware, uint, 0664);
4504MODULE_PARM_DESC(debugfirmware, "\n amvdec_h264 debug load firmware\n");
4505module_param(fixed_frame_rate_flag, uint, 0664);
4506MODULE_PARM_DESC(fixed_frame_rate_flag,
4507 "\n amvdec_h264 fixed_frame_rate_flag\n");
4508module_param(decoder_debug_flag, uint, 0664);
4509MODULE_PARM_DESC(decoder_debug_flag,
4510 "\n amvdec_h264 decoder_debug_flag\n");
4511
4512module_param(dpb_size_adj, uint, 0664);
4513MODULE_PARM_DESC(dpb_size_adj,
4514 "\n amvdec_h264 dpb_size_adj\n");
4515
4516
4517module_param(decoder_force_reset, uint, 0664);
4518MODULE_PARM_DESC(decoder_force_reset,
4519 "\n amvdec_h264 decoder force reset\n");
4520module_param(no_idr_error_max, uint, 0664);
4521MODULE_PARM_DESC(no_idr_error_max,
4522 "\n print no_idr_error_max\n");
4523module_param(enable_switch_fense, uint, 0664);
4524MODULE_PARM_DESC(enable_switch_fense,
4525 "\n enable switch fense\n");
4526
4527#ifdef SUPPORT_BAD_MACRO_BLOCK_REDUNDANCY
4528module_param(bad_block_scale, uint, 0664);
4529MODULE_PARM_DESC(bad_block_scale,
4530 "\n print bad_block_scale\n");
4531#endif
4532
4533module_param(enable_userdata_debug, uint, 0664);
4534MODULE_PARM_DESC(enable_userdata_debug,
4535 "\n enable_userdata_debug\n");
4536
4537
4538module_init(amvdec_h264_driver_init_module);
4539module_exit(amvdec_h264_driver_remove_module);
4540
4541MODULE_DESCRIPTION("AMLOGIC H264 Video Decoder Driver");
4542MODULE_LICENSE("GPL");
4543MODULE_AUTHOR("Chen Zhang <chen.zhang@amlogic.com>");
4544