2 * drivers/amlogic/amports/vvp9.c
4 * Copyright (C) 2015 Amlogic, Inc. All rights reserved.
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.
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
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <linux/errno.h>
22 #include <linux/interrupt.h>
23 #include <linux/semaphore.h>
24 #include <linux/delay.h>
25 #include <linux/timer.h>
26 #include <linux/kfifo.h>
27 #include <linux/kthread.h>
28 #include <linux/spinlock.h>
29 #include <linux/platform_device.h>
30 #include <linux/amlogic/media/vfm/vframe.h>
31 #include <linux/amlogic/media/utils/amstream.h>
32 #include <linux/amlogic/media/utils/vformat.h>
33 #include <linux/amlogic/media/frame_sync/ptsserv.h>
34 #include <linux/amlogic/media/canvas/canvas.h>
35 #include <linux/amlogic/media/vfm/vframe_provider.h>
36 #include <linux/amlogic/media/vfm/vframe_receiver.h>
37 #include <linux/dma-mapping.h>
38 #include <linux/dma-contiguous.h>
39 #include <linux/slab.h>
40 #include <linux/amlogic/tee.h>
41 #include "../../../stream_input/amports/amports_priv.h"
42 #include <linux/amlogic/media/codec_mm/codec_mm.h>
43 #include "../utils/decoder_mmu_box.h"
44 #include "../utils/decoder_bmmu_box.h"
46 #define MEM_NAME "codec_vp9"
47 /* #include <mach/am_regs.h> */
48 #include <linux/amlogic/media/utils/vdec_reg.h>
49 #include "../utils/vdec.h"
50 #include "../utils/amvdec.h"
51 #ifdef CONFIG_AMLOGIC_MEDIA_MULTI_DEC
52 #include "../utils/vdec_profile.h"
55 #include <linux/amlogic/media/video_sink/video.h>
56 #include <linux/amlogic/media/codec_mm/configs.h>
57 #include "../utils/config_parser.h"
58 #include "../utils/firmware.h"
59 #include "../../../common/chips/decoder_cpu_ver_info.h"
60 #include "../utils/vdec_v4l2_buffer_ops.h"
61 #include <media/v4l2-mem2mem.h>
63 #define MIX_STREAM_SUPPORT
68 /*#define SUPPORT_FB_DECODING*/
69 /*#define FB_DECODING_TEST_SCHEDULE*/
72 #define HW_MASK_FRONT 0x1
73 #define HW_MASK_BACK 0x2
75 #define VP9D_MPP_REFINFO_TBL_ACCCONFIG 0x3442
76 #define VP9D_MPP_REFINFO_DATA 0x3443
77 #define VP9D_MPP_REF_SCALE_ENBL 0x3441
78 #define HEVC_MPRED_CTRL4 0x324c
79 #define HEVC_CM_HEADER_START_ADDR 0x3628
80 #define HEVC_DBLK_CFGB 0x350b
81 #define HEVCD_MPP_ANC2AXI_TBL_DATA 0x3464
82 #define HEVC_SAO_MMU_VH1_ADDR 0x363b
83 #define HEVC_SAO_MMU_VH0_ADDR 0x363a
85 #define HEVC_MV_INFO 0x310d
86 #define HEVC_QP_INFO 0x3137
87 #define HEVC_SKIP_INFO 0x3136
89 #define VP9_10B_DEC_IDLE 0
90 #define VP9_10B_DEC_FRAME_HEADER 1
91 #define VP9_10B_DEC_SLICE_SEGMENT 2
92 #define VP9_10B_DECODE_SLICE 5
93 #define VP9_10B_DISCARD_NAL 6
94 #define VP9_DUMP_LMEM 7
95 #define HEVC_DECPIC_DATA_DONE 0xa
96 #define HEVC_DECPIC_DATA_ERROR 0xb
97 #define HEVC_NAL_DECODE_DONE 0xe
98 #define HEVC_DECODE_BUFEMPTY 0x20
99 #define HEVC_DECODE_TIMEOUT 0x21
100 #define HEVC_SEARCH_BUFEMPTY 0x22
101 #define HEVC_DECODE_OVER_SIZE 0x23
102 #define HEVC_S2_DECODING_DONE 0x50
103 #define VP9_HEAD_PARSER_DONE 0xf0
104 #define VP9_HEAD_SEARCH_DONE 0xf1
106 #define HEVC_ACTION_DONE 0xff
108 #define VF_POOL_SIZE 32
111 #define pr_info printk
113 #define DECODE_MODE_SINGLE ((0x80 << 24) | 0)
114 #define DECODE_MODE_MULTI_STREAMBASE ((0x80 << 24) | 1)
115 #define DECODE_MODE_MULTI_FRAMEBASE ((0x80 << 24) | 2)
116 #define DECODE_MODE_SINGLE_LOW_LATENCY ((0x80 << 24) | 3)
117 #define DECODE_MODE_MULTI_FRAMEBASE_NOHEAD ((0x80 << 24) | 4)
119 #define VP9_TRIGGER_FRAME_DONE 0x100
120 #define VP9_TRIGGER_FRAME_ENABLE 0x200
122 #define MV_MEM_UNIT 0x240
123 /*---------------------------------------------------
124 * Include "parser_cmd.h"
125 *---------------------------------------------------
127 #define PARSER_CMD_SKIP_CFG_0 0x0000090b
129 #define PARSER_CMD_SKIP_CFG_1 0x1b14140f
131 #define PARSER_CMD_SKIP_CFG_2 0x001b1910
133 #define PARSER_CMD_NUMBER 37
135 /*#define HEVC_PIC_STRUCT_SUPPORT*/
136 /* to remove, fix build error */
138 /*#define CODEC_MM_FLAGS_FOR_VDECODER 0*/
140 #define MULTI_INSTANCE_SUPPORT
141 #define SUPPORT_10BIT
142 /* #define ERROR_HANDLE_DEBUG */
145 #define STAT_KTHREAD 0x40
148 #ifdef MULTI_INSTANCE_SUPPORT
149 #define MAX_DECODE_INSTANCE_NUM 9
150 #define MULTI_DRIVER_NAME "ammvdec_vp9"
151 static unsigned int max_decode_instance_num
152 = MAX_DECODE_INSTANCE_NUM
;
153 static unsigned int decode_frame_count
[MAX_DECODE_INSTANCE_NUM
];
154 static unsigned int display_frame_count
[MAX_DECODE_INSTANCE_NUM
];
155 static unsigned int max_process_time
[MAX_DECODE_INSTANCE_NUM
];
156 static unsigned int run_count
[MAX_DECODE_INSTANCE_NUM
];
157 static unsigned int input_empty
[MAX_DECODE_INSTANCE_NUM
];
158 static unsigned int not_run_ready
[MAX_DECODE_INSTANCE_NUM
];
160 static u32 decode_timeout_val
= 200;
161 static int start_decode_buf_level
= 0x8000;
162 static u32 work_buf_size
;
164 static u32 mv_buf_margin
;
166 /* DOUBLE_WRITE_MODE is enabled only when NV21 8 bit output is needed */
167 /* double_write_mode:
168 * 0, no double write;
170 * 2, (1/4):(1/4) ratio;
171 * 3, (1/4):(1/4) ratio, with both compressed frame included
172 * 4, (1/2):(1/2) ratio;
173 * 0x10, double write only
174 * 0x100, if > 1080p,use mode 4,else use mode 1;
175 * 0x200, if > 1080p,use mode 2,else use mode 1;
176 * 0x300, if > 720p, use mode 4, else use mode 1;
178 static u32 double_write_mode
;
180 #define DRIVER_NAME "amvdec_vp9"
181 #define MODULE_NAME "amvdec_vp9"
182 #define DRIVER_HEADER_NAME "amvdec_vp9_header"
185 #define PUT_INTERVAL (HZ/100)
186 #define ERROR_SYSTEM_RESET_COUNT 200
189 #define PTS_NONE_REF_USE_DURATION 1
191 #define PTS_MODE_SWITCHING_THRESHOLD 3
192 #define PTS_MODE_SWITCHING_RECOVERY_THREASHOLD 3
194 #define DUR2PTS(x) ((x)*90/96)
197 static int vvp9_vf_states(struct vframe_states
*states
, void *);
198 static struct vframe_s
*vvp9_vf_peek(void *);
199 static struct vframe_s
*vvp9_vf_get(void *);
200 static void vvp9_vf_put(struct vframe_s
*, void *);
201 static int vvp9_event_cb(int type
, void *data
, void *private_data
);
203 static int vvp9_stop(struct VP9Decoder_s
*pbi
);
204 #ifdef MULTI_INSTANCE_SUPPORT
205 static s32
vvp9_init(struct vdec_s
*vdec
);
207 static s32
vvp9_init(struct VP9Decoder_s
*pbi
);
209 static void vvp9_prot_init(struct VP9Decoder_s
*pbi
, u32 mask
);
210 static int vvp9_local_init(struct VP9Decoder_s
*pbi
);
211 static void vvp9_put_timer_func(unsigned long arg
);
212 static void dump_data(struct VP9Decoder_s
*pbi
, int size
);
213 static unsigned char get_data_check_sum
214 (struct VP9Decoder_s
*pbi
, int size
);
215 static void dump_pic_list(struct VP9Decoder_s
*pbi
);
216 static int vp9_alloc_mmu(
217 struct VP9Decoder_s
*pbi
,
221 unsigned short bit_depth
,
222 unsigned int *mmu_index_adr
);
225 static const char vvp9_dec_id
[] = "vvp9-dev";
227 #define PROVIDER_NAME "decoder.vp9"
228 #define MULTI_INSTANCE_PROVIDER_NAME "vdec.vp9"
230 static const struct vframe_operations_s vvp9_vf_provider
= {
231 .peek
= vvp9_vf_peek
,
234 .event_cb
= vvp9_event_cb
,
235 .vf_states
= vvp9_vf_states
,
238 static struct vframe_provider_s vvp9_vf_prov
;
240 static u32 bit_depth_luma
;
241 static u32 bit_depth_chroma
;
242 static u32 frame_width
;
243 static u32 frame_height
;
244 static u32 video_signal_type
;
246 static u32 on_no_keyframe_skiped
;
248 #define PROB_SIZE (496 * 2 * 4)
249 #define PROB_BUF_SIZE (0x5000)
250 #define COUNT_BUF_SIZE (0x300 * 4 * 4)
251 /*compute_losless_comp_body_size(4096, 2304, 1) = 18874368(0x1200000)*/
252 #define MAX_FRAME_4K_NUM 0x1200
253 #define MAX_FRAME_8K_NUM 0x4800
255 #define HEVC_ASSIST_MMU_MAP_ADDR 0x3009
257 #ifdef SUPPORT_FB_DECODING
258 /* register define */
259 #define HEVC_ASSIST_HED_FB_W_CTL 0x3006
260 #define HEVC_ASSIST_HED_FB_R_CTL 0x3007
261 #define HEVC_ASSIST_HED_FB_ADDR 0x3008
262 #define HEVC_ASSIST_FB_MMU_MAP_ADDR 0x300a
263 #define HEVC_ASSIST_FBD_MMU_MAP_ADDR 0x300b
266 #define MAX_STAGE_PAGE_NUM 0x1200
267 #define STAGE_MMU_MAP_SIZE (MAX_STAGE_PAGE_NUM * 4)
269 static inline int div_r32(int64_t m
, int n
)
286 unsigned int alloc_flag
;
288 unsigned int cma_page_count
;
289 unsigned long alloc_addr
;
290 unsigned long start_adr
;
293 unsigned int free_start_adr
;
294 ulong v4l_ref_buf_addr
;
301 unsigned long start_adr
;
306 /* #undef BUFMGR_ONLY to enable hardware configuration */
308 /*#define TEST_WR_PTR_INC*/
309 /*#define WR_PTR_INC_NUM 128*/
310 #define WR_PTR_INC_NUM 1
314 #undef MEMORY_MAP_IN_REAL_CHIP
316 /*#undef DOS_PROJECT*/
317 /*#define MEMORY_MAP_IN_REAL_CHIP*/
319 /*#define BUFFER_MGR_ONLY*/
320 /*#define CONFIG_HEVC_CLK_FORCED_ON*/
321 /*#define ENABLE_SWAP_TEST*/
324 #define VP9_LPF_LVL_UPDATE
325 /*#define DBG_LF_PRINT*/
329 #define LOSLESS_COMPRESS_MODE
332 #define DOUBLE_WRITE_YSTART_TEMP 0x02000000
333 #define DOUBLE_WRITE_CSTART_TEMP 0x02900000
337 typedef unsigned int u32
;
338 typedef unsigned short u16
;
340 #define VP9_DEBUG_BUFMGR 0x01
341 #define VP9_DEBUG_BUFMGR_MORE 0x02
342 #define VP9_DEBUG_BUFMGR_DETAIL 0x04
343 #define VP9_DEBUG_OUT_PTS 0x10
344 #define VP9_DEBUG_SEND_PARAM_WITH_REG 0x100
345 #define VP9_DEBUG_MERGE 0x200
346 #define VP9_DEBUG_DBG_LF_PRINT 0x400
347 #define VP9_DEBUG_REG 0x800
348 #define VP9_DEBUG_2_STAGE 0x1000
349 #define VP9_DEBUG_2_STAGE_MORE 0x2000
350 #define VP9_DEBUG_QOS_INFO 0x4000
351 #define VP9_DEBUG_DIS_LOC_ERROR_PROC 0x10000
352 #define VP9_DEBUG_DIS_SYS_ERROR_PROC 0x20000
353 #define VP9_DEBUG_DUMP_PIC_LIST 0x40000
354 #define VP9_DEBUG_TRIG_SLICE_SEGMENT_PROC 0x80000
355 #define VP9_DEBUG_NO_TRIGGER_FRAME 0x100000
356 #define VP9_DEBUG_LOAD_UCODE_FROM_FILE 0x200000
357 #define VP9_DEBUG_FORCE_SEND_AGAIN 0x400000
358 #define VP9_DEBUG_DUMP_DATA 0x800000
359 #define VP9_DEBUG_CACHE 0x1000000
360 #define VP9_DEBUG_CACHE_HIT_RATE 0x2000000
361 #define IGNORE_PARAM_FROM_CONFIG 0x8000000
362 #ifdef MULTI_INSTANCE_SUPPORT
363 #define PRINT_FLAG_ERROR 0x0
364 #define PRINT_FLAG_V4L_DETAIL 0x10000000
365 #define PRINT_FLAG_VDEC_STATUS 0x20000000
366 #define PRINT_FLAG_VDEC_DETAIL 0x40000000
367 #define PRINT_FLAG_VDEC_DATA 0x80000000
371 static bool is_reset
;
375 bit 0, enable ucode print
376 bit 1, enable ucode detail print
377 bit [31:16] not 0, pos to dump lmem
378 bit 2, pop bits to lmem
379 bit [11:8], pre-pop bits for alignment (when bit 2 is 1)
381 static u32 udebug_flag
;
383 when udebug_flag[1:0] is not 0
384 udebug_pause_pos not 0,
387 static u32 udebug_pause_pos
;
389 when udebug_flag[1:0] is not 0
390 and udebug_pause_pos is not 0,
391 pause only when DEBUG_REG2 is equal to this val
393 static u32 udebug_pause_val
;
395 static u32 udebug_pause_decode_idx
;
397 static u32 without_display_mode
;
401 void WRITE_VREG_DBG2(unsigned int adr
, unsigned int val
)
403 if (debug
& VP9_DEBUG_REG
)
404 pr_info("%s(%x, %x)\n", __func__
, adr
, val
);
406 WRITE_VREG(adr
, val
);
410 #define WRITE_VREG WRITE_VREG_DBG2
413 #define FRAME_CNT_WINDOW_SIZE 59
414 #define RATE_CORRECTION_THRESHOLD 5
415 /**************************************************
417 VP9 buffer management start
419 ***************************************************/
421 #define MMU_COMPRESS_HEADER_SIZE 0x48000
422 #define MMU_COMPRESS_8K_HEADER_SIZE (0x48000*4)
423 #define MAX_SIZE_8K (8192 * 4608)
424 #define MAX_SIZE_4K (4096 * 2304)
425 #define IS_8K_SIZE(w, h) (((w) * (h)) > MAX_SIZE_4K)
427 #define INVALID_IDX -1 /* Invalid buffer index.*/
429 #define RPM_BEGIN 0x200
430 #define RPM_END 0x280
434 unsigned short data
[RPM_END
- RPM_BEGIN
];
437 /* from ucode lmem, do not change this struct */
438 unsigned short profile
;
439 unsigned short show_existing_frame
;
440 unsigned short frame_to_show_idx
;
441 unsigned short frame_type
; /*1 bit*/
442 unsigned short show_frame
; /*1 bit*/
443 unsigned short error_resilient_mode
; /*1 bit*/
444 unsigned short intra_only
; /*1 bit*/
445 unsigned short display_size_present
; /*1 bit*/
446 unsigned short reset_frame_context
;
447 unsigned short refresh_frame_flags
;
448 unsigned short width
;
449 unsigned short height
;
450 unsigned short display_width
;
451 unsigned short display_height
;
453 *bit[11:8] - ref_frame_info_0 (ref(3-bits), ref_frame_sign_bias(1-bit))
454 *bit[7:4] - ref_frame_info_1 (ref(3-bits), ref_frame_sign_bias(1-bit))
455 *bit[3:0] - ref_frame_info_2 (ref(3-bits), ref_frame_sign_bias(1-bit))
457 unsigned short ref_info
;
459 *bit[2]: same_frame_size0
460 *bit[1]: same_frame_size1
461 *bit[0]: same_frame_size2
463 unsigned short same_frame_size
;
465 unsigned short mode_ref_delta_enabled
;
466 unsigned short ref_deltas
[4];
467 unsigned short mode_deltas
[2];
468 unsigned short filter_level
;
469 unsigned short sharpness_level
;
470 unsigned short bit_depth
;
471 unsigned short seg_quant_info
[8];
472 unsigned short seg_enabled
;
473 unsigned short seg_abs_delta
;
474 /* bit 15: feature enabled; bit 8, sign; bit[5:0], data */
475 unsigned short seg_lf_info
[8];
480 struct vpx_codec_frame_buffer_s
{
481 uint8_t *data
; /**< Pointer to the data buffer */
482 size_t size
; /**< Size of data in bytes */
483 void *priv
; /**< Frame's private data */
486 enum vpx_color_space_t
{
487 VPX_CS_UNKNOWN
= 0, /**< Unknown */
488 VPX_CS_BT_601
= 1, /**< BT.601 */
489 VPX_CS_BT_709
= 2, /**< BT.709 */
490 VPX_CS_SMPTE_170
= 3, /**< SMPTE.170 */
491 VPX_CS_SMPTE_240
= 4, /**< SMPTE.240 */
492 VPX_CS_BT_2020
= 5, /**< BT.2020 */
493 VPX_CS_RESERVED
= 6, /**< Reserved */
494 VPX_CS_SRGB
= 7 /**< sRGB */
495 }; /**< alias for enum vpx_color_space */
497 enum vpx_bit_depth_t
{
498 VPX_BITS_8
= 8, /**< 8 bits */
499 VPX_BITS_10
= 10, /**< 10 bits */
500 VPX_BITS_12
= 12, /**< 12 bits */
503 #define MAX_SLICE_NUM 1024
504 struct PIC_BUFFER_CONFIG_s
{
513 #ifdef MULTI_INSTANCE_SUPPORT
514 struct canvas_config_s canvas_config
[2];
526 unsigned long header_adr
;
527 unsigned long mpred_mv_wr_start_addr
;
528 /*unsigned long mc_y_adr;
529 *unsigned long mc_u_v_adr;
531 unsigned int dw_y_adr
;
532 unsigned int dw_u_v_adr
;
557 uint8_t *alpha_buffer
;
559 uint8_t *buffer_alloc
;
565 unsigned int bit_depth
;
566 enum vpx_color_space_t color_space
;
570 unsigned long cma_alloc_addr
;
572 int double_write_mode
;
574 /* picture qos infomation*/
588 enum BITSTREAM_PROFILE
{
602 enum REFERENCE_MODE
{
603 SINGLE_REFERENCE
= 0,
604 COMPOUND_REFERENCE
= 1,
605 REFERENCE_MODE_SELECT
= 2,
610 #define INTRA_FRAME 0
612 #define GOLDEN_FRAME 2
613 #define ALTREF_FRAME 3
614 #define MAX_REF_FRAMES 4
616 #define REFS_PER_FRAME 3
618 #define REF_FRAMES_LOG2 3
619 #define REF_FRAMES (1 << REF_FRAMES_LOG2)
620 #define REF_FRAMES_4K (6)
622 /*4 scratch frames for the new frames to support a maximum of 4 cores decoding
623 *in parallel, 3 for scaled references on the encoder.
624 *TODO(hkuang): Add ondemand frame buffers instead of hardcoding the number
625 * // of framebuffers.
626 *TODO(jkoleszar): These 3 extra references could probably come from the
627 *normal reference pool.
629 #define FRAME_BUFFERS (REF_FRAMES + 16)
630 #define HEADER_FRAME_BUFFERS (FRAME_BUFFERS)
631 #define MAX_BUF_NUM (FRAME_BUFFERS)
632 #define MV_BUFFER_NUM FRAME_BUFFERS
633 #ifdef SUPPORT_FB_DECODING
634 #define STAGE_MAX_BUFFERS 16
636 #define STAGE_MAX_BUFFERS 0
639 #define FRAME_CONTEXTS_LOG2 2
640 #define FRAME_CONTEXTS (1 << FRAME_CONTEXTS_LOG2)
641 /*buffer + header buffer + workspace*/
642 #ifdef MV_USE_FIXED_BUF
643 #define MAX_BMMU_BUFFER_NUM (FRAME_BUFFERS + HEADER_FRAME_BUFFERS + 1)
644 #define VF_BUFFER_IDX(n) (n)
645 #define HEADER_BUFFER_IDX(n) (FRAME_BUFFERS + n)
646 #define WORK_SPACE_BUF_ID (FRAME_BUFFERS + HEADER_FRAME_BUFFERS)
648 #define MAX_BMMU_BUFFER_NUM \
649 (FRAME_BUFFERS + HEADER_FRAME_BUFFERS + MV_BUFFER_NUM + 1)
650 #define VF_BUFFER_IDX(n) (n)
651 #define HEADER_BUFFER_IDX(n) (FRAME_BUFFERS + n)
652 #define MV_BUFFER_IDX(n) (FRAME_BUFFERS + HEADER_FRAME_BUFFERS + n)
653 #define WORK_SPACE_BUF_ID \
654 (FRAME_BUFFERS + HEADER_FRAME_BUFFERS + MV_BUFFER_NUM)
657 struct RefCntBuffer_s
{
662 struct vpx_codec_frame_buffer_s raw_frame_buffer
;
663 struct PIC_BUFFER_CONFIG_s buf
;
665 /*The Following variables will only be used in frame parallel decode.
667 *frame_worker_owner indicates which FrameWorker owns this buffer. NULL means
668 *that no FrameWorker owns, or is decoding, this buffer.
669 *VP9Worker *frame_worker_owner;
671 *row and col indicate which position frame has been decoded to in real
672 *pixel unit. They are reset to -1 when decoding begins and set to INT_MAX
673 *when the frame is fully decoded.
680 /*TODO(dkovalev): idx is not really required and should be removed, now it
681 *is used in vp9_onyxd_if.c
684 struct PIC_BUFFER_CONFIG_s
*buf
;
685 /*struct scale_factors sf;*/
688 struct InternalFrameBuffer_s
{
692 } InternalFrameBuffer
;
694 struct InternalFrameBufferList_s
{
695 int num_internal_frame_buffers
;
696 struct InternalFrameBuffer_s
*int_fb
;
697 } InternalFrameBufferList
;
699 struct BufferPool_s
{
700 /*Protect BufferPool from being accessed by several FrameWorkers at
701 *the same time during frame parallel decode.
702 *TODO(hkuang): Try to use atomic variable instead of locking the whole pool.
704 *Private data associated with the frame buffer callbacks.
707 *vpx_get_frame_buffer_cb_fn_t get_fb_cb;
708 *vpx_release_frame_buffer_cb_fn_t release_fb_cb;
711 struct RefCntBuffer_s frame_bufs
[FRAME_BUFFERS
];
713 /*Frame buffers allocated internally by the codec.*/
714 struct InternalFrameBufferList_s int_frame_buffers
;
720 #define lock_buffer_pool(pool, flags) \
721 spin_lock_irqsave(&pool->lock, flags)
723 #define unlock_buffer_pool(pool, flags) \
724 spin_unlock_irqrestore(&pool->lock, flags)
726 struct VP9_Common_s
{
727 enum vpx_color_space_t color_space
;
738 int use_highbitdepth
;/*Marks if we need to use 16bit frame buffers.*/
740 struct PIC_BUFFER_CONFIG_s
*frame_to_show
;
741 struct RefCntBuffer_s
*prev_frame
;
743 /*TODO(hkuang): Combine this with cur_buf in macroblockd.*/
744 struct RefCntBuffer_s
*cur_frame
;
746 int ref_frame_map
[REF_FRAMES
]; /* maps fb_idx to reference slot */
748 /*Prepare ref_frame_map for the next frame.
749 *Only used in frame parallel decode.
751 int next_ref_frame_map
[REF_FRAMES
];
753 /* TODO(jkoleszar): could expand active_ref_idx to 4,
754 *with 0 as intra, and roll new_fb_idx into it.
757 /*Each frame can reference REFS_PER_FRAME buffers*/
758 struct RefBuffer_s frame_refs
[REFS_PER_FRAME
];
763 /*last frame's frame type for motion search*/
764 enum FRAME_TYPE last_frame_type
;
765 enum FRAME_TYPE frame_type
;
769 int show_existing_frame
;
771 /*Flag signaling that the frame is encoded using only INTRA modes.*/
773 uint8_t last_intra_only
;
775 int allow_high_precision_mv
;
777 /*Flag signaling that the frame context should be reset to default
778 *values. 0 or 1 implies don't reset, 2 reset just the context
779 *specified in the frame header, 3 reset all contexts.
781 int reset_frame_context
;
783 /*MBs, mb_rows/cols is in 16-pixel units; mi_rows/cols is in
784 * MODE_INFO (8-pixel) units.
787 int mb_rows
, mi_rows
;
788 int mb_cols
, mi_cols
;
791 /*Whether to use previous frame's motion vectors for prediction.*/
792 int use_prev_frame_mvs
;
794 int refresh_frame_context
; /* Two state 0 = NO, 1 = YES */
796 int ref_frame_sign_bias
[MAX_REF_FRAMES
]; /* Two state 0, 1 */
798 /*struct loopfilter lf;*/
799 /*struct segmentation seg;*/
801 /*TODO(hkuang):Remove this as it is the same as frame_parallel_decode*/
803 int frame_parallel_decode
; /* frame-based threading.*/
805 /*Context probabilities for reference frame prediction*/
806 /*MV_REFERENCE_FRAME comp_fixed_ref;*/
807 /*MV_REFERENCE_FRAME comp_var_ref[2];*/
808 enum REFERENCE_MODE reference_mode
;
810 /*FRAME_CONTEXT *fc; */ /* this frame entropy */
811 /*FRAME_CONTEXT *frame_contexts; */ /*FRAME_CONTEXTS*/
812 /*unsigned int frame_context_idx; *//* Context to use/update */
813 /*FRAME_COUNTS counts;*/
815 unsigned int current_video_frame
;
816 enum BITSTREAM_PROFILE profile
;
818 enum vpx_bit_depth_t bit_depth
;
820 int error_resilient_mode
;
821 int frame_parallel_decoding_mode
;
824 int skip_loop_filter
;
826 /*External BufferPool passed from outside.*/
827 struct BufferPool_s
*buffer_pool
;
829 int above_context_alloc_cols
;
833 static void set_canvas(struct VP9Decoder_s
*pbi
,
834 struct PIC_BUFFER_CONFIG_s
*pic_config
);
835 static int prepare_display_buf(struct VP9Decoder_s
*pbi
,
836 struct PIC_BUFFER_CONFIG_s
*pic_config
);
838 static void fill_frame_info(struct VP9Decoder_s
*pbi
,
839 struct PIC_BUFFER_CONFIG_s
*frame
,
840 unsigned int framesize
,
843 static struct PIC_BUFFER_CONFIG_s
*get_frame_new_buffer(struct VP9_Common_s
*cm
)
845 return &cm
->buffer_pool
->frame_bufs
[cm
->new_fb_idx
].buf
;
848 static void ref_cnt_fb(struct RefCntBuffer_s
*bufs
, int *idx
, int new_idx
)
850 const int ref_index
= *idx
;
852 if (ref_index
>= 0 && bufs
[ref_index
].ref_count
> 0) {
853 bufs
[ref_index
].ref_count
--;
854 /*pr_info("[MMU DEBUG 2] dec ref_count[%d] : %d\r\n",
855 * ref_index, bufs[ref_index].ref_count);
861 bufs
[new_idx
].ref_count
++;
862 /*pr_info("[MMU DEBUG 3] inc ref_count[%d] : %d\r\n",
863 * new_idx, bufs[new_idx].ref_count);
867 int vp9_release_frame_buffer(struct vpx_codec_frame_buffer_s
*fb
)
869 struct InternalFrameBuffer_s
*const int_fb
=
870 (struct InternalFrameBuffer_s
*)fb
->priv
;
876 static int compute_losless_comp_body_size(int width
, int height
,
877 uint8_t is_bit_depth_10
);
879 static void setup_display_size(struct VP9_Common_s
*cm
, union param_u
*params
,
880 int print_header_info
)
882 cm
->display_width
= cm
->width
;
883 cm
->display_height
= cm
->height
;
884 if (params
->p
.display_size_present
) {
885 if (print_header_info
)
886 pr_info(" * 1-bit display_size_present read : 1\n");
887 cm
->display_width
= params
->p
.display_width
;
888 cm
->display_height
= params
->p
.display_height
;
889 /*vp9_read_frame_size(rb, &cm->display_width,
890 * &cm->display_height);
893 if (print_header_info
)
894 pr_info(" * 1-bit display_size_present read : 0\n");
899 uint8_t print_header_info
= 0;
913 struct buff_s sao_abv
;
914 struct buff_s sao_vb
;
915 struct buff_s short_term_rps
;
919 struct buff_s sao_up
;
920 struct buff_s swap_buf
;
921 struct buff_s swap_buf2
;
922 struct buff_s scalelut
;
923 struct buff_s dblk_para
;
924 struct buff_s dblk_data
;
925 struct buff_s seg_map
;
926 struct buff_s mmu_vbh
;
927 struct buff_s cm_header
;
928 struct buff_s mpred_above
;
929 #ifdef MV_USE_FIXED_BUF
930 struct buff_s mpred_mv
;
935 #ifdef MULTI_INSTANCE_SUPPORT
936 #define DEC_RESULT_NONE 0
937 #define DEC_RESULT_DONE 1
938 #define DEC_RESULT_AGAIN 2
939 #define DEC_RESULT_CONFIG_PARAM 3
940 #define DEC_RESULT_ERROR 4
941 #define DEC_INIT_PICLIST 5
942 #define DEC_UNINIT_PICLIST 6
943 #define DEC_RESULT_GET_DATA 7
944 #define DEC_RESULT_GET_DATA_RETRY 8
945 #define DEC_RESULT_EOS 9
946 #define DEC_RESULT_FORCE_EXIT 10
947 #define DEC_V4L2_CONTINUE_DECODING 18
949 #define DEC_S1_RESULT_NONE 0
950 #define DEC_S1_RESULT_DONE 1
951 #define DEC_S1_RESULT_FORCE_EXIT 2
952 #define DEC_S1_RESULT_TEST_TRIGGER_DONE 0xf0
954 #ifdef FB_DECODING_TEST_SCHEDULE
955 #define TEST_SET_NONE 0
956 #define TEST_SET_PIC_DONE 1
957 #define TEST_SET_S2_DONE 2
960 static void vp9_work(struct work_struct
*work
);
962 struct loop_filter_info_n
;
966 #ifdef SUPPORT_FB_DECODING
967 static void mpred_process(struct VP9Decoder_s
*pbi
);
968 static void vp9_s1_work(struct work_struct
*work
);
972 unsigned short rpm
[RPM_END
- RPM_BEGIN
];
975 static unsigned int not_run2_ready
[MAX_DECODE_INSTANCE_NUM
];
977 static unsigned int run2_count
[MAX_DECODE_INSTANCE_NUM
];
979 #ifdef FB_DECODING_TEST_SCHEDULE
980 u32 stage_buf_num
; /* = 16;*/
986 struct VP9Decoder_s
{
987 #ifdef MULTI_INSTANCE_SUPPORT
990 struct device
*cma_dev
;
991 struct platform_device
*platform_dev
;
992 void (*vdec_cb
)(struct vdec_s
*, void *);
994 struct vframe_chunk_s
*chunk
;
996 struct work_struct work
;
997 struct work_struct recycle_mmu_work
;
998 struct work_struct set_clk_work
;
999 u32 start_shift_bytes
;
1001 struct BuffInfo_s work_space_buf_store
;
1002 unsigned long buf_start
;
1004 u32 cma_alloc_count
;
1005 unsigned long cma_alloc_addr
;
1007 unsigned long int start_process_time
;
1008 unsigned last_lcu_idx
;
1009 int decode_timeout_count
;
1010 unsigned timeout_num
;
1011 int save_buffer_mode
;
1013 int double_write_mode
;
1017 unsigned char m_ins_flag
;
1018 char *provider_name
;
1019 union param_u param
;
1023 struct timer_list timer
;
1028 uint8_t first_sc_checked
;
1029 uint8_t process_busy
;
1030 #define PROC_STATE_INIT 0
1031 #define PROC_STATE_DECODESLICE 1
1032 #define PROC_STATE_SENDAGAIN 2
1033 uint8_t process_state
;
1034 u32 ucode_pause_pos
;
1037 struct buff_s mc_buf_spec
;
1038 struct dec_sysinfo vvp9_amstream_dec_info
;
1041 dma_addr_t rpm_phy_addr
;
1042 dma_addr_t lmem_phy_addr
;
1043 unsigned short *lmem_ptr
;
1044 unsigned short *debug_ptr
;
1046 void *prob_buffer_addr
;
1047 void *count_buffer_addr
;
1048 dma_addr_t prob_buffer_phy_addr
;
1049 dma_addr_t count_buffer_phy_addr
;
1051 void *frame_mmu_map_addr
;
1052 dma_addr_t frame_mmu_map_phy_addr
;
1054 unsigned int use_cma_flag
;
1056 struct BUF_s m_BUF
[MAX_BUF_NUM
];
1057 struct MVBUF_s m_mv_BUF
[MV_BUFFER_NUM
];
1059 DECLARE_KFIFO(newframe_q
, struct vframe_s
*, VF_POOL_SIZE
);
1060 DECLARE_KFIFO(display_q
, struct vframe_s
*, VF_POOL_SIZE
);
1061 DECLARE_KFIFO(pending_q
, struct vframe_s
*, VF_POOL_SIZE
);
1062 struct vframe_s vfpool
[VF_POOL_SIZE
];
1069 unsigned int losless_comp_body_size
;
1071 u32 video_signal_type
;
1074 int last_lookup_pts
;
1076 u64 last_lookup_pts_us64
;
1078 u64 shift_byte_count
;
1081 u32 frame_cnt_window
;
1084 u32 duration_from_pts_done
;
1085 bool vp9_first_pts_ready
;
1087 u32 shift_byte_count_lo
;
1088 u32 shift_byte_count_hi
;
1089 int pts_mode_switching_count
;
1090 int pts_mode_recovery_count
;
1093 u32 saved_resolution
;
1096 struct VP9_Common_s common
;
1097 struct RefCntBuffer_s
*cur_buf
;
1098 int refresh_frame_flags
;
1099 uint8_t need_resync
;
1100 uint8_t hold_ref_buf
;
1101 uint8_t ready_for_new_data
;
1102 struct BufferPool_s vp9_buffer_pool
;
1104 struct BuffInfo_s
*work_space_buf
;
1106 struct buff_s
*mc_buf
;
1108 unsigned int frame_width
;
1109 unsigned int frame_height
;
1111 unsigned short *rpm_ptr
;
1122 uint8_t has_keyframe
;
1126 /* bit 0, for decoding; bit 1, for displaying */
1127 uint8_t ignore_bufmgr_error
;
1129 int PB_skip_count_after_decoding
;
1133 int default_filt_lvl
;
1134 struct loop_filter_info_n
*lfi
;
1135 struct loopfilter
*lf
;
1136 struct segmentation
*seg_4lf
;
1138 struct vdec_info
*gvs
;
1140 u32 pre_stream_offset
;
1142 unsigned int dec_status
;
1144 int new_frame_displayed
;
1148 struct vframe_master_display_colour_s vf_dp
;
1149 struct firmware_s
*fw
;
1152 #ifdef SUPPORT_FB_DECODING
1155 struct work_struct s1_work
;
1156 int used_stage_buf_num
;
1159 void *stage_mmu_map_addr
;
1160 dma_addr_t stage_mmu_map_phy_addr
;
1161 struct stage_buf_s
*s1_buf
;
1162 struct stage_buf_s
*s2_buf
;
1163 struct stage_buf_s
*stage_bufs
1164 [STAGE_MAX_BUFFERS
];
1165 unsigned char run2_busy
;
1167 int s1_mv_buf_index
;
1168 int s1_mv_buf_index_pre
;
1169 int s1_mv_buf_index_pre_pre
;
1170 unsigned long s1_mpred_mv_wr_start_addr
;
1171 unsigned long s1_mpred_mv_wr_start_addr_pre
;
1172 unsigned short s1_intra_only
;
1173 unsigned short s1_frame_type
;
1174 unsigned short s1_width
;
1175 unsigned short s1_height
;
1176 unsigned short s1_last_show_frame
;
1177 union param_u s1_param
;
1178 u8 back_not_run_ready
;
1180 int need_cache_size
;
1183 int low_latency_flag
;
1185 bool pic_list_init_done
;
1186 bool pic_list_init_done2
;
1189 bool v4l_params_parsed
;
1190 int frameinfo_enable
;
1191 struct vframe_qos_s vframe_qos
;
1193 u32 dynamic_buf_num_margin
;
1194 struct vframe_s vframe_dummy
;
1197 static int vp9_print(struct VP9Decoder_s
*pbi
,
1198 int flag
, const char *fmt
, ...)
1200 #define HEVC_PRINT_BUF 256
1201 unsigned char buf
[HEVC_PRINT_BUF
];
1209 va_start(args
, fmt
);
1211 len
= sprintf(buf
, "[%d]", pbi
->index
);
1212 vsnprintf(buf
+ len
, HEVC_PRINT_BUF
- len
, fmt
, args
);
1213 pr_debug("%s", buf
);
1219 static int is_oversize(int w
, int h
)
1221 int max
= (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_SM1
)?
1222 MAX_SIZE_8K
: MAX_SIZE_4K
;
1224 if (w
<= 0 || h
<= 0)
1227 if (h
!= 0 && (w
> max
/ h
))
1233 static int v4l_alloc_and_config_pic(struct VP9Decoder_s
*pbi
,
1234 struct PIC_BUFFER_CONFIG_s
*pic
);
1236 static void resize_context_buffers(struct VP9Decoder_s
*pbi
,
1237 struct VP9_Common_s
*cm
, int width
, int height
)
1239 if (cm
->width
!= width
|| cm
->height
!= height
) {
1242 pbi
->vp9_first_pts_ready
= 0;
1243 pbi
->duration_from_pts_done
= 0;
1245 pr_info("%s (%d,%d)=>(%d,%d)\r\n", __func__
, cm
->width
,
1246 cm
->height
, width
, height
);
1248 cm
->height
= height
;
1251 *if (cm->cur_frame->mvs == NULL ||
1252 * cm->mi_rows > cm->cur_frame->mi_rows ||
1253 * cm->mi_cols > cm->cur_frame->mi_cols) {
1254 * resize_mv_buffer(cm);
1259 static int valid_ref_frame_size(int ref_width
, int ref_height
,
1260 int this_width
, int this_height
) {
1261 return 2 * this_width
>= ref_width
&&
1262 2 * this_height
>= ref_height
&&
1263 this_width
<= 16 * ref_width
&&
1264 this_height
<= 16 * ref_height
;
1268 *static int valid_ref_frame_img_fmt(enum vpx_bit_depth_t ref_bit_depth,
1269 * int ref_xss, int ref_yss,
1270 * enum vpx_bit_depth_t this_bit_depth,
1271 * int this_xss, int this_yss) {
1272 * return ref_bit_depth == this_bit_depth && ref_xss == this_xss &&
1273 * ref_yss == this_yss;
1278 static int setup_frame_size(
1279 struct VP9Decoder_s
*pbi
,
1280 struct VP9_Common_s
*cm
, union param_u
*params
,
1281 unsigned int *mmu_index_adr
,
1282 int print_header_info
) {
1284 struct BufferPool_s
* const pool
= cm
->buffer_pool
;
1285 struct PIC_BUFFER_CONFIG_s
*ybf
;
1288 width
= params
->p
.width
;
1289 height
= params
->p
.height
;
1290 if (is_oversize(width
, height
)) {
1291 vp9_print(pbi
, 0, "%s, Error: Invalid frame size\n", __func__
);
1295 /*vp9_read_frame_size(rb, &width, &height);*/
1296 if (print_header_info
)
1297 pr_info(" * 16-bits w read : %d (width : %d)\n", width
, height
);
1298 if (print_header_info
)
1300 (" * 16-bits h read : %d (height : %d)\n", width
, height
);
1302 WRITE_VREG(HEVC_PARSER_PICTURE_SIZE
, (height
<< 16) | width
);
1303 #ifdef VP9_10B_HED_FB
1304 WRITE_VREG(HEVC_ASSIST_PIC_SIZE_FB_READ
, (height
<< 16) | width
);
1306 if (pbi
->mmu_enable
&& ((pbi
->double_write_mode
& 0x10) == 0)) {
1307 ret
= vp9_alloc_mmu(pbi
,
1311 params
->p
.bit_depth
,
1314 pr_err("can't alloc need mmu1,idx %d ret =%d\n",
1319 cm
->cur_fb_idx_mmu
= cm
->new_fb_idx
;
1322 resize_context_buffers(pbi
, cm
, width
, height
);
1323 setup_display_size(cm
, params
, print_header_info
);
1325 lock_buffer_pool(pool
);
1326 if (vp9_realloc_frame_buffer(
1327 get_frame_new_buffer(cm
), cm
->width
, cm
->height
,
1328 cm
->subsampling_x
, cm
->subsampling_y
,
1329 #if CONFIG_VP9_HIGHBITDEPTH
1330 cm
->use_highbitdepth
,
1332 VP9_DEC_BORDER_IN_PIXELS
,
1334 &pool
->frame_bufs
[cm
->new_fb_idx
].raw_frame_buffer
,
1335 pool
->get_fb_cb
, pool
->cb_priv
)) {
1336 unlock_buffer_pool(pool
);
1337 vpx_internal_error(&cm
->error
, VPX_CODEC_MEM_ERROR
,
1338 "Failed to allocate frame buffer");
1340 unlock_buffer_pool(pool
);
1343 ybf
= get_frame_new_buffer(cm
);
1347 ybf
->y_crop_width
= width
;
1348 ybf
->y_crop_height
= height
;
1349 ybf
->bit_depth
= params
->p
.bit_depth
;
1351 pool
->frame_bufs
[cm
->new_fb_idx
].buf
.subsampling_x
= cm
->subsampling_x
;
1352 pool
->frame_bufs
[cm
->new_fb_idx
].buf
.subsampling_y
= cm
->subsampling_y
;
1353 pool
->frame_bufs
[cm
->new_fb_idx
].buf
.bit_depth
=
1354 (unsigned int)cm
->bit_depth
;
1355 pool
->frame_bufs
[cm
->new_fb_idx
].buf
.color_space
= cm
->color_space
;
1359 static int setup_frame_size_with_refs(
1360 struct VP9Decoder_s
*pbi
,
1361 struct VP9_Common_s
*cm
,
1362 union param_u
*params
,
1363 unsigned int *mmu_index_adr
,
1364 int print_header_info
) {
1368 int has_valid_ref_frame
= 0;
1369 struct PIC_BUFFER_CONFIG_s
*ybf
;
1370 struct BufferPool_s
* const pool
= cm
->buffer_pool
;
1373 for (i
= 0; i
< REFS_PER_FRAME
; ++i
) {
1374 if ((params
->p
.same_frame_size
>>
1375 (REFS_PER_FRAME
- i
- 1)) & 0x1) {
1376 struct PIC_BUFFER_CONFIG_s
*const buf
=
1377 cm
->frame_refs
[i
].buf
;
1378 /*if (print_header_info)
1380 * ("1-bit same_frame_size[%d] read : 1\n", i);
1382 width
= buf
->y_crop_width
;
1383 height
= buf
->y_crop_height
;
1384 /*if (print_header_info)
1386 * (" - same_frame_size width : %d\n", width);
1388 /*if (print_header_info)
1390 * (" - same_frame_size height : %d\n", height);
1395 /*if (print_header_info)
1397 * ("1-bit same_frame_size[%d] read : 0\n", i);
1403 /*vp9_read_frame_size(rb, &width, &height);*/
1404 width
= params
->p
.width
;
1405 height
= params
->p
.height
;
1406 /*if (print_header_info)
1408 * (" * 16-bits w read : %d (width : %d)\n",
1410 *if (print_header_info)
1412 * (" * 16-bits h read : %d (height : %d)\n",
1417 if (is_oversize(width
, height
)) {
1418 vp9_print(pbi
, 0, "%s, Error: Invalid frame size\n", __func__
);
1422 params
->p
.width
= width
;
1423 params
->p
.height
= height
;
1425 WRITE_VREG(HEVC_PARSER_PICTURE_SIZE
, (height
<< 16) | width
);
1426 if (pbi
->mmu_enable
&& ((pbi
->double_write_mode
& 0x10) == 0)) {
1427 /*if(cm->prev_fb_idx >= 0) release_unused_4k(cm->prev_fb_idx);
1428 *cm->prev_fb_idx = cm->new_fb_idx;
1431 * ("[DEBUG DEBUG]Before alloc_mmu,
1432 * prev_fb_idx : %d, new_fb_idx : %d\r\n",
1433 * cm->prev_fb_idx, cm->new_fb_idx);
1435 ret
= vp9_alloc_mmu(pbi
, cm
->new_fb_idx
,
1436 params
->p
.width
, params
->p
.height
,
1437 params
->p
.bit_depth
, mmu_index_adr
);
1439 pr_err("can't alloc need mmu,idx %d\r\n",
1443 cm
->cur_fb_idx_mmu
= cm
->new_fb_idx
;
1446 /*Check to make sure at least one of frames that this frame references
1447 *has valid dimensions.
1449 for (i
= 0; i
< REFS_PER_FRAME
; ++i
) {
1450 struct RefBuffer_s
* const ref_frame
= &cm
->frame_refs
[i
];
1452 has_valid_ref_frame
|=
1453 valid_ref_frame_size(ref_frame
->buf
->y_crop_width
,
1454 ref_frame
->buf
->y_crop_height
,
1457 if (!has_valid_ref_frame
) {
1458 pr_err("Error: Referenced frame has invalid size\r\n");
1462 for (i
= 0; i
< REFS_PER_FRAME
; ++i
) {
1463 struct RefBuffer_s
* const ref_frame
=
1465 if (!valid_ref_frame_img_fmt(
1466 ref_frame
->buf
->bit_depth
,
1467 ref_frame
->buf
->subsampling_x
,
1468 ref_frame
->buf
->subsampling_y
,
1473 ("Referenced frame incompatible color fmt\r\n");
1477 resize_context_buffers(pbi
, cm
, width
, height
);
1478 setup_display_size(cm
, params
, print_header_info
);
1481 lock_buffer_pool(pool
);
1482 if (vp9_realloc_frame_buffer(
1483 get_frame_new_buffer(cm
), cm
->width
, cm
->height
,
1484 cm
->subsampling_x
, cm
->subsampling_y
,
1485 #if CONFIG_VP9_HIGHBITDEPTH
1486 cm
->use_highbitdepth
,
1488 VP9_DEC_BORDER_IN_PIXELS
,
1490 &pool
->frame_bufs
[cm
->new_fb_idx
].raw_frame_buffer
,
1493 unlock_buffer_pool(pool
);
1494 vpx_internal_error(&cm
->error
, VPX_CODEC_MEM_ERROR
,
1495 "Failed to allocate frame buffer");
1497 unlock_buffer_pool(pool
);
1500 ybf
= get_frame_new_buffer(cm
);
1504 ybf
->y_crop_width
= width
;
1505 ybf
->y_crop_height
= height
;
1506 ybf
->bit_depth
= params
->p
.bit_depth
;
1508 pool
->frame_bufs
[cm
->new_fb_idx
].buf
.subsampling_x
= cm
->subsampling_x
;
1509 pool
->frame_bufs
[cm
->new_fb_idx
].buf
.subsampling_y
= cm
->subsampling_y
;
1510 pool
->frame_bufs
[cm
->new_fb_idx
].buf
.bit_depth
=
1511 (unsigned int)cm
->bit_depth
;
1512 pool
->frame_bufs
[cm
->new_fb_idx
].buf
.color_space
= cm
->color_space
;
1516 static inline bool close_to(int a
, int b
, int m
)
1518 return (abs(a
- b
) < m
) ? true : false;
1521 #ifdef MULTI_INSTANCE_SUPPORT
1522 static int vp9_print_cont(struct VP9Decoder_s
*pbi
,
1523 int flag
, const char *fmt
, ...)
1525 unsigned char buf
[HEVC_PRINT_BUF
];
1533 va_start(args
, fmt
);
1534 vsnprintf(buf
+ len
, HEVC_PRINT_BUF
- len
, fmt
, args
);
1535 pr_debug("%s", buf
);
1541 static void trigger_schedule(struct VP9Decoder_s
*pbi
)
1543 if (pbi
->is_used_v4l
) {
1544 struct aml_vcodec_ctx
*ctx
=
1545 (struct aml_vcodec_ctx
*)(pbi
->v4l2_ctx
);
1547 if (ctx
->param_sets_from_ucode
&&
1548 !pbi
->v4l_params_parsed
)
1549 vdec_v4l_write_frame_sync(ctx
);
1553 pbi
->vdec_cb(hw_to_vdec(pbi
), pbi
->vdec_cb_arg
);
1556 static void reset_process_time(struct VP9Decoder_s
*pbi
)
1558 if (pbi
->start_process_time
) {
1559 unsigned process_time
=
1560 1000 * (jiffies
- pbi
->start_process_time
) / HZ
;
1561 pbi
->start_process_time
= 0;
1562 if (process_time
> max_process_time
[pbi
->index
])
1563 max_process_time
[pbi
->index
] = process_time
;
1567 static void start_process_time(struct VP9Decoder_s
*pbi
)
1569 pbi
->start_process_time
= jiffies
;
1570 pbi
->decode_timeout_count
= 0;
1571 pbi
->last_lcu_idx
= 0;
1574 static void timeout_process(struct VP9Decoder_s
*pbi
)
1579 0, "%s decoder timeout\n", __func__
);
1581 pbi
->dec_result
= DEC_RESULT_DONE
;
1582 reset_process_time(pbi
);
1583 vdec_schedule_work(&pbi
->work
);
1586 static u32
get_valid_double_write_mode(struct VP9Decoder_s
*pbi
)
1588 return ((double_write_mode
& 0x80000000) == 0) ?
1589 pbi
->double_write_mode
:
1590 (double_write_mode
& 0x7fffffff);
1593 static int get_double_write_mode(struct VP9Decoder_s
*pbi
)
1595 u32 valid_dw_mode
= get_valid_double_write_mode(pbi
);
1598 struct VP9_Common_s
*cm
= &pbi
->common
;
1599 struct PIC_BUFFER_CONFIG_s
*cur_pic_config
;
1601 /* mask for supporting double write value bigger than 0x100 */
1602 if (valid_dw_mode
& 0xffffff00) {
1604 return 1;/*no valid frame,*/
1605 cur_pic_config
= &cm
->cur_frame
->buf
;
1606 w
= cur_pic_config
->y_crop_width
;
1607 h
= cur_pic_config
->y_crop_height
;
1610 switch (valid_dw_mode
) {
1612 if (w
> 1920 && h
> 1088)
1616 if (w
> 1920 && h
> 1088)
1620 if (w
> 1280 && h
> 720)
1629 return valid_dw_mode
;
1632 /* for double write buf alloc */
1633 static int get_double_write_mode_init(struct VP9Decoder_s
*pbi
)
1635 u32 valid_dw_mode
= get_valid_double_write_mode(pbi
);
1637 int w
= pbi
->init_pic_w
;
1638 int h
= pbi
->init_pic_h
;
1641 switch (valid_dw_mode
) {
1643 if (w
> 1920 && h
> 1088)
1647 if (w
> 1920 && h
> 1088)
1651 if (w
> 1280 && h
> 720)
1662 static int get_double_write_ratio(struct VP9Decoder_s
*pbi
,
1666 if ((dw_mode
== 2) ||
1669 else if (dw_mode
== 4)
1674 //#define MAX_4K_NUM 0x1200
1677 struct VP9Decoder_s
*pbi
,
1681 unsigned short bit_depth
,
1682 unsigned int *mmu_index_adr
)
1684 int bit_depth_10
= (bit_depth
== VPX_BITS_10
);
1686 int cur_mmu_4k_number
, max_frame_num
;
1687 if (!pbi
->mmu_box
) {
1688 pr_err("error no mmu box!\n");
1691 if (pbi
->double_write_mode
& 0x10)
1693 if (bit_depth
>= VPX_BITS_12
) {
1694 pbi
->fatal_error
= DECODER_FATAL_ERROR_SIZE_OVERFLOW
;
1695 pr_err("fatal_error, un support bit depth 12!\n\n");
1698 picture_size
= compute_losless_comp_body_size(pic_width
, pic_height
,
1700 cur_mmu_4k_number
= ((picture_size
+ (1 << 12) - 1) >> 12);
1702 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_SM1
)
1703 max_frame_num
= MAX_FRAME_8K_NUM
;
1705 max_frame_num
= MAX_FRAME_4K_NUM
;
1707 if (cur_mmu_4k_number
> max_frame_num
) {
1708 pr_err("over max !! cur_mmu_4k_number 0x%x width %d height %d\n",
1709 cur_mmu_4k_number
, pic_width
, pic_height
);
1712 return decoder_mmu_box_alloc_idx(
1720 #ifndef MV_USE_FIXED_BUF
1721 static void dealloc_mv_bufs(struct VP9Decoder_s
*pbi
)
1724 for (i
= 0; i
< MV_BUFFER_NUM
; i
++) {
1725 if (pbi
->m_mv_BUF
[i
].start_adr
) {
1728 "dealloc mv buf(%d) adr %ld size 0x%x used_flag %d\n",
1729 i
, pbi
->m_mv_BUF
[i
].start_adr
,
1730 pbi
->m_mv_BUF
[i
].size
,
1731 pbi
->m_mv_BUF
[i
].used_flag
);
1732 decoder_bmmu_box_free_idx(
1735 pbi
->m_mv_BUF
[i
].start_adr
= 0;
1736 pbi
->m_mv_BUF
[i
].size
= 0;
1737 pbi
->m_mv_BUF
[i
].used_flag
= 0;
1742 static int alloc_mv_buf(struct VP9Decoder_s
*pbi
,
1747 if (pbi
->m_mv_BUF
[i
].start_adr
&&
1748 size
> pbi
->m_mv_BUF
[i
].size
) {
1749 dealloc_mv_bufs(pbi
);
1750 } else if (pbi
->m_mv_BUF
[i
].start_adr
)
1753 if (decoder_bmmu_box_alloc_buf_phy
1755 MV_BUFFER_IDX(i
), size
,
1757 &pbi
->m_mv_BUF
[i
].start_adr
) < 0) {
1758 pbi
->m_mv_BUF
[i
].start_adr
= 0;
1761 pbi
->m_mv_BUF
[i
].size
= size
;
1762 pbi
->m_mv_BUF
[i
].used_flag
= 0;
1766 "MV Buffer %d: start_adr %p size %x\n",
1768 (void *)pbi
->m_mv_BUF
[i
].start_adr
,
1769 pbi
->m_mv_BUF
[i
].size
);
1775 static int init_mv_buf_list(struct VP9Decoder_s
*pbi
)
1779 int count
= MV_BUFFER_NUM
;
1780 int pic_width
= pbi
->init_pic_w
;
1781 int pic_height
= pbi
->init_pic_h
;
1782 int lcu_size
= 64; /*fixed 64*/
1783 int pic_width_64
= (pic_width
+ 63) & (~0x3f);
1784 int pic_height_32
= (pic_height
+ 31) & (~0x1f);
1785 int pic_width_lcu
= (pic_width_64
% lcu_size
) ?
1786 pic_width_64
/ lcu_size
+ 1
1787 : pic_width_64
/ lcu_size
;
1788 int pic_height_lcu
= (pic_height_32
% lcu_size
) ?
1789 pic_height_32
/ lcu_size
+ 1
1790 : pic_height_32
/ lcu_size
;
1791 int lcu_total
= pic_width_lcu
* pic_height_lcu
;
1792 int size
= ((lcu_total
* MV_MEM_UNIT
) + 0xffff) &
1794 if (mv_buf_margin
> 0)
1795 count
= REF_FRAMES
+ mv_buf_margin
;
1797 if (pbi
->init_pic_w
> 2048 && pbi
->init_pic_h
> 1088)
1798 count
= REF_FRAMES_4K
+ mv_buf_margin
;
1801 pr_info("%s w:%d, h:%d, count: %d\n",
1802 __func__
, pbi
->init_pic_w
, pbi
->init_pic_h
, count
);
1806 i
< count
&& i
< MV_BUFFER_NUM
; i
++) {
1807 if (alloc_mv_buf(pbi
, i
, size
) < 0) {
1815 static int get_mv_buf(struct VP9Decoder_s
*pbi
,
1817 unsigned long *mpred_mv_wr_start_addr
)
1821 for (i
= 0; i
< MV_BUFFER_NUM
; i
++) {
1822 if (pbi
->m_mv_BUF
[i
].start_adr
&&
1823 pbi
->m_mv_BUF
[i
].used_flag
== 0) {
1824 pbi
->m_mv_BUF
[i
].used_flag
= 1;
1831 *mv_buf_index
= ret
;
1832 *mpred_mv_wr_start_addr
=
1833 (pbi
->m_mv_BUF
[ret
].start_adr
+ 0xffff) &
1835 if (debug
& VP9_DEBUG_BUFMGR_MORE
)
1837 "%s => %d (%ld) size 0x%x\n",
1839 *mpred_mv_wr_start_addr
,
1840 pbi
->m_mv_BUF
[ret
].size
);
1843 "%s: Error, mv buf is not enough\n",
1849 static void put_mv_buf(struct VP9Decoder_s
*pbi
,
1852 int i
= *mv_buf_index
;
1853 if (i
>= MV_BUFFER_NUM
) {
1854 if (debug
& VP9_DEBUG_BUFMGR_MORE
)
1856 "%s: index %d beyond range\n",
1860 if (debug
& VP9_DEBUG_BUFMGR_MORE
)
1862 "%s(%d): used_flag(%d)\n",
1864 pbi
->m_mv_BUF
[i
].used_flag
);
1867 if (pbi
->m_mv_BUF
[i
].start_adr
&&
1868 pbi
->m_mv_BUF
[i
].used_flag
)
1869 pbi
->m_mv_BUF
[i
].used_flag
= 0;
1872 static void put_un_used_mv_bufs(struct VP9Decoder_s
*pbi
)
1874 struct VP9_Common_s
*const cm
= &pbi
->common
;
1875 struct RefCntBuffer_s
*const frame_bufs
= cm
->buffer_pool
->frame_bufs
;
1877 for (i
= 0; i
< pbi
->used_buf_num
; ++i
) {
1878 if ((frame_bufs
[i
].ref_count
== 0) &&
1879 (frame_bufs
[i
].buf
.index
!= -1) &&
1880 (frame_bufs
[i
].buf
.mv_buf_index
>= 0)
1882 put_mv_buf(pbi
, &frame_bufs
[i
].buf
.mv_buf_index
);
1886 #ifdef SUPPORT_FB_DECODING
1887 static bool mv_buf_available(struct VP9Decoder_s
*pbi
)
1891 for (i
= 0; i
< MV_BUFFER_NUM
; i
++) {
1892 if (pbi
->m_mv_BUF
[i
].start_adr
&&
1893 pbi
->m_mv_BUF
[i
].used_flag
== 0) {
1903 #ifdef SUPPORT_FB_DECODING
1904 static void init_stage_buf(struct VP9Decoder_s
*pbi
)
1907 for (i
= 0; i
< STAGE_MAX_BUFFERS
1908 && i
< stage_buf_num
; i
++) {
1909 pbi
->stage_bufs
[i
] =
1910 vmalloc(sizeof(struct stage_buf_s
));
1911 if (pbi
->stage_bufs
[i
] == NULL
) {
1913 0, "%s vmalloc fail\n", __func__
);
1916 pbi
->stage_bufs
[i
]->index
= i
;
1918 pbi
->used_stage_buf_num
= i
;
1923 pbi
->s1_mv_buf_index
= FRAME_BUFFERS
;
1924 pbi
->s1_mv_buf_index_pre
= FRAME_BUFFERS
;
1925 pbi
->s1_mv_buf_index_pre_pre
= FRAME_BUFFERS
;
1927 if (pbi
->used_stage_buf_num
> 0)
1929 0, "%s 2 stage decoding buf %d\n",
1931 pbi
->used_stage_buf_num
);
1934 static void uninit_stage_buf(struct VP9Decoder_s
*pbi
)
1937 for (i
= 0; i
< pbi
->used_stage_buf_num
; i
++) {
1938 if (pbi
->stage_bufs
[i
])
1939 vfree(pbi
->stage_bufs
[i
]);
1940 pbi
->stage_bufs
[i
] = NULL
;
1942 pbi
->used_stage_buf_num
= 0;
1949 static int get_s1_buf(
1950 struct VP9Decoder_s
*pbi
)
1952 struct stage_buf_s
*buf
= NULL
;
1954 int buf_page_num
= MAX_STAGE_PAGE_NUM
;
1955 int next_s1_pos
= pbi
->s1_pos
+ 1;
1957 if (next_s1_pos
>= pbi
->used_stage_buf_num
)
1959 if (next_s1_pos
== pbi
->s2_pos
) {
1964 buf
= pbi
->stage_bufs
[pbi
->s1_pos
];
1965 ret
= decoder_mmu_box_alloc_idx(
1969 pbi
->stage_mmu_map_addr
);
1972 "%s decoder_mmu_box_alloc fail for index %d (s1_pos %d s2_pos %d)\n",
1973 __func__
, buf
->index
,
1974 pbi
->s1_pos
, pbi
->s2_pos
);
1977 vp9_print(pbi
, VP9_DEBUG_2_STAGE
,
1978 "%s decoder_mmu_box_alloc %d page for index %d (s1_pos %d s2_pos %d)\n",
1979 __func__
, buf_page_num
, buf
->index
,
1980 pbi
->s1_pos
, pbi
->s2_pos
);
1986 static void inc_s1_pos(struct VP9Decoder_s
*pbi
)
1988 struct stage_buf_s
*buf
=
1989 pbi
->stage_bufs
[pbi
->s1_pos
];
1992 #ifdef FB_DECODING_TEST_SCHEDULE
1993 MAX_STAGE_PAGE_NUM
/2;
1995 (READ_VREG(HEVC_ASSIST_HED_FB_W_CTL
) >> 16);
1997 decoder_mmu_box_free_idx_tail(pbi
->mmu_box
,
1998 FRAME_BUFFERS
+ buf
->index
, used_page_num
);
2001 if (pbi
->s1_pos
>= pbi
->used_stage_buf_num
)
2004 vp9_print(pbi
, VP9_DEBUG_2_STAGE
,
2005 "%s (used_page_num %d) for index %d (s1_pos %d s2_pos %d)\n",
2006 __func__
, used_page_num
, buf
->index
,
2007 pbi
->s1_pos
, pbi
->s2_pos
);
2010 #define s2_buf_available(pbi) (pbi->s1_pos != pbi->s2_pos)
2012 static int get_s2_buf(
2013 struct VP9Decoder_s
*pbi
)
2016 struct stage_buf_s
*buf
= NULL
;
2017 if (s2_buf_available(pbi
)) {
2018 buf
= pbi
->stage_bufs
[pbi
->s2_pos
];
2019 vp9_print(pbi
, VP9_DEBUG_2_STAGE
,
2020 "%s for index %d (s1_pos %d s2_pos %d)\n",
2021 __func__
, buf
->index
,
2022 pbi
->s1_pos
, pbi
->s2_pos
);
2029 static void inc_s2_pos(struct VP9Decoder_s
*pbi
)
2031 struct stage_buf_s
*buf
=
2032 pbi
->stage_bufs
[pbi
->s2_pos
];
2033 decoder_mmu_box_free_idx(pbi
->mmu_box
,
2034 FRAME_BUFFERS
+ buf
->index
);
2036 if (pbi
->s2_pos
>= pbi
->used_stage_buf_num
)
2038 vp9_print(pbi
, VP9_DEBUG_2_STAGE
,
2039 "%s for index %d (s1_pos %d s2_pos %d)\n",
2040 __func__
, buf
->index
,
2041 pbi
->s1_pos
, pbi
->s2_pos
);
2044 static int get_free_stage_buf_num(struct VP9Decoder_s
*pbi
)
2047 if (pbi
->s1_pos
>= pbi
->s2_pos
)
2048 num
= pbi
->used_stage_buf_num
-
2049 (pbi
->s1_pos
- pbi
->s2_pos
) - 1;
2051 num
= (pbi
->s2_pos
- pbi
->s1_pos
) - 1;
2055 #ifndef FB_DECODING_TEST_SCHEDULE
2056 static DEFINE_SPINLOCK(fb_core_spin_lock
);
2058 static u8
is_s2_decoding_finished(struct VP9Decoder_s
*pbi
)
2060 /* to do: VLSI review
2061 completion of last LCU decoding in BACK
2066 static void start_s1_decoding(struct VP9Decoder_s
*pbi
)
2068 /* to do: VLSI review
2069 after parser, how to start LCU decoding in BACK
2073 static void fb_reset_core(struct vdec_s
*vdec
, u32 mask
)
2075 /* to do: VLSI review
2076 1. how to disconnect DMC for FRONT and BACK
2077 2. reset bit 13, 24, FRONT or BACK ??
2080 unsigned long flags
;
2082 if (mask
& HW_MASK_FRONT
)
2083 WRITE_VREG(HEVC_STREAM_CONTROL
, 0);
2084 spin_lock_irqsave(&fb_core_spin_lock
, flags
);
2085 codec_dmcbus_write(DMC_REQ_CTRL
,
2086 codec_dmcbus_read(DMC_REQ_CTRL
) & (~(1 << 4)));
2087 spin_unlock_irqrestore(&fb_core_spin_lock
, flags
);
2089 while (!(codec_dmcbus_read(DMC_CHAN_STS
)
2093 if ((mask
& HW_MASK_FRONT
) &&
2094 input_frame_based(vdec
))
2095 WRITE_VREG(HEVC_STREAM_CONTROL
, 0);
2112 if (mask
& HW_MASK_FRONT
) {
2114 (1<<3)|(1<<4)|(1<<11)|
2117 if (mask
& HW_MASK_BACK
) {
2119 (1<<8)|(1<<13)|(1<<14)|(1<<15)|
2120 (1<<17)|(1<<19)|(1<<24);
2122 WRITE_VREG(DOS_SW_RESET3
, reset_bits
);
2124 (1<<3)|(1<<4)|(1<<8)|(1<<11)|
2125 (1<<12)|(1<<13)|(1<<14)|(1<<15)|
2126 (1<<17)|(1<<18)|(1<<19)|(1<<24);
2128 WRITE_VREG(DOS_SW_RESET3
, 0);
2131 spin_lock_irqsave(&fb_core_spin_lock
, flags
);
2132 codec_dmcbus_write(DMC_REQ_CTRL
,
2133 codec_dmcbus_read(DMC_REQ_CTRL
) | (1 << 4));
2134 spin_unlock_irqrestore(&fb_core_spin_lock
, flags
);
2141 static void init_pic_list_hw(struct VP9Decoder_s
*pbi
);
2143 static int get_free_fb(struct VP9Decoder_s
*pbi
)
2145 struct VP9_Common_s
*const cm
= &pbi
->common
;
2146 struct RefCntBuffer_s
*const frame_bufs
= cm
->buffer_pool
->frame_bufs
;
2148 unsigned long flags
;
2150 lock_buffer_pool(cm
->buffer_pool
, flags
);
2151 if (debug
& VP9_DEBUG_BUFMGR_MORE
) {
2152 for (i
= 0; i
< pbi
->used_buf_num
; ++i
) {
2153 pr_info("%s:%d, ref_count %d vf_ref %d index %d\r\n",
2154 __func__
, i
, frame_bufs
[i
].ref_count
,
2155 frame_bufs
[i
].buf
.vf_ref
,
2156 frame_bufs
[i
].buf
.index
);
2159 for (i
= 0; i
< pbi
->used_buf_num
; ++i
) {
2160 if ((frame_bufs
[i
].ref_count
== 0) &&
2161 (frame_bufs
[i
].buf
.vf_ref
== 0) &&
2162 (frame_bufs
[i
].buf
.index
!= -1)
2166 if (i
!= pbi
->used_buf_num
) {
2167 frame_bufs
[i
].ref_count
= 1;
2168 /*pr_info("[MMU DEBUG 1] set ref_count[%d] : %d\r\n",
2169 i, frame_bufs[i].ref_count);*/
2171 /* Reset i to be INVALID_IDX to indicate
2172 no free buffer found*/
2176 unlock_buffer_pool(cm
->buffer_pool
, flags
);
2180 static int v4l_get_free_fb(struct VP9Decoder_s
*pbi
)
2182 struct VP9_Common_s
*const cm
= &pbi
->common
;
2183 struct RefCntBuffer_s
*const frame_bufs
= cm
->buffer_pool
->frame_bufs
;
2184 struct aml_vcodec_ctx
* v4l
= pbi
->v4l2_ctx
;
2185 struct v4l_buff_pool
*pool
= &v4l
->cap_pool
;
2186 struct PIC_BUFFER_CONFIG_s
*pic
= NULL
;
2187 int i
, idx
= INVALID_IDX
;
2190 lock_buffer_pool(cm
->buffer_pool
, flags
);
2192 for (i
= 0; i
< pool
->in
; ++i
) {
2193 u32 state
= (pool
->seq
[i
] >> 16);
2194 u32 index
= (pool
->seq
[i
] & 0xffff);
2197 case V4L_CAP_BUFF_IN_DEC
:
2198 pic
= &frame_bufs
[i
].buf
;
2199 if ((frame_bufs
[i
].ref_count
== 0) &&
2200 (pic
->vf_ref
== 0) &&
2201 (pic
->index
!= -1) &&
2202 pic
->cma_alloc_addr
) {
2206 case V4L_CAP_BUFF_IN_M2M
:
2207 pic
= &frame_bufs
[index
].buf
;
2208 pic
->y_crop_width
= pbi
->frame_width
;
2209 pic
->y_crop_height
= pbi
->frame_height
;
2210 if (!v4l_alloc_and_config_pic(pbi
, pic
)) {
2211 set_canvas(pbi
, pic
);
2212 init_pic_list_hw(pbi
);
2217 pr_err("v4l buffer state err %d.\n", state
);
2221 if (idx
!= INVALID_IDX
) {
2222 frame_bufs
[idx
].ref_count
= 1;
2227 unlock_buffer_pool(cm
->buffer_pool
, flags
);
2232 static int get_free_buf_count(struct VP9Decoder_s
*pbi
)
2234 struct VP9_Common_s
*const cm
= &pbi
->common
;
2235 struct RefCntBuffer_s
*const frame_bufs
= cm
->buffer_pool
->frame_bufs
;
2237 int free_buf_count
= 0;
2238 for (i
= 0; i
< pbi
->used_buf_num
; ++i
)
2239 if ((frame_bufs
[i
].ref_count
== 0) &&
2240 (frame_bufs
[i
].buf
.vf_ref
== 0) &&
2241 (frame_bufs
[i
].buf
.index
!= -1)
2244 return free_buf_count
;
2247 static void decrease_ref_count(int idx
, struct RefCntBuffer_s
*const frame_bufs
,
2248 struct BufferPool_s
*const pool
)
2251 --frame_bufs
[idx
].ref_count
;
2252 /*pr_info("[MMU DEBUG 7] dec ref_count[%d] : %d\r\n", idx,
2253 * frame_bufs[idx].ref_count);
2255 /*A worker may only get a free framebuffer index when
2256 *calling get_free_fb. But the private buffer is not set up
2257 *until finish decoding header. So any error happens during
2258 *decoding header, the frame_bufs will not have valid priv
2262 if (frame_bufs
[idx
].ref_count
== 0 &&
2263 frame_bufs
[idx
].raw_frame_buffer
.priv
)
2264 vp9_release_frame_buffer
2265 (&frame_bufs
[idx
].raw_frame_buffer
);
2269 static void generate_next_ref_frames(struct VP9Decoder_s
*pbi
)
2271 struct VP9_Common_s
*const cm
= &pbi
->common
;
2272 struct RefCntBuffer_s
*frame_bufs
= cm
->buffer_pool
->frame_bufs
;
2273 struct BufferPool_s
*const pool
= cm
->buffer_pool
;
2274 int mask
, ref_index
= 0;
2275 unsigned long flags
;
2277 /* Generate next_ref_frame_map.*/
2278 lock_buffer_pool(pool
, flags
);
2279 for (mask
= pbi
->refresh_frame_flags
; mask
; mask
>>= 1) {
2281 cm
->next_ref_frame_map
[ref_index
] = cm
->new_fb_idx
;
2282 ++frame_bufs
[cm
->new_fb_idx
].ref_count
;
2283 /*pr_info("[MMU DEBUG 4] inc ref_count[%d] : %d\r\n",
2284 *cm->new_fb_idx, frame_bufs[cm->new_fb_idx].ref_count);
2287 cm
->next_ref_frame_map
[ref_index
] =
2288 cm
->ref_frame_map
[ref_index
];
2289 /* Current thread holds the reference frame.*/
2290 if (cm
->ref_frame_map
[ref_index
] >= 0) {
2291 ++frame_bufs
[cm
->ref_frame_map
[ref_index
]].ref_count
;
2293 *("[MMU DEBUG 5] inc ref_count[%d] : %d\r\n",
2294 *cm->ref_frame_map[ref_index],
2295 *frame_bufs[cm->ref_frame_map[ref_index]].ref_count);
2301 for (; ref_index
< REF_FRAMES
; ++ref_index
) {
2302 cm
->next_ref_frame_map
[ref_index
] =
2303 cm
->ref_frame_map
[ref_index
];
2304 /* Current thread holds the reference frame.*/
2305 if (cm
->ref_frame_map
[ref_index
] >= 0) {
2306 ++frame_bufs
[cm
->ref_frame_map
[ref_index
]].ref_count
;
2307 /*pr_info("[MMU DEBUG 6] inc ref_count[%d] : %d\r\n",
2308 *cm->ref_frame_map[ref_index],
2309 *frame_bufs[cm->ref_frame_map[ref_index]].ref_count);
2313 unlock_buffer_pool(pool
, flags
);
2317 static void refresh_ref_frames(struct VP9Decoder_s
*pbi
)
2320 struct VP9_Common_s
*const cm
= &pbi
->common
;
2321 struct BufferPool_s
*pool
= cm
->buffer_pool
;
2322 struct RefCntBuffer_s
*frame_bufs
= cm
->buffer_pool
->frame_bufs
;
2323 int mask
, ref_index
= 0;
2324 unsigned long flags
;
2326 lock_buffer_pool(pool
, flags
);
2327 for (mask
= pbi
->refresh_frame_flags
; mask
; mask
>>= 1) {
2328 const int old_idx
= cm
->ref_frame_map
[ref_index
];
2329 /*Current thread releases the holding of reference frame.*/
2330 decrease_ref_count(old_idx
, frame_bufs
, pool
);
2332 /*Release the reference frame in reference map.*/
2333 if ((mask
& 1) && old_idx
>= 0)
2334 decrease_ref_count(old_idx
, frame_bufs
, pool
);
2335 cm
->ref_frame_map
[ref_index
] =
2336 cm
->next_ref_frame_map
[ref_index
];
2340 /*Current thread releases the holding of reference frame.*/
2341 for (; ref_index
< REF_FRAMES
&& !cm
->show_existing_frame
;
2343 const int old_idx
= cm
->ref_frame_map
[ref_index
];
2345 decrease_ref_count(old_idx
, frame_bufs
, pool
);
2346 cm
->ref_frame_map
[ref_index
] =
2347 cm
->next_ref_frame_map
[ref_index
];
2349 unlock_buffer_pool(pool
, flags
);
2353 int vp9_bufmgr_process(struct VP9Decoder_s
*pbi
, union param_u
*params
)
2355 struct VP9_Common_s
*const cm
= &pbi
->common
;
2356 struct BufferPool_s
*pool
= cm
->buffer_pool
;
2357 struct RefCntBuffer_s
*frame_bufs
= cm
->buffer_pool
->frame_bufs
;
2358 struct PIC_BUFFER_CONFIG_s
*pic
= NULL
;
2362 pbi
->ready_for_new_data
= 0;
2364 if (pbi
->has_keyframe
== 0 &&
2365 params
->p
.frame_type
!= KEY_FRAME
){
2366 on_no_keyframe_skiped
++;
2369 pbi
->has_keyframe
= 1;
2370 on_no_keyframe_skiped
= 0;
2372 if (pbi
->mmu_enable
) {
2373 if (!pbi
->m_ins_flag
)
2374 pbi
->used_4k_num
= (READ_VREG(HEVC_SAO_MMU_STATUS
) >> 16);
2375 if (cm
->prev_fb_idx
>= 0) {
2376 decoder_mmu_box_free_idx_tail(pbi
->mmu_box
,
2377 cm
->prev_fb_idx
, pbi
->used_4k_num
);
2381 if (cm
->new_fb_idx
>= 0
2382 && frame_bufs
[cm
->new_fb_idx
].ref_count
== 0){
2383 vp9_release_frame_buffer
2384 (&frame_bufs
[cm
->new_fb_idx
].raw_frame_buffer
);
2386 /*pr_info("Before get_free_fb, prev_fb_idx : %d, new_fb_idx : %d\r\n",
2387 cm->prev_fb_idx, cm->new_fb_idx);*/
2388 #ifndef MV_USE_FIXED_BUF
2389 put_un_used_mv_bufs(pbi
);
2390 if (debug
& VP9_DEBUG_BUFMGR_DETAIL
)
2393 cm
->new_fb_idx
= pbi
->is_used_v4l
?
2394 v4l_get_free_fb(pbi
) :
2396 if (cm
->new_fb_idx
== INVALID_IDX
) {
2397 pr_info("get_free_fb error\r\n");
2400 #ifndef MV_USE_FIXED_BUF
2401 #ifdef SUPPORT_FB_DECODING
2402 if (pbi
->used_stage_buf_num
== 0) {
2405 &pool
->frame_bufs
[cm
->new_fb_idx
].
2407 &pool
->frame_bufs
[cm
->new_fb_idx
].
2408 buf
.mpred_mv_wr_start_addr
2410 pr_info("get_mv_buf fail\r\n");
2413 if (debug
& VP9_DEBUG_BUFMGR_DETAIL
)
2415 #ifdef SUPPORT_FB_DECODING
2419 cm
->cur_frame
= &pool
->frame_bufs
[cm
->new_fb_idx
];
2420 /*if (debug & VP9_DEBUG_BUFMGR)
2421 pr_info("[VP9 DEBUG]%s(get_free_fb): %d\r\n", __func__,
2424 pbi
->cur_buf
= &frame_bufs
[cm
->new_fb_idx
];
2425 if (pbi
->mmu_enable
) {
2426 /* moved to after picture size ready
2427 *alloc_mmu(cm, params->p.width, params->p.height,
2428 *params->p.bit_depth, pbi->frame_mmu_map_addr);
2430 cm
->prev_fb_idx
= cm
->new_fb_idx
;
2432 /*read_uncompressed_header()*/
2433 cm
->last_frame_type
= cm
->frame_type
;
2434 cm
->last_intra_only
= cm
->intra_only
;
2435 cm
->profile
= params
->p
.profile
;
2436 if (cm
->profile
>= MAX_PROFILES
) {
2437 pr_err("Error: Unsupported profile %d\r\n", cm
->profile
);
2440 cm
->show_existing_frame
= params
->p
.show_existing_frame
;
2441 if (cm
->show_existing_frame
) {
2442 /* Show an existing frame directly.*/
2443 int frame_to_show_idx
= params
->p
.frame_to_show_idx
;
2445 unsigned long flags
;
2446 if (frame_to_show_idx
>= REF_FRAMES
) {
2447 pr_info("frame_to_show_idx %d exceed max index\r\n",
2452 frame_to_show
= cm
->ref_frame_map
[frame_to_show_idx
];
2453 /*pr_info("frame_to_show %d\r\n", frame_to_show);*/
2454 lock_buffer_pool(pool
, flags
);
2455 if (frame_to_show
< 0 ||
2456 frame_bufs
[frame_to_show
].ref_count
< 1) {
2457 unlock_buffer_pool(pool
, flags
);
2459 ("Error:Buffer %d does not contain a decoded frame",
2464 ref_cnt_fb(frame_bufs
, &cm
->new_fb_idx
, frame_to_show
);
2465 unlock_buffer_pool(pool
, flags
);
2466 pbi
->refresh_frame_flags
= 0;
2467 /*cm->lf.filter_level = 0;*/
2471 *if (pbi->frame_parallel_decode) {
2472 * for (i = 0; i < REF_FRAMES; ++i)
2473 * cm->next_ref_frame_map[i] =
2474 * cm->ref_frame_map[i];
2477 /* do not decode, search next start code */
2480 cm
->frame_type
= params
->p
.frame_type
;
2481 cm
->show_frame
= params
->p
.show_frame
;
2482 cm
->error_resilient_mode
= params
->p
.error_resilient_mode
;
2485 if (cm
->frame_type
== KEY_FRAME
) {
2486 pbi
->refresh_frame_flags
= (1 << REF_FRAMES
) - 1;
2488 for (i
= 0; i
< REFS_PER_FRAME
; ++i
) {
2489 cm
->frame_refs
[i
].idx
= INVALID_IDX
;
2490 cm
->frame_refs
[i
].buf
= NULL
;
2493 ret
= setup_frame_size(pbi
,
2494 cm
, params
, pbi
->frame_mmu_map_addr
,
2498 if (pbi
->need_resync
) {
2499 memset(&cm
->ref_frame_map
, -1,
2500 sizeof(cm
->ref_frame_map
));
2501 pbi
->need_resync
= 0;
2504 cm
->intra_only
= cm
->show_frame
? 0 : params
->p
.intra_only
;
2505 /*if (print_header_info) {
2506 * if (cm->show_frame)
2508 * ("intra_only set to 0 because of show_frame\n");
2511 * ("1-bit intra_only read: %d\n", cm->intra_only);
2516 cm
->reset_frame_context
= cm
->error_resilient_mode
?
2517 0 : params
->p
.reset_frame_context
;
2518 if (print_header_info
) {
2519 if (cm
->error_resilient_mode
)
2521 ("reset to 0 error_resilient_mode\n");
2524 (" * 2-bits reset_frame_context read : %d\n",
2525 cm
->reset_frame_context
);
2528 if (cm
->intra_only
) {
2529 if (cm
->profile
> PROFILE_0
) {
2530 /*read_bitdepth_colorspace_sampling(cm,
2531 * rb, print_header_info);
2534 /*NOTE: The intra-only frame header
2535 *does not include the specification
2536 *of either the color format or
2538 *in profile 0. VP9 specifies that the default
2539 *color format should be YUV 4:2:0 in this
2542 cm
->color_space
= VPX_CS_BT_601
;
2543 cm
->subsampling_y
= cm
->subsampling_x
= 1;
2544 cm
->bit_depth
= VPX_BITS_8
;
2545 cm
->use_highbitdepth
= 0;
2548 pbi
->refresh_frame_flags
=
2549 params
->p
.refresh_frame_flags
;
2550 /*if (print_header_info)
2551 * pr_info("*%d-bits refresh_frame read:0x%x\n",
2552 * REF_FRAMES, pbi->refresh_frame_flags);
2554 ret
= setup_frame_size(pbi
,
2557 pbi
->frame_mmu_map_addr
,
2561 if (pbi
->need_resync
) {
2562 memset(&cm
->ref_frame_map
, -1,
2563 sizeof(cm
->ref_frame_map
));
2564 pbi
->need_resync
= 0;
2566 } else if (pbi
->need_resync
!= 1) { /* Skip if need resync */
2567 pbi
->refresh_frame_flags
=
2568 params
->p
.refresh_frame_flags
;
2569 if (print_header_info
)
2571 ("*%d-bits refresh_frame read:0x%x\n",
2572 REF_FRAMES
, pbi
->refresh_frame_flags
);
2573 for (i
= 0; i
< REFS_PER_FRAME
; ++i
) {
2575 (params
->p
.ref_info
>>
2576 (((REFS_PER_FRAME
-i
-1)*4)+1))
2579 cm
->ref_frame_map
[ref
];
2580 struct RefBuffer_s
* const ref_frame
=
2582 if (print_header_info
)
2583 pr_info("*%d-bits ref[%d]read:%d\n",
2584 REF_FRAMES_LOG2
, i
, ref
);
2585 ref_frame
->idx
= idx
;
2586 ref_frame
->buf
= &frame_bufs
[idx
].buf
;
2587 cm
->ref_frame_sign_bias
[LAST_FRAME
+ i
]
2588 = (params
->p
.ref_info
>>
2589 ((REFS_PER_FRAME
-i
-1)*4)) & 0x1;
2590 if (print_header_info
)
2591 pr_info("1bit ref_frame_sign_bias");
2595 *cm->ref_frame_sign_bias
2599 *("[VP9 DEBUG]%s(get ref):%d\r\n",
2600 *__func__, ref_frame->idx);
2605 ret
= setup_frame_size_with_refs(
2609 pbi
->frame_mmu_map_addr
,
2613 for (i
= 0; i
< REFS_PER_FRAME
; ++i
) {
2614 /*struct RefBuffer_s *const ref_buf =
2615 *&cm->frame_refs[i];
2618 *vp9_setup_scale_factors_for_frame
2624 pic
= get_frame_new_buffer(cm
);
2628 pic
->bit_depth
= cm
->bit_depth
;
2629 pic
->color_space
= cm
->color_space
;
2630 pic
->slice_type
= cm
->frame_type
;
2632 if (pbi
->need_resync
) {
2634 ("Error: Keyframe/intra-only frame required to reset\r\n");
2637 generate_next_ref_frames(pbi
);
2638 pbi
->hold_ref_buf
= 1;
2641 if (frame_is_intra_only(cm
) || cm
->error_resilient_mode
)
2642 vp9_setup_past_independence(cm
);
2643 setup_loopfilter(&cm
->lf
, rb
, print_header_info
);
2644 setup_quantization(cm
, &pbi
->mb
, rb
, print_header_info
);
2645 setup_segmentation(&cm
->seg
, rb
, print_header_info
);
2646 setup_segmentation_dequant(cm
, print_header_info
);
2648 setup_tile_info(cm
, rb
, print_header_info
);
2649 sz
= vp9_rb_read_literal(rb
, 16);
2650 if (print_header_info
)
2651 pr_info(" * 16-bits size read : %d (0x%x)\n", sz
, sz
);
2654 vpx_internal_error(&cm
->error
, VPX_CODEC_CORRUPT_FRAME
,
2655 "Invalid header size");
2657 /*end read_uncompressed_header()*/
2658 cm
->use_prev_frame_mvs
= !cm
->error_resilient_mode
&&
2659 cm
->width
== cm
->last_width
&&
2660 cm
->height
== cm
->last_height
&&
2661 !cm
->last_intra_only
&&
2662 cm
->last_show_frame
&&
2663 (cm
->last_frame_type
!= KEY_FRAME
);
2666 *("set use_prev_frame_mvs to %d (last_width %d last_height %d",
2667 *cm->use_prev_frame_mvs, cm->last_width, cm->last_height);
2669 *(" last_intra_only %d last_show_frame %d last_frame_type %d)\n",
2670 *cm->last_intra_only, cm->last_show_frame, cm->last_frame_type);
2676 void swap_frame_buffers(struct VP9Decoder_s
*pbi
)
2679 struct VP9_Common_s
*const cm
= &pbi
->common
;
2680 struct BufferPool_s
*const pool
= cm
->buffer_pool
;
2681 struct RefCntBuffer_s
*const frame_bufs
= cm
->buffer_pool
->frame_bufs
;
2682 unsigned long flags
;
2683 refresh_ref_frames(pbi
);
2684 pbi
->hold_ref_buf
= 0;
2685 cm
->frame_to_show
= get_frame_new_buffer(cm
);
2687 if (cm
->frame_to_show
) {
2688 /*if (!pbi->frame_parallel_decode || !cm->show_frame) {*/
2689 lock_buffer_pool(pool
, flags
);
2690 --frame_bufs
[cm
->new_fb_idx
].ref_count
;
2691 /*pr_info("[MMU DEBUG 8] dec ref_count[%d] : %d\r\n", cm->new_fb_idx,
2692 * frame_bufs[cm->new_fb_idx].ref_count);
2694 unlock_buffer_pool(pool
, flags
);
2698 /*Invalidate these references until the next frame starts.*/
2699 for (ref_index
= 0; ref_index
< 3; ref_index
++)
2700 cm
->frame_refs
[ref_index
].idx
= -1;
2704 static void check_resync(vpx_codec_alg_priv_t
*const ctx
,
2705 const struct VP9Decoder_s
*const pbi
)
2707 /* Clear resync flag if worker got a key frame or intra only frame.*/
2708 if (ctx
->need_resync
== 1 && pbi
->need_resync
== 0 &&
2709 (pbi
->common
.intra_only
|| pbi
->common
.frame_type
== KEY_FRAME
))
2710 ctx
->need_resync
= 0;
2714 int vp9_get_raw_frame(struct VP9Decoder_s
*pbi
, struct PIC_BUFFER_CONFIG_s
*sd
)
2716 struct VP9_Common_s
*const cm
= &pbi
->common
;
2719 if (pbi
->ready_for_new_data
== 1)
2722 pbi
->ready_for_new_data
= 1;
2724 /* no raw frame to show!!! */
2725 if (!cm
->show_frame
)
2728 /* may not be get buff in v4l2 */
2729 if (!cm
->frame_to_show
)
2732 pbi
->ready_for_new_data
= 1;
2734 *sd
= *cm
->frame_to_show
;
2740 int vp9_bufmgr_init(struct VP9Decoder_s
*pbi
, struct BuffInfo_s
*buf_spec_i
,
2741 struct buff_s
*mc_buf_i
) {
2742 struct VP9_Common_s
*cm
= &pbi
->common
;
2744 /*memset(pbi, 0, sizeof(struct VP9Decoder_s));*/
2745 pbi
->frame_count
= 0;
2747 pbi
->pre_stream_offset
= 0;
2748 cm
->buffer_pool
= &pbi
->vp9_buffer_pool
;
2749 spin_lock_init(&cm
->buffer_pool
->lock
);
2750 cm
->prev_fb_idx
= INVALID_IDX
;
2751 cm
->new_fb_idx
= INVALID_IDX
;
2752 pbi
->used_4k_num
= -1;
2753 cm
->cur_fb_idx_mmu
= INVALID_IDX
;
2755 ("After vp9_bufmgr_init, prev_fb_idx : %d, new_fb_idx : %d\r\n",
2756 cm
->prev_fb_idx
, cm
->new_fb_idx
);
2757 pbi
->need_resync
= 1;
2758 /* Initialize the references to not point to any frame buffers.*/
2759 memset(&cm
->ref_frame_map
, -1, sizeof(cm
->ref_frame_map
));
2760 memset(&cm
->next_ref_frame_map
, -1, sizeof(cm
->next_ref_frame_map
));
2761 cm
->current_video_frame
= 0;
2762 pbi
->ready_for_new_data
= 1;
2765 pbi
->work_space_buf
= buf_spec_i
;
2766 if (!pbi
->mmu_enable
)
2767 pbi
->mc_buf
= mc_buf_i
;
2769 pbi
->rpm_addr
= NULL
;
2770 pbi
->lmem_addr
= NULL
;
2772 pbi
->use_cma_flag
= 0;
2773 pbi
->decode_idx
= 0;
2775 /*int m_uiMaxCUWidth = 1<<7;*/
2776 /*int m_uiMaxCUHeight = 1<<7;*/
2777 pbi
->has_keyframe
= 0;
2780 pbi
->error_flag
= 0;
2782 pbi
->pts_mode
= PTS_NORMAL
;
2784 pbi
->last_lookup_pts
= 0;
2785 pbi
->last_pts_us64
= 0;
2786 pbi
->last_lookup_pts_us64
= 0;
2787 pbi
->shift_byte_count
= 0;
2788 pbi
->shift_byte_count_lo
= 0;
2789 pbi
->shift_byte_count_hi
= 0;
2790 pbi
->pts_mode_switching_count
= 0;
2791 pbi
->pts_mode_recovery_count
= 0;
2799 int vp9_bufmgr_postproc(struct VP9Decoder_s
*pbi
)
2801 struct VP9_Common_s
*cm
= &pbi
->common
;
2802 struct PIC_BUFFER_CONFIG_s sd
;
2804 if (pbi
->postproc_done
)
2806 pbi
->postproc_done
= 1;
2807 swap_frame_buffers(pbi
);
2808 if (!cm
->show_existing_frame
) {
2809 cm
->last_show_frame
= cm
->show_frame
;
2810 cm
->prev_frame
= cm
->cur_frame
;
2812 if (cm
->seg
.enabled
&& !pbi
->frame_parallel_decode
)
2813 vp9_swap_current_and_last_seg_map(cm
);
2816 cm
->last_width
= cm
->width
;
2817 cm
->last_height
= cm
->height
;
2819 cm
->current_video_frame
++;
2821 if (vp9_get_raw_frame(pbi
, &sd
) == 0) {
2822 /*pr_info("Display frame index %d\r\n", sd.index);*/
2823 sd
.stream_offset
= pbi
->pre_stream_offset
;
2824 prepare_display_buf(pbi
, &sd
);
2825 pbi
->pre_stream_offset
= READ_VREG(HEVC_SHIFT_BYTE_COUNT
);
2830 * ("Not display this frame,ready_for_new_data%d show_frame%d\r\n",
2831 * pbi->ready_for_new_data, cm->show_frame);
2836 /*struct VP9Decoder_s vp9_decoder;*/
2837 union param_u vp9_param
;
2839 /**************************************************
2841 *VP9 buffer management end
2843 ***************************************************
2847 #define HEVC_CM_BODY_START_ADDR 0x3626
2848 #define HEVC_CM_BODY_LENGTH 0x3627
2849 #define HEVC_CM_HEADER_LENGTH 0x3629
2850 #define HEVC_CM_HEADER_OFFSET 0x362b
2852 #define LOSLESS_COMPRESS_MODE
2854 /*#define DECOMP_HEADR_SURGENT*/
2856 static u32 mem_map_mode
= 2 /* 0:linear 1:32x32 2:64x32*/
2858 static u32 mem_map_mode
; /* 0:linear 1:32x32 2:64x32 ; m8baby test1902 */
2860 static u32 enable_mem_saving
= 1;
2861 static u32 force_w_h
;
2863 static u32 force_fps
;
2866 const u32 vp9_version
= 201602101;
2870 static u32 pop_shorts
;
2872 static u32 dbg_skip_decode_index
;
2873 static u32 endian
= 0xff0;
2874 #ifdef ERROR_HANDLE_DEBUG
2875 static u32 dbg_nal_skip_flag
;
2876 /* bit[0], skip vps; bit[1], skip sps; bit[2], skip pps */
2877 static u32 dbg_nal_skip_count
;
2880 static u32 decode_pic_begin
;
2881 static uint slice_parse_begin
;
2883 #ifdef MIX_STREAM_SUPPORT
2884 static u32 buf_alloc_width
= 4096;
2885 static u32 buf_alloc_height
= 2304;
2886 static u32 vp9_max_pic_w
= 4096;
2887 static u32 vp9_max_pic_h
= 2304;
2889 static u32 dynamic_buf_num_margin
;
2891 static u32 buf_alloc_width
;
2892 static u32 buf_alloc_height
;
2893 static u32 dynamic_buf_num_margin
= 7;
2895 static u32 buf_alloc_depth
= 10;
2896 static u32 buf_alloc_size
;
2899 * bit[1]: 0, always release cma buffer when stop
2900 * bit[1]: 1, never release cma buffer when stop
2901 *bit[0]: 1, when stop, release cma buffer if blackout is 1;
2902 *do not release cma buffer is blackout is not 1
2904 *bit[2]: 0, when start decoding, check current displayed buffer
2905 * (only for buffer decoded by vp9) if blackout is 0
2906 * 1, do not check current displayed buffer
2908 *bit[3]: 1, if blackout is not 1, do not release current
2909 * displayed cma buffer always.
2911 /* set to 1 for fast play;
2912 * set to 8 for other case of "keep last frame"
2914 static u32 buffer_mode
= 1;
2915 /* buffer_mode_dbg: debug only*/
2916 static u32 buffer_mode_dbg
= 0xffff0000;
2920 *bit 0, 1: only display I picture;
2921 *bit 1, 1: only decode I picture;
2923 static u32 i_only_flag
;
2925 static u32 low_latency_flag
;
2929 static u32 max_decoding_time
;
2933 /*error_handle_policy:
2934 *bit 0: 0, auto skip error_skip_nal_count nals before error recovery;
2935 *1, skip error_skip_nal_count nals before error recovery;
2936 *bit 1 (valid only when bit0 == 1):
2937 *1, wait vps/sps/pps after error recovery;
2938 *bit 2 (valid only when bit0 == 0):
2939 *0, auto search after error recovery (vp9_recover() called);
2940 *1, manual search after error recovery
2941 *(change to auto search after get IDR: WRITE_VREG(NAL_SEARCH_CTL, 0x2))
2943 *bit 4: 0, set error_mark after reset/recover
2944 * 1, do not set error_mark after reset/recover
2945 *bit 5: 0, check total lcu for every picture
2946 * 1, do not check total lcu
2950 static u32 error_handle_policy
;
2951 /*static u32 parser_sei_enable = 1;*/
2952 #define MAX_BUF_NUM_NORMAL 12
2953 #define MAX_BUF_NUM_LESS 10
2954 static u32 max_buf_num
= MAX_BUF_NUM_NORMAL
;
2955 #define MAX_BUF_NUM_SAVE_BUF 8
2957 static u32 run_ready_min_buf_num
= 2;
2960 static DEFINE_MUTEX(vvp9_mutex
);
2961 #ifndef MULTI_INSTANCE_SUPPORT
2962 static struct device
*cma_dev
;
2965 #define HEVC_DEC_STATUS_REG HEVC_ASSIST_SCRATCH_0
2966 #define HEVC_RPM_BUFFER HEVC_ASSIST_SCRATCH_1
2967 #define HEVC_SHORT_TERM_RPS HEVC_ASSIST_SCRATCH_2
2968 #define VP9_ADAPT_PROB_REG HEVC_ASSIST_SCRATCH_3
2969 #define VP9_MMU_MAP_BUFFER HEVC_ASSIST_SCRATCH_4
2970 #define HEVC_PPS_BUFFER HEVC_ASSIST_SCRATCH_5
2971 #define HEVC_SAO_UP HEVC_ASSIST_SCRATCH_6
2972 #define HEVC_STREAM_SWAP_BUFFER HEVC_ASSIST_SCRATCH_7
2973 #define HEVC_STREAM_SWAP_BUFFER2 HEVC_ASSIST_SCRATCH_8
2974 #define VP9_PROB_SWAP_BUFFER HEVC_ASSIST_SCRATCH_9
2975 #define VP9_COUNT_SWAP_BUFFER HEVC_ASSIST_SCRATCH_A
2976 #define VP9_SEG_MAP_BUFFER HEVC_ASSIST_SCRATCH_B
2977 #define HEVC_SCALELUT HEVC_ASSIST_SCRATCH_D
2978 #define HEVC_WAIT_FLAG HEVC_ASSIST_SCRATCH_E
2979 #define RPM_CMD_REG HEVC_ASSIST_SCRATCH_F
2980 #define LMEM_DUMP_ADR HEVC_ASSIST_SCRATCH_F
2981 #define HEVC_STREAM_SWAP_TEST HEVC_ASSIST_SCRATCH_L
2982 #ifdef MULTI_INSTANCE_SUPPORT
2983 #define HEVC_DECODE_COUNT HEVC_ASSIST_SCRATCH_M
2984 #define HEVC_DECODE_SIZE HEVC_ASSIST_SCRATCH_N
2986 #define HEVC_DECODE_PIC_BEGIN_REG HEVC_ASSIST_SCRATCH_M
2987 #define HEVC_DECODE_PIC_NUM_REG HEVC_ASSIST_SCRATCH_N
2989 #define DEBUG_REG1 HEVC_ASSIST_SCRATCH_G
2990 #define DEBUG_REG2 HEVC_ASSIST_SCRATCH_H
2994 *ucode parser/search control
2995 *bit 0: 0, header auto parse; 1, header manual parse
2996 *bit 1: 0, auto skip for noneseamless stream; 1, no skip
2997 *bit [3:2]: valid when bit1==0;
2998 *0, auto skip nal before first vps/sps/pps/idr;
2999 *1, auto skip nal before first vps/sps/pps
3000 *2, auto skip nal before first vps/sps/pps,
3001 * and not decode until the first I slice (with slice address of 0)
3003 *3, auto skip before first I slice (nal_type >=16 && nal_type<=21)
3004 *bit [15:4] nal skip count (valid when bit0 == 1 (manual mode) )
3005 *bit [16]: for NAL_UNIT_EOS when bit0 is 0:
3006 * 0, send SEARCH_DONE to arm ; 1, do not send SEARCH_DONE to arm
3007 *bit [17]: for NAL_SEI when bit0 is 0:
3008 * 0, do not parse SEI in ucode; 1, parse SEI in ucode
3009 *bit [31:20]: used by ucode for debug purpose
3011 #define NAL_SEARCH_CTL HEVC_ASSIST_SCRATCH_I
3012 /*[31:24] chip feature
3013 31: 0, use MBOX1; 1, use MBOX0
3015 #define DECODE_MODE HEVC_ASSIST_SCRATCH_J
3016 #define DECODE_STOP_POS HEVC_ASSIST_SCRATCH_K
3018 #ifdef MULTI_INSTANCE_SUPPORT
3019 #define RPM_BUF_SIZE (0x400 * 2)
3021 #define RPM_BUF_SIZE (0x80*2)
3023 #define LMEM_BUF_SIZE (0x400 * 2)
3025 #define WORK_BUF_SPEC_NUM 3
3026 static struct BuffInfo_s amvvp9_workbuff_spec
[WORK_BUF_SPEC_NUM
] = {
3032 /* IPP work space calculation :
3033 * 4096 * (Y+CbCr+Flags) = 12k, round to 16k
3038 .buf_size
= 0x30000,
3041 .buf_size
= 0x30000,
3044 /* SHORT_TERM_RPS - Max 64 set, 16 entry every set,
3045 * total 64x16x2 = 2048 bytes (0x800)
3050 /* VPS STORE AREA - Max 16 VPS, each has 0x80 bytes,
3051 * total 0x0800 bytes
3056 /* SPS STORE AREA - Max 16 SPS, each has 0x80 bytes,
3057 * total 0x0800 bytes
3062 /* PPS STORE AREA - Max 64 PPS, each has 0x80 bytes,
3063 * total 0x2000 bytes
3068 /* SAO UP STORE AREA - Max 640(10240/16) LCU,
3069 * each has 16 bytes total 0x2800 bytes
3074 /* 256cyclex64bit = 2K bytes 0x800
3075 * (only 144 cycles valid)
3083 /* support up to 32 SCALELUT 1024x32 =
3089 /* DBLK -> Max 256(4096/16) LCU,
3090 *each para 1024bytes(total:0x40000),
3091 *data 1024bytes(total:0x40000)
3093 .buf_size
= 0x80000,
3096 .buf_size
= 0x80000,
3099 /*4096x2304/64/64 *24 = 0xd800 Bytes*/
3103 .buf_size
= 0x5000, /*2*16*(more than 2304)/4, 4K*/
3107 /*add one for keeper.*/
3108 .buf_size
= MMU_COMPRESS_HEADER_SIZE
*
3109 (FRAME_BUFFERS
+ 1),
3110 /* 0x44000 = ((1088*2*1024*4)/32/4)*(32/8) */
3114 .buf_size
= 0x10000, /* 2 * size of hevc*/
3116 #ifdef MV_USE_FIXED_BUF
3117 .mpred_mv
= {/* 1080p, 0x40000 per buffer */
3118 .buf_size
= 0x40000 * FRAME_BUFFERS
,
3122 .buf_size
= RPM_BUF_SIZE
,
3125 .buf_size
= 0x400 * 2,
3132 /* IPP work space calculation :
3133 * 4096 * (Y+CbCr+Flags) = 12k, round to 16k
3138 .buf_size
= 0x30000,
3141 .buf_size
= 0x30000,
3144 /* SHORT_TERM_RPS - Max 64 set, 16 entry every set,
3145 * total 64x16x2 = 2048 bytes (0x800)
3150 /* VPS STORE AREA - Max 16 VPS, each has 0x80 bytes,
3151 * total 0x0800 bytes
3156 /* SPS STORE AREA - Max 16 SPS, each has 0x80 bytes,
3157 * total 0x0800 bytes
3162 /* PPS STORE AREA - Max 64 PPS, each has 0x80 bytes,
3163 * total 0x2000 bytes
3168 /* SAO UP STORE AREA - Max 640(10240/16) LCU,
3169 * each has 16 bytes total 0x2800 bytes
3174 /* 256cyclex64bit = 2K bytes 0x800
3175 * (only 144 cycles valid)
3183 /* support up to 32 SCALELUT 1024x32 = 32Kbytes
3189 /* DBLK -> Max 256(4096/16) LCU,
3190 *each para 1024bytes(total:0x40000),
3191 *data 1024bytes(total:0x40000)
3193 .buf_size
= 0x80000,
3196 .buf_size
= 0x80000,
3199 /*4096x2304/64/64 *24 = 0xd800 Bytes*/
3203 .buf_size
= 0x5000,/*2*16*(more than 2304)/4, 4K*/
3207 /*add one for keeper.*/
3208 .buf_size
= MMU_COMPRESS_HEADER_SIZE
*
3209 (FRAME_BUFFERS
+ 1),
3210 /* 0x44000 = ((1088*2*1024*4)/32/4)*(32/8) */
3214 .buf_size
= 0x10000, /* 2 * size of hevc*/
3216 #ifdef MV_USE_FIXED_BUF
3218 /* .buf_size = 0x100000*16,
3219 * //4k2k , 0x100000 per buffer
3221 /* 4096x2304 , 0x120000 per buffer */
3222 .buf_size
= 0x120000 * FRAME_BUFFERS
,
3226 .buf_size
= RPM_BUF_SIZE
,
3229 .buf_size
= 0x400 * 2,
3233 .max_width
= 4096*2,
3234 .max_height
= 2304*2,
3236 // IPP work space calculation : 4096 * (Y+CbCr+Flags) = 12k, round to 16k
3237 .buf_size
= 0x4000*2,
3240 .buf_size
= 0x30000*2,
3243 .buf_size
= 0x30000*2,
3246 // SHORT_TERM_RPS - Max 64 set, 16 entry every set, total 64x16x2 = 2048 bytes (0x800)
3250 // VPS STORE AREA - Max 16 VPS, each has 0x80 bytes, total 0x0800 bytes
3254 // SPS STORE AREA - Max 16 SPS, each has 0x80 bytes, total 0x0800 bytes
3258 // PPS STORE AREA - Max 64 PPS, each has 0x80 bytes, total 0x2000 bytes
3262 // SAO UP STORE AREA - Max 640(10240/16) LCU, each has 16 bytes total 0x2800 bytes
3263 .buf_size
= 0x2800*2,
3266 // 256cyclex64bit = 2K bytes 0x800 (only 144 cycles valid)
3273 // support up to 32 SCALELUT 1024x32 = 32Kbytes (0x8000)
3274 .buf_size
= 0x8000*2,
3277 // DBLK -> Max 256(4096/16) LCU, each para 1024bytes(total:0x40000), data 1024bytes(total:0x40000)
3278 .buf_size
= 0x80000*2,
3281 .buf_size
= 0x80000*2,
3284 /*4096x2304/64/64 *24 = 0xd800 Bytes*/
3285 .buf_size
= 0xd800*4,
3288 .buf_size
= 0x5000*2, //2*16*(more than 2304)/4, 4K
3292 //.buf_size = MMU_COMPRESS_HEADER_SIZE*8, // 0x44000 = ((1088*2*1024*4)/32/4)*(32/8)
3293 .buf_size
= MMU_COMPRESS_HEADER_SIZE
*16, // 0x44000 = ((1088*2*1024*4)/32/4)*(32/8)
3297 .buf_size
= 0x10000*2, /* 2 * size of hevc*/
3299 #ifdef MV_USE_FIXED_BUF
3301 //4k2k , 0x100000 per buffer */
3302 /* 4096x2304 , 0x120000 per buffer */
3303 .buf_size
= 0x120000 * FRAME_BUFFERS
* 4,
3307 .buf_size
= RPM_BUF_SIZE
,
3310 .buf_size
= 0x400 * 2,
3316 /*Losless compression body buffer size 4K per 64x32 (jt)*/
3317 int compute_losless_comp_body_size(int width
, int height
,
3318 uint8_t is_bit_depth_10
)
3324 width_x64
= width
+ 63;
3326 height_x32
= height
+ 31;
3328 bsize
= (is_bit_depth_10
?4096:3200)*width_x64
*height_x32
;
3329 if (debug
& VP9_DEBUG_BUFMGR_MORE
)
3330 pr_info("%s(%d,%d,%d)=>%d\n",
3331 __func__
, width
, height
,
3332 is_bit_depth_10
, bsize
);
3337 /* Losless compression header buffer size 32bytes per 128x64 (jt)*/
3338 static int compute_losless_comp_header_size(int width
, int height
)
3344 width_x128
= width
+ 127;
3346 height_x64
= height
+ 63;
3349 hsize
= 32 * width_x128
* height_x64
;
3350 if (debug
& VP9_DEBUG_BUFMGR_MORE
)
3351 pr_info("%s(%d,%d)=>%d\n",
3352 __func__
, width
, height
,
3358 static void init_buff_spec(struct VP9Decoder_s
*pbi
,
3359 struct BuffInfo_s
*buf_spec
)
3361 void *mem_start_virt
;
3363 buf_spec
->ipp
.buf_start
= buf_spec
->start_adr
;
3364 buf_spec
->sao_abv
.buf_start
=
3365 buf_spec
->ipp
.buf_start
+ buf_spec
->ipp
.buf_size
;
3367 buf_spec
->sao_vb
.buf_start
=
3368 buf_spec
->sao_abv
.buf_start
+ buf_spec
->sao_abv
.buf_size
;
3369 buf_spec
->short_term_rps
.buf_start
=
3370 buf_spec
->sao_vb
.buf_start
+ buf_spec
->sao_vb
.buf_size
;
3371 buf_spec
->vps
.buf_start
=
3372 buf_spec
->short_term_rps
.buf_start
+
3373 buf_spec
->short_term_rps
.buf_size
;
3374 buf_spec
->sps
.buf_start
=
3375 buf_spec
->vps
.buf_start
+ buf_spec
->vps
.buf_size
;
3376 buf_spec
->pps
.buf_start
=
3377 buf_spec
->sps
.buf_start
+ buf_spec
->sps
.buf_size
;
3378 buf_spec
->sao_up
.buf_start
=
3379 buf_spec
->pps
.buf_start
+ buf_spec
->pps
.buf_size
;
3380 buf_spec
->swap_buf
.buf_start
=
3381 buf_spec
->sao_up
.buf_start
+ buf_spec
->sao_up
.buf_size
;
3382 buf_spec
->swap_buf2
.buf_start
=
3383 buf_spec
->swap_buf
.buf_start
+ buf_spec
->swap_buf
.buf_size
;
3384 buf_spec
->scalelut
.buf_start
=
3385 buf_spec
->swap_buf2
.buf_start
+ buf_spec
->swap_buf2
.buf_size
;
3386 buf_spec
->dblk_para
.buf_start
=
3387 buf_spec
->scalelut
.buf_start
+ buf_spec
->scalelut
.buf_size
;
3388 buf_spec
->dblk_data
.buf_start
=
3389 buf_spec
->dblk_para
.buf_start
+ buf_spec
->dblk_para
.buf_size
;
3390 buf_spec
->seg_map
.buf_start
=
3391 buf_spec
->dblk_data
.buf_start
+ buf_spec
->dblk_data
.buf_size
;
3392 if (pbi
== NULL
|| pbi
->mmu_enable
) {
3393 buf_spec
->mmu_vbh
.buf_start
=
3394 buf_spec
->seg_map
.buf_start
+
3395 buf_spec
->seg_map
.buf_size
;
3396 buf_spec
->mpred_above
.buf_start
=
3397 buf_spec
->mmu_vbh
.buf_start
+
3398 buf_spec
->mmu_vbh
.buf_size
;
3400 buf_spec
->mpred_above
.buf_start
=
3401 buf_spec
->seg_map
.buf_start
+ buf_spec
->seg_map
.buf_size
;
3403 #ifdef MV_USE_FIXED_BUF
3404 buf_spec
->mpred_mv
.buf_start
=
3405 buf_spec
->mpred_above
.buf_start
+
3406 buf_spec
->mpred_above
.buf_size
;
3408 buf_spec
->rpm
.buf_start
=
3409 buf_spec
->mpred_mv
.buf_start
+
3410 buf_spec
->mpred_mv
.buf_size
;
3412 buf_spec
->rpm
.buf_start
=
3413 buf_spec
->mpred_above
.buf_start
+
3414 buf_spec
->mpred_above
.buf_size
;
3417 buf_spec
->lmem
.buf_start
=
3418 buf_spec
->rpm
.buf_start
+
3419 buf_spec
->rpm
.buf_size
;
3421 buf_spec
->lmem
.buf_start
+
3422 buf_spec
->lmem
.buf_size
;
3427 if (!vdec_secure(hw_to_vdec(pbi
))) {
3429 codec_mm_phys_to_virt(buf_spec
->dblk_para
.buf_start
);
3430 if (mem_start_virt
) {
3431 memset(mem_start_virt
, 0,
3432 buf_spec
->dblk_para
.buf_size
);
3433 codec_mm_dma_flush(mem_start_virt
,
3434 buf_spec
->dblk_para
.buf_size
,
3437 mem_start_virt
= codec_mm_vmap(
3438 buf_spec
->dblk_para
.buf_start
,
3439 buf_spec
->dblk_para
.buf_size
);
3440 if (mem_start_virt
) {
3441 memset(mem_start_virt
, 0,
3442 buf_spec
->dblk_para
.buf_size
);
3443 codec_mm_dma_flush(mem_start_virt
,
3444 buf_spec
->dblk_para
.buf_size
,
3446 codec_mm_unmap_phyaddr(mem_start_virt
);
3448 /*not virt for tvp playing,
3449 may need clear on ucode.*/
3450 pr_err("mem_start_virt failed\n");
3456 pr_info("%s workspace (%x %x) size = %x\n", __func__
,
3457 buf_spec
->start_adr
, buf_spec
->end_adr
,
3458 buf_spec
->end_adr
- buf_spec
->start_adr
);
3462 pr_info("ipp.buf_start :%x\n",
3463 buf_spec
->ipp
.buf_start
);
3464 pr_info("sao_abv.buf_start :%x\n",
3465 buf_spec
->sao_abv
.buf_start
);
3466 pr_info("sao_vb.buf_start :%x\n",
3467 buf_spec
->sao_vb
.buf_start
);
3468 pr_info("short_term_rps.buf_start :%x\n",
3469 buf_spec
->short_term_rps
.buf_start
);
3470 pr_info("vps.buf_start :%x\n",
3471 buf_spec
->vps
.buf_start
);
3472 pr_info("sps.buf_start :%x\n",
3473 buf_spec
->sps
.buf_start
);
3474 pr_info("pps.buf_start :%x\n",
3475 buf_spec
->pps
.buf_start
);
3476 pr_info("sao_up.buf_start :%x\n",
3477 buf_spec
->sao_up
.buf_start
);
3478 pr_info("swap_buf.buf_start :%x\n",
3479 buf_spec
->swap_buf
.buf_start
);
3480 pr_info("swap_buf2.buf_start :%x\n",
3481 buf_spec
->swap_buf2
.buf_start
);
3482 pr_info("scalelut.buf_start :%x\n",
3483 buf_spec
->scalelut
.buf_start
);
3484 pr_info("dblk_para.buf_start :%x\n",
3485 buf_spec
->dblk_para
.buf_start
);
3486 pr_info("dblk_data.buf_start :%x\n",
3487 buf_spec
->dblk_data
.buf_start
);
3488 pr_info("seg_map.buf_start :%x\n",
3489 buf_spec
->seg_map
.buf_start
);
3490 if (pbi
->mmu_enable
) {
3491 pr_info("mmu_vbh.buf_start :%x\n",
3492 buf_spec
->mmu_vbh
.buf_start
);
3494 pr_info("mpred_above.buf_start :%x\n",
3495 buf_spec
->mpred_above
.buf_start
);
3496 #ifdef MV_USE_FIXED_BUF
3497 pr_info("mpred_mv.buf_start :%x\n",
3498 buf_spec
->mpred_mv
.buf_start
);
3500 if ((debug
& VP9_DEBUG_SEND_PARAM_WITH_REG
) == 0) {
3501 pr_info("rpm.buf_start :%x\n",
3502 buf_spec
->rpm
.buf_start
);
3508 #define THODIYIL_MCRCC_CANVAS_ALGX 4
3510 static u32 mcrcc_cache_alg_flag
= THODIYIL_MCRCC_CANVAS_ALGX
;
3512 static void mcrcc_perfcount_reset(void)
3514 if (debug
& VP9_DEBUG_CACHE
)
3515 pr_info("[cache_util.c] Entered mcrcc_perfcount_reset...\n");
3516 WRITE_VREG(HEVCD_MCRCC_PERFMON_CTL
, (unsigned int)0x1);
3517 WRITE_VREG(HEVCD_MCRCC_PERFMON_CTL
, (unsigned int)0x0);
3521 static unsigned raw_mcr_cnt_total_prev
;
3522 static unsigned hit_mcr_0_cnt_total_prev
;
3523 static unsigned hit_mcr_1_cnt_total_prev
;
3524 static unsigned byp_mcr_cnt_nchcanv_total_prev
;
3525 static unsigned byp_mcr_cnt_nchoutwin_total_prev
;
3527 static void mcrcc_get_hitrate(unsigned reset_pre
)
3529 unsigned delta_hit_mcr_0_cnt
;
3530 unsigned delta_hit_mcr_1_cnt
;
3531 unsigned delta_raw_mcr_cnt
;
3532 unsigned delta_mcr_cnt_nchcanv
;
3533 unsigned delta_mcr_cnt_nchoutwin
;
3536 unsigned raw_mcr_cnt
;
3537 unsigned hit_mcr_cnt
;
3538 unsigned byp_mcr_cnt_nchoutwin
;
3539 unsigned byp_mcr_cnt_nchcanv
;
3542 raw_mcr_cnt_total_prev
= 0;
3543 hit_mcr_0_cnt_total_prev
= 0;
3544 hit_mcr_1_cnt_total_prev
= 0;
3545 byp_mcr_cnt_nchcanv_total_prev
= 0;
3546 byp_mcr_cnt_nchoutwin_total_prev
= 0;
3548 if (debug
& VP9_DEBUG_CACHE
)
3549 pr_info("[cache_util.c] Entered mcrcc_get_hitrate...\n");
3550 WRITE_VREG(HEVCD_MCRCC_PERFMON_CTL
, (unsigned int)(0x0<<1));
3551 raw_mcr_cnt
= READ_VREG(HEVCD_MCRCC_PERFMON_DATA
);
3552 WRITE_VREG(HEVCD_MCRCC_PERFMON_CTL
, (unsigned int)(0x1<<1));
3553 hit_mcr_cnt
= READ_VREG(HEVCD_MCRCC_PERFMON_DATA
);
3554 WRITE_VREG(HEVCD_MCRCC_PERFMON_CTL
, (unsigned int)(0x2<<1));
3555 byp_mcr_cnt_nchoutwin
= READ_VREG(HEVCD_MCRCC_PERFMON_DATA
);
3556 WRITE_VREG(HEVCD_MCRCC_PERFMON_CTL
, (unsigned int)(0x3<<1));
3557 byp_mcr_cnt_nchcanv
= READ_VREG(HEVCD_MCRCC_PERFMON_DATA
);
3559 if (debug
& VP9_DEBUG_CACHE
)
3560 pr_info("raw_mcr_cnt_total: %d\n",
3562 if (debug
& VP9_DEBUG_CACHE
)
3563 pr_info("hit_mcr_cnt_total: %d\n",
3565 if (debug
& VP9_DEBUG_CACHE
)
3566 pr_info("byp_mcr_cnt_nchoutwin_total: %d\n",
3567 byp_mcr_cnt_nchoutwin
);
3568 if (debug
& VP9_DEBUG_CACHE
)
3569 pr_info("byp_mcr_cnt_nchcanv_total: %d\n",
3570 byp_mcr_cnt_nchcanv
);
3572 delta_raw_mcr_cnt
= raw_mcr_cnt
-
3573 raw_mcr_cnt_total_prev
;
3574 delta_mcr_cnt_nchcanv
= byp_mcr_cnt_nchcanv
-
3575 byp_mcr_cnt_nchcanv_total_prev
;
3576 delta_mcr_cnt_nchoutwin
= byp_mcr_cnt_nchoutwin
-
3577 byp_mcr_cnt_nchoutwin_total_prev
;
3578 raw_mcr_cnt_total_prev
= raw_mcr_cnt
;
3579 byp_mcr_cnt_nchcanv_total_prev
= byp_mcr_cnt_nchcanv
;
3580 byp_mcr_cnt_nchoutwin_total_prev
= byp_mcr_cnt_nchoutwin
;
3582 WRITE_VREG(HEVCD_MCRCC_PERFMON_CTL
, (unsigned int)(0x4<<1));
3583 tmp
= READ_VREG(HEVCD_MCRCC_PERFMON_DATA
);
3584 if (debug
& VP9_DEBUG_CACHE
)
3585 pr_info("miss_mcr_0_cnt_total: %d\n", tmp
);
3586 WRITE_VREG(HEVCD_MCRCC_PERFMON_CTL
, (unsigned int)(0x5<<1));
3587 tmp
= READ_VREG(HEVCD_MCRCC_PERFMON_DATA
);
3588 if (debug
& VP9_DEBUG_CACHE
)
3589 pr_info("miss_mcr_1_cnt_total: %d\n", tmp
);
3590 WRITE_VREG(HEVCD_MCRCC_PERFMON_CTL
, (unsigned int)(0x6<<1));
3591 tmp
= READ_VREG(HEVCD_MCRCC_PERFMON_DATA
);
3592 if (debug
& VP9_DEBUG_CACHE
)
3593 pr_info("hit_mcr_0_cnt_total: %d\n", tmp
);
3594 delta_hit_mcr_0_cnt
= tmp
- hit_mcr_0_cnt_total_prev
;
3595 hit_mcr_0_cnt_total_prev
= tmp
;
3596 WRITE_VREG(HEVCD_MCRCC_PERFMON_CTL
, (unsigned int)(0x7<<1));
3597 tmp
= READ_VREG(HEVCD_MCRCC_PERFMON_DATA
);
3598 if (debug
& VP9_DEBUG_CACHE
)
3599 pr_info("hit_mcr_1_cnt_total: %d\n", tmp
);
3600 delta_hit_mcr_1_cnt
= tmp
- hit_mcr_1_cnt_total_prev
;
3601 hit_mcr_1_cnt_total_prev
= tmp
;
3603 if (delta_raw_mcr_cnt
!= 0) {
3604 hitrate
= 100 * delta_hit_mcr_0_cnt
3605 / delta_raw_mcr_cnt
;
3606 if (debug
& VP9_DEBUG_CACHE
)
3607 pr_info("CANV0_HIT_RATE : %d\n", hitrate
);
3608 hitrate
= 100 * delta_hit_mcr_1_cnt
3609 / delta_raw_mcr_cnt
;
3610 if (debug
& VP9_DEBUG_CACHE
)
3611 pr_info("CANV1_HIT_RATE : %d\n", hitrate
);
3612 hitrate
= 100 * delta_mcr_cnt_nchcanv
3613 / delta_raw_mcr_cnt
;
3614 if (debug
& VP9_DEBUG_CACHE
)
3615 pr_info("NONCACH_CANV_BYP_RATE : %d\n", hitrate
);
3616 hitrate
= 100 * delta_mcr_cnt_nchoutwin
3617 / delta_raw_mcr_cnt
;
3618 if (debug
& VP9_DEBUG_CACHE
)
3619 pr_info("CACHE_OUTWIN_BYP_RATE : %d\n", hitrate
);
3623 if (raw_mcr_cnt
!= 0) {
3624 hitrate
= 100 * hit_mcr_cnt
/ raw_mcr_cnt
;
3625 if (debug
& VP9_DEBUG_CACHE
)
3626 pr_info("MCRCC_HIT_RATE : %d\n", hitrate
);
3627 hitrate
= 100 * (byp_mcr_cnt_nchoutwin
+ byp_mcr_cnt_nchcanv
)
3629 if (debug
& VP9_DEBUG_CACHE
)
3630 pr_info("MCRCC_BYP_RATE : %d\n", hitrate
);
3632 if (debug
& VP9_DEBUG_CACHE
)
3633 pr_info("MCRCC_HIT_RATE : na\n");
3634 if (debug
& VP9_DEBUG_CACHE
)
3635 pr_info("MCRCC_BYP_RATE : na\n");
3641 static void decomp_perfcount_reset(void)
3643 if (debug
& VP9_DEBUG_CACHE
)
3644 pr_info("[cache_util.c] Entered decomp_perfcount_reset...\n");
3645 WRITE_VREG(HEVCD_MPP_DECOMP_PERFMON_CTL
, (unsigned int)0x1);
3646 WRITE_VREG(HEVCD_MPP_DECOMP_PERFMON_CTL
, (unsigned int)0x0);
3650 static void decomp_get_hitrate(void)
3652 unsigned raw_mcr_cnt
;
3653 unsigned hit_mcr_cnt
;
3655 if (debug
& VP9_DEBUG_CACHE
)
3656 pr_info("[cache_util.c] Entered decomp_get_hitrate...\n");
3657 WRITE_VREG(HEVCD_MPP_DECOMP_PERFMON_CTL
, (unsigned int)(0x0<<1));
3658 raw_mcr_cnt
= READ_VREG(HEVCD_MPP_DECOMP_PERFMON_DATA
);
3659 WRITE_VREG(HEVCD_MPP_DECOMP_PERFMON_CTL
, (unsigned int)(0x1<<1));
3660 hit_mcr_cnt
= READ_VREG(HEVCD_MPP_DECOMP_PERFMON_DATA
);
3662 if (debug
& VP9_DEBUG_CACHE
)
3663 pr_info("hcache_raw_cnt_total: %d\n", raw_mcr_cnt
);
3664 if (debug
& VP9_DEBUG_CACHE
)
3665 pr_info("hcache_hit_cnt_total: %d\n", hit_mcr_cnt
);
3667 if (raw_mcr_cnt
!= 0) {
3668 hitrate
= hit_mcr_cnt
* 100 / raw_mcr_cnt
;
3669 if (debug
& VP9_DEBUG_CACHE
)
3670 pr_info("DECOMP_HCACHE_HIT_RATE : %d\n", hitrate
);
3672 if (debug
& VP9_DEBUG_CACHE
)
3673 pr_info("DECOMP_HCACHE_HIT_RATE : na\n");
3675 WRITE_VREG(HEVCD_MPP_DECOMP_PERFMON_CTL
, (unsigned int)(0x2<<1));
3676 raw_mcr_cnt
= READ_VREG(HEVCD_MPP_DECOMP_PERFMON_DATA
);
3677 WRITE_VREG(HEVCD_MPP_DECOMP_PERFMON_CTL
, (unsigned int)(0x3<<1));
3678 hit_mcr_cnt
= READ_VREG(HEVCD_MPP_DECOMP_PERFMON_DATA
);
3680 if (debug
& VP9_DEBUG_CACHE
)
3681 pr_info("dcache_raw_cnt_total: %d\n", raw_mcr_cnt
);
3682 if (debug
& VP9_DEBUG_CACHE
)
3683 pr_info("dcache_hit_cnt_total: %d\n", hit_mcr_cnt
);
3685 if (raw_mcr_cnt
!= 0) {
3686 hitrate
= hit_mcr_cnt
* 100 / raw_mcr_cnt
;
3687 if (debug
& VP9_DEBUG_CACHE
)
3688 pr_info("DECOMP_DCACHE_HIT_RATE : %d\n", hitrate
);
3690 if (debug
& VP9_DEBUG_CACHE
)
3691 pr_info("DECOMP_DCACHE_HIT_RATE : na\n");
3696 static void decomp_get_comprate(void)
3698 unsigned raw_ucomp_cnt
;
3699 unsigned fast_comp_cnt
;
3700 unsigned slow_comp_cnt
;
3703 if (debug
& VP9_DEBUG_CACHE
)
3704 pr_info("[cache_util.c] Entered decomp_get_comprate...\n");
3705 WRITE_VREG(HEVCD_MPP_DECOMP_PERFMON_CTL
, (unsigned int)(0x4<<1));
3706 fast_comp_cnt
= READ_VREG(HEVCD_MPP_DECOMP_PERFMON_DATA
);
3707 WRITE_VREG(HEVCD_MPP_DECOMP_PERFMON_CTL
, (unsigned int)(0x5<<1));
3708 slow_comp_cnt
= READ_VREG(HEVCD_MPP_DECOMP_PERFMON_DATA
);
3709 WRITE_VREG(HEVCD_MPP_DECOMP_PERFMON_CTL
, (unsigned int)(0x6<<1));
3710 raw_ucomp_cnt
= READ_VREG(HEVCD_MPP_DECOMP_PERFMON_DATA
);
3712 if (debug
& VP9_DEBUG_CACHE
)
3713 pr_info("decomp_fast_comp_total: %d\n", fast_comp_cnt
);
3714 if (debug
& VP9_DEBUG_CACHE
)
3715 pr_info("decomp_slow_comp_total: %d\n", slow_comp_cnt
);
3716 if (debug
& VP9_DEBUG_CACHE
)
3717 pr_info("decomp_raw_uncomp_total: %d\n", raw_ucomp_cnt
);
3719 if (raw_ucomp_cnt
!= 0) {
3720 comprate
= (fast_comp_cnt
+ slow_comp_cnt
)
3721 * 100 / raw_ucomp_cnt
;
3722 if (debug
& VP9_DEBUG_CACHE
)
3723 pr_info("DECOMP_COMP_RATIO : %d\n", comprate
);
3725 if (debug
& VP9_DEBUG_CACHE
)
3726 pr_info("DECOMP_COMP_RATIO : na\n");
3730 /* cache_util.c end */
3732 /*====================================================
3733 *========================================================================
3735 *========================================================================
3737 #define VP9_PARTITION_START 0
3738 #define VP9_PARTITION_SIZE_STEP (3 * 4)
3739 #define VP9_PARTITION_ONE_SIZE (4 * VP9_PARTITION_SIZE_STEP)
3740 #define VP9_PARTITION_KEY_START 0
3741 #define VP9_PARTITION_P_START VP9_PARTITION_ONE_SIZE
3742 #define VP9_PARTITION_SIZE (2 * VP9_PARTITION_ONE_SIZE)
3743 #define VP9_SKIP_START (VP9_PARTITION_START + VP9_PARTITION_SIZE)
3744 #define VP9_SKIP_SIZE 4 /* only use 3*/
3745 #define VP9_TX_MODE_START (VP9_SKIP_START+VP9_SKIP_SIZE)
3746 #define VP9_TX_MODE_8_0_OFFSET 0
3747 #define VP9_TX_MODE_8_1_OFFSET 1
3748 #define VP9_TX_MODE_16_0_OFFSET 2
3749 #define VP9_TX_MODE_16_1_OFFSET 4
3750 #define VP9_TX_MODE_32_0_OFFSET 6
3751 #define VP9_TX_MODE_32_1_OFFSET 9
3752 #define VP9_TX_MODE_SIZE 12
3753 #define VP9_COEF_START (VP9_TX_MODE_START+VP9_TX_MODE_SIZE)
3754 #define VP9_COEF_BAND_0_OFFSET 0
3755 #define VP9_COEF_BAND_1_OFFSET (VP9_COEF_BAND_0_OFFSET + 3 * 3 + 1)
3756 #define VP9_COEF_BAND_2_OFFSET (VP9_COEF_BAND_1_OFFSET + 6 * 3)
3757 #define VP9_COEF_BAND_3_OFFSET (VP9_COEF_BAND_2_OFFSET + 6 * 3)
3758 #define VP9_COEF_BAND_4_OFFSET (VP9_COEF_BAND_3_OFFSET + 6 * 3)
3759 #define VP9_COEF_BAND_5_OFFSET (VP9_COEF_BAND_4_OFFSET + 6 * 3)
3760 #define VP9_COEF_SIZE_ONE_SET 100 /* ((3 +5*6)*3 + 1 padding)*/
3761 #define VP9_COEF_4X4_START (VP9_COEF_START + 0 * VP9_COEF_SIZE_ONE_SET)
3762 #define VP9_COEF_8X8_START (VP9_COEF_START + 4 * VP9_COEF_SIZE_ONE_SET)
3763 #define VP9_COEF_16X16_START (VP9_COEF_START + 8 * VP9_COEF_SIZE_ONE_SET)
3764 #define VP9_COEF_32X32_START (VP9_COEF_START + 12 * VP9_COEF_SIZE_ONE_SET)
3765 #define VP9_COEF_SIZE_PLANE (2 * VP9_COEF_SIZE_ONE_SET)
3766 #define VP9_COEF_SIZE (4 * 2 * 2 * VP9_COEF_SIZE_ONE_SET)
3767 #define VP9_INTER_MODE_START (VP9_COEF_START+VP9_COEF_SIZE)
3768 #define VP9_INTER_MODE_SIZE 24 /* only use 21 ( #*7)*/
3769 #define VP9_INTERP_START (VP9_INTER_MODE_START+VP9_INTER_MODE_SIZE)
3770 #define VP9_INTERP_SIZE 8
3771 #define VP9_INTRA_INTER_START (VP9_INTERP_START+VP9_INTERP_SIZE)
3772 #define VP9_INTRA_INTER_SIZE 4
3773 #define VP9_INTERP_INTRA_INTER_START VP9_INTERP_START
3774 #define VP9_INTERP_INTRA_INTER_SIZE (VP9_INTERP_SIZE + VP9_INTRA_INTER_SIZE)
3775 #define VP9_COMP_INTER_START \
3776 (VP9_INTERP_INTRA_INTER_START+VP9_INTERP_INTRA_INTER_SIZE)
3777 #define VP9_COMP_INTER_SIZE 5
3778 #define VP9_COMP_REF_START (VP9_COMP_INTER_START+VP9_COMP_INTER_SIZE)
3779 #define VP9_COMP_REF_SIZE 5
3780 #define VP9_SINGLE_REF_START (VP9_COMP_REF_START+VP9_COMP_REF_SIZE)
3781 #define VP9_SINGLE_REF_SIZE 10
3782 #define VP9_REF_MODE_START VP9_COMP_INTER_START
3783 #define VP9_REF_MODE_SIZE \
3784 (VP9_COMP_INTER_SIZE+VP9_COMP_REF_SIZE+VP9_SINGLE_REF_SIZE)
3785 #define VP9_IF_Y_MODE_START (VP9_REF_MODE_START+VP9_REF_MODE_SIZE)
3786 #define VP9_IF_Y_MODE_SIZE 36
3787 #define VP9_IF_UV_MODE_START (VP9_IF_Y_MODE_START+VP9_IF_Y_MODE_SIZE)
3788 #define VP9_IF_UV_MODE_SIZE 92 /* only use 90*/
3789 #define VP9_MV_JOINTS_START (VP9_IF_UV_MODE_START+VP9_IF_UV_MODE_SIZE)
3790 #define VP9_MV_JOINTS_SIZE 3
3791 #define VP9_MV_SIGN_0_START (VP9_MV_JOINTS_START+VP9_MV_JOINTS_SIZE)
3792 #define VP9_MV_SIGN_0_SIZE 1
3793 #define VP9_MV_CLASSES_0_START (VP9_MV_SIGN_0_START+VP9_MV_SIGN_0_SIZE)
3794 #define VP9_MV_CLASSES_0_SIZE 10
3795 #define VP9_MV_CLASS0_0_START (VP9_MV_CLASSES_0_START+VP9_MV_CLASSES_0_SIZE)
3796 #define VP9_MV_CLASS0_0_SIZE 1
3797 #define VP9_MV_BITS_0_START (VP9_MV_CLASS0_0_START+VP9_MV_CLASS0_0_SIZE)
3798 #define VP9_MV_BITS_0_SIZE 10
3799 #define VP9_MV_SIGN_1_START (VP9_MV_BITS_0_START+VP9_MV_BITS_0_SIZE)
3800 #define VP9_MV_SIGN_1_SIZE 1
3801 #define VP9_MV_CLASSES_1_START \
3802 (VP9_MV_SIGN_1_START+VP9_MV_SIGN_1_SIZE)
3803 #define VP9_MV_CLASSES_1_SIZE 10
3804 #define VP9_MV_CLASS0_1_START \
3805 (VP9_MV_CLASSES_1_START+VP9_MV_CLASSES_1_SIZE)
3806 #define VP9_MV_CLASS0_1_SIZE 1
3807 #define VP9_MV_BITS_1_START \
3808 (VP9_MV_CLASS0_1_START+VP9_MV_CLASS0_1_SIZE)
3809 #define VP9_MV_BITS_1_SIZE 10
3810 #define VP9_MV_CLASS0_FP_0_START \
3811 (VP9_MV_BITS_1_START+VP9_MV_BITS_1_SIZE)
3812 #define VP9_MV_CLASS0_FP_0_SIZE 9
3813 #define VP9_MV_CLASS0_FP_1_START \
3814 (VP9_MV_CLASS0_FP_0_START+VP9_MV_CLASS0_FP_0_SIZE)
3815 #define VP9_MV_CLASS0_FP_1_SIZE 9
3816 #define VP9_MV_CLASS0_HP_0_START \
3817 (VP9_MV_CLASS0_FP_1_START+VP9_MV_CLASS0_FP_1_SIZE)
3818 #define VP9_MV_CLASS0_HP_0_SIZE 2
3819 #define VP9_MV_CLASS0_HP_1_START \
3820 (VP9_MV_CLASS0_HP_0_START+VP9_MV_CLASS0_HP_0_SIZE)
3821 #define VP9_MV_CLASS0_HP_1_SIZE 2
3822 #define VP9_MV_START VP9_MV_JOINTS_START
3823 #define VP9_MV_SIZE 72 /*only use 69*/
3825 #define VP9_TOTAL_SIZE (VP9_MV_START + VP9_MV_SIZE)
3828 /*========================================================================
3829 * vp9_count_mem define
3830 *========================================================================
3832 #define VP9_COEF_COUNT_START 0
3833 #define VP9_COEF_COUNT_BAND_0_OFFSET 0
3834 #define VP9_COEF_COUNT_BAND_1_OFFSET \
3835 (VP9_COEF_COUNT_BAND_0_OFFSET + 3*5)
3836 #define VP9_COEF_COUNT_BAND_2_OFFSET \
3837 (VP9_COEF_COUNT_BAND_1_OFFSET + 6*5)
3838 #define VP9_COEF_COUNT_BAND_3_OFFSET \
3839 (VP9_COEF_COUNT_BAND_2_OFFSET + 6*5)
3840 #define VP9_COEF_COUNT_BAND_4_OFFSET \
3841 (VP9_COEF_COUNT_BAND_3_OFFSET + 6*5)
3842 #define VP9_COEF_COUNT_BAND_5_OFFSET \
3843 (VP9_COEF_COUNT_BAND_4_OFFSET + 6*5)
3844 #define VP9_COEF_COUNT_SIZE_ONE_SET 165 /* ((3 +5*6)*5 */
3845 #define VP9_COEF_COUNT_4X4_START \
3846 (VP9_COEF_COUNT_START + 0*VP9_COEF_COUNT_SIZE_ONE_SET)
3847 #define VP9_COEF_COUNT_8X8_START \
3848 (VP9_COEF_COUNT_START + 4*VP9_COEF_COUNT_SIZE_ONE_SET)
3849 #define VP9_COEF_COUNT_16X16_START \
3850 (VP9_COEF_COUNT_START + 8*VP9_COEF_COUNT_SIZE_ONE_SET)
3851 #define VP9_COEF_COUNT_32X32_START \
3852 (VP9_COEF_COUNT_START + 12*VP9_COEF_COUNT_SIZE_ONE_SET)
3853 #define VP9_COEF_COUNT_SIZE_PLANE (2 * VP9_COEF_COUNT_SIZE_ONE_SET)
3854 #define VP9_COEF_COUNT_SIZE (4 * 2 * 2 * VP9_COEF_COUNT_SIZE_ONE_SET)
3856 #define VP9_INTRA_INTER_COUNT_START \
3857 (VP9_COEF_COUNT_START+VP9_COEF_COUNT_SIZE)
3858 #define VP9_INTRA_INTER_COUNT_SIZE (4*2)
3859 #define VP9_COMP_INTER_COUNT_START \
3860 (VP9_INTRA_INTER_COUNT_START+VP9_INTRA_INTER_COUNT_SIZE)
3861 #define VP9_COMP_INTER_COUNT_SIZE (5*2)
3862 #define VP9_COMP_REF_COUNT_START \
3863 (VP9_COMP_INTER_COUNT_START+VP9_COMP_INTER_COUNT_SIZE)
3864 #define VP9_COMP_REF_COUNT_SIZE (5*2)
3865 #define VP9_SINGLE_REF_COUNT_START \
3866 (VP9_COMP_REF_COUNT_START+VP9_COMP_REF_COUNT_SIZE)
3867 #define VP9_SINGLE_REF_COUNT_SIZE (10*2)
3868 #define VP9_TX_MODE_COUNT_START \
3869 (VP9_SINGLE_REF_COUNT_START+VP9_SINGLE_REF_COUNT_SIZE)
3870 #define VP9_TX_MODE_COUNT_SIZE (12*2)
3871 #define VP9_SKIP_COUNT_START \
3872 (VP9_TX_MODE_COUNT_START+VP9_TX_MODE_COUNT_SIZE)
3873 #define VP9_SKIP_COUNT_SIZE (3*2)
3874 #define VP9_MV_SIGN_0_COUNT_START \
3875 (VP9_SKIP_COUNT_START+VP9_SKIP_COUNT_SIZE)
3876 #define VP9_MV_SIGN_0_COUNT_SIZE (1*2)
3877 #define VP9_MV_SIGN_1_COUNT_START \
3878 (VP9_MV_SIGN_0_COUNT_START+VP9_MV_SIGN_0_COUNT_SIZE)
3879 #define VP9_MV_SIGN_1_COUNT_SIZE (1*2)
3880 #define VP9_MV_BITS_0_COUNT_START \
3881 (VP9_MV_SIGN_1_COUNT_START+VP9_MV_SIGN_1_COUNT_SIZE)
3882 #define VP9_MV_BITS_0_COUNT_SIZE (10*2)
3883 #define VP9_MV_BITS_1_COUNT_START \
3884 (VP9_MV_BITS_0_COUNT_START+VP9_MV_BITS_0_COUNT_SIZE)
3885 #define VP9_MV_BITS_1_COUNT_SIZE (10*2)
3886 #define VP9_MV_CLASS0_HP_0_COUNT_START \
3887 (VP9_MV_BITS_1_COUNT_START+VP9_MV_BITS_1_COUNT_SIZE)
3888 #define VP9_MV_CLASS0_HP_0_COUNT_SIZE (2*2)
3889 #define VP9_MV_CLASS0_HP_1_COUNT_START \
3890 (VP9_MV_CLASS0_HP_0_COUNT_START+VP9_MV_CLASS0_HP_0_COUNT_SIZE)
3891 #define VP9_MV_CLASS0_HP_1_COUNT_SIZE (2*2)
3892 /* Start merge_tree*/
3893 #define VP9_INTER_MODE_COUNT_START \
3894 (VP9_MV_CLASS0_HP_1_COUNT_START+VP9_MV_CLASS0_HP_1_COUNT_SIZE)
3895 #define VP9_INTER_MODE_COUNT_SIZE (7*4)
3896 #define VP9_IF_Y_MODE_COUNT_START \
3897 (VP9_INTER_MODE_COUNT_START+VP9_INTER_MODE_COUNT_SIZE)
3898 #define VP9_IF_Y_MODE_COUNT_SIZE (10*4)
3899 #define VP9_IF_UV_MODE_COUNT_START \
3900 (VP9_IF_Y_MODE_COUNT_START+VP9_IF_Y_MODE_COUNT_SIZE)
3901 #define VP9_IF_UV_MODE_COUNT_SIZE (10*10)
3902 #define VP9_PARTITION_P_COUNT_START \
3903 (VP9_IF_UV_MODE_COUNT_START+VP9_IF_UV_MODE_COUNT_SIZE)
3904 #define VP9_PARTITION_P_COUNT_SIZE (4*4*4)
3905 #define VP9_INTERP_COUNT_START \
3906 (VP9_PARTITION_P_COUNT_START+VP9_PARTITION_P_COUNT_SIZE)
3907 #define VP9_INTERP_COUNT_SIZE (4*3)
3908 #define VP9_MV_JOINTS_COUNT_START \
3909 (VP9_INTERP_COUNT_START+VP9_INTERP_COUNT_SIZE)
3910 #define VP9_MV_JOINTS_COUNT_SIZE (1 * 4)
3911 #define VP9_MV_CLASSES_0_COUNT_START \
3912 (VP9_MV_JOINTS_COUNT_START+VP9_MV_JOINTS_COUNT_SIZE)
3913 #define VP9_MV_CLASSES_0_COUNT_SIZE (1*11)
3914 #define VP9_MV_CLASS0_0_COUNT_START \
3915 (VP9_MV_CLASSES_0_COUNT_START+VP9_MV_CLASSES_0_COUNT_SIZE)
3916 #define VP9_MV_CLASS0_0_COUNT_SIZE (1*2)
3917 #define VP9_MV_CLASSES_1_COUNT_START \
3918 (VP9_MV_CLASS0_0_COUNT_START+VP9_MV_CLASS0_0_COUNT_SIZE)
3919 #define VP9_MV_CLASSES_1_COUNT_SIZE (1*11)
3920 #define VP9_MV_CLASS0_1_COUNT_START \
3921 (VP9_MV_CLASSES_1_COUNT_START+VP9_MV_CLASSES_1_COUNT_SIZE)
3922 #define VP9_MV_CLASS0_1_COUNT_SIZE (1*2)
3923 #define VP9_MV_CLASS0_FP_0_COUNT_START \
3924 (VP9_MV_CLASS0_1_COUNT_START+VP9_MV_CLASS0_1_COUNT_SIZE)
3925 #define VP9_MV_CLASS0_FP_0_COUNT_SIZE (3*4)
3926 #define VP9_MV_CLASS0_FP_1_COUNT_START \
3927 (VP9_MV_CLASS0_FP_0_COUNT_START+VP9_MV_CLASS0_FP_0_COUNT_SIZE)
3928 #define VP9_MV_CLASS0_FP_1_COUNT_SIZE (3*4)
3931 #define DC_PRED 0 /* Average of above and left pixels*/
3932 #define V_PRED 1 /* Vertical*/
3933 #define H_PRED 2 /* Horizontal*/
3934 #define D45_PRED 3 /*Directional 45 deg = round(arctan(1/1) * 180/pi)*/
3935 #define D135_PRED 4 /* Directional 135 deg = 180 - 45*/
3936 #define D117_PRED 5 /* Directional 117 deg = 180 - 63*/
3937 #define D153_PRED 6 /* Directional 153 deg = 180 - 27*/
3938 #define D207_PRED 7 /* Directional 207 deg = 180 + 27*/
3939 #define D63_PRED 8 /*Directional 63 deg = round(arctan(2/1) * 180/pi)*/
3940 #define TM_PRED 9 /*True-motion*/
3942 int clip_prob(int p
)
3944 return (p
> 255) ? 255 : (p
< 1) ? 1 : p
;
3947 #define ROUND_POWER_OF_TWO(value, n) \
3948 (((value) + (1 << ((n) - 1))) >> (n))
3950 #define MODE_MV_COUNT_SAT 20
3951 static const int count_to_update_factor
[MODE_MV_COUNT_SAT
+ 1] = {
3952 0, 6, 12, 19, 25, 32, 38, 44, 51, 57, 64,
3953 70, 76, 83, 89, 96, 102, 108, 115, 121, 128
3956 void vp9_tree_merge_probs(unsigned int *prev_prob
, unsigned int *cur_prob
,
3957 int coef_node_start
, int tree_left
, int tree_right
, int tree_i
,
3960 int prob_32
, prob_res
, prob_shift
;
3961 int pre_prob
, new_prob
;
3962 int den
, m_count
, get_prob
, factor
;
3964 prob_32
= prev_prob
[coef_node_start
/ 4 * 2];
3965 prob_res
= coef_node_start
& 3;
3966 prob_shift
= prob_res
* 8;
3967 pre_prob
= (prob_32
>> prob_shift
) & 0xff;
3969 den
= tree_left
+ tree_right
;
3972 new_prob
= pre_prob
;
3974 m_count
= (den
< MODE_MV_COUNT_SAT
) ?
3975 den
: MODE_MV_COUNT_SAT
;
3976 get_prob
= clip_prob(
3977 div_r32(((int64_t)tree_left
* 256 + (den
>> 1)),
3980 factor
= count_to_update_factor
[m_count
];
3981 new_prob
= ROUND_POWER_OF_TWO(pre_prob
* (256 - factor
)
3982 + get_prob
* factor
, 8);
3984 cur_prob
[coef_node_start
/ 4 * 2] = (cur_prob
[coef_node_start
/ 4 * 2]
3985 & (~(0xff << prob_shift
))) | (new_prob
<< prob_shift
);
3987 /*pr_info(" - [%d][%d] 0x%02X --> 0x%02X (0x%X 0x%X) (%X)\n",
3988 *tree_i, node, pre_prob, new_prob, tree_left, tree_right,
3989 *cur_prob[coef_node_start/4*2]);
3994 /*void adapt_coef_probs(void)*/
3995 void adapt_coef_probs(int pic_count
, int prev_kf
, int cur_kf
, int pre_fc
,
3996 unsigned int *prev_prob
, unsigned int *cur_prob
, unsigned int *count
)
3998 /* 80 * 64bits = 0xF00 ( use 0x1000 4K bytes)
3999 *unsigned int prev_prob[496*2];
4000 *unsigned int cur_prob[496*2];
4001 *0x300 * 128bits = 0x3000 (32K Bytes)
4002 *unsigned int count[0x300*4];
4005 int tx_size
, coef_tx_size_start
, coef_count_tx_size_start
;
4006 int plane
, coef_plane_start
, coef_count_plane_start
;
4007 int type
, coef_type_start
, coef_count_type_start
;
4008 int band
, coef_band_start
, coef_count_band_start
;
4010 int cxt
, coef_cxt_start
, coef_count_cxt_start
;
4011 int node
, coef_node_start
, coef_count_node_start
;
4013 int tree_i
, tree_left
, tree_right
;
4017 /*int update_factor = 112;*/ /*If COEF_MAX_UPDATE_FACTOR_AFTER_KEY,
4020 /* If COEF_MAX_UPDATE_FACTOR_AFTER_KEY, use 128*/
4021 /*int update_factor = (pic_count == 1) ? 128 : 112;*/
4022 int update_factor
= cur_kf
? 112 :
4023 prev_kf
? 128 : 112;
4037 if (debug
& VP9_DEBUG_MERGE
)
4039 ("\n ##adapt_coef_probs (pre_fc : %d ,prev_kf : %d,cur_kf : %d)##\n\n",
4040 pre_fc
, prev_kf
, cur_kf
);
4042 /*adapt_coef_probs*/
4043 for (tx_size
= 0; tx_size
< 4; tx_size
++) {
4044 coef_tx_size_start
= VP9_COEF_START
4045 + tx_size
* 4 * VP9_COEF_SIZE_ONE_SET
;
4046 coef_count_tx_size_start
= VP9_COEF_COUNT_START
4047 + tx_size
* 4 * VP9_COEF_COUNT_SIZE_ONE_SET
;
4048 coef_plane_start
= coef_tx_size_start
;
4049 coef_count_plane_start
= coef_count_tx_size_start
;
4050 for (plane
= 0; plane
< 2; plane
++) {
4051 coef_type_start
= coef_plane_start
;
4052 coef_count_type_start
= coef_count_plane_start
;
4053 for (type
= 0; type
< 2; type
++) {
4054 coef_band_start
= coef_type_start
;
4055 coef_count_band_start
= coef_count_type_start
;
4056 for (band
= 0; band
< 6; band
++) {
4061 coef_cxt_start
= coef_band_start
;
4062 coef_count_cxt_start
=
4063 coef_count_band_start
;
4064 for (cxt
= 0; cxt
< cxt_num
; cxt
++) {
4066 count
[coef_count_cxt_start
];
4068 count
[coef_count_cxt_start
+ 1];
4070 count
[coef_count_cxt_start
+ 2];
4072 count
[coef_count_cxt_start
+ 3];
4074 count
[coef_count_cxt_start
+ 4];
4084 (node
= 0; node
< 3; node
++) {
4090 coef_node_start
& 3;
4094 (prob_32
>> prob_shift
)
4101 branch_ct
[node
][0] +
4116 update_factor
* m_count
4122 get_prob
* factor
, 8);
4124 cur_prob
[coef_node_start
4128 / 4 * 2] & (~(0xff <<
4133 coef_node_start
+= 1;
4138 coef_count_cxt_start
=
4139 coef_count_cxt_start
4143 coef_band_start
+= 10;
4144 coef_count_band_start
+= 15;
4146 coef_band_start
+= 18;
4147 coef_count_band_start
+= 30;
4150 coef_type_start
+= VP9_COEF_SIZE_ONE_SET
;
4151 coef_count_type_start
+=
4152 VP9_COEF_COUNT_SIZE_ONE_SET
;
4154 coef_plane_start
+= 2 * VP9_COEF_SIZE_ONE_SET
;
4155 coef_count_plane_start
+=
4156 2 * VP9_COEF_COUNT_SIZE_ONE_SET
;
4161 /*mode_mv_merge_probs - merge_intra_inter_prob*/
4162 for (coef_count_node_start
= VP9_INTRA_INTER_COUNT_START
;
4163 coef_count_node_start
< (VP9_MV_CLASS0_HP_1_COUNT_START
+
4164 VP9_MV_CLASS0_HP_1_COUNT_SIZE
); coef_count_node_start
+= 2) {
4166 if (coef_count_node_start
==
4167 VP9_INTRA_INTER_COUNT_START
) {
4168 if (debug
& VP9_DEBUG_MERGE
)
4169 pr_info(" # merge_intra_inter_prob\n");
4170 coef_node_start
= VP9_INTRA_INTER_START
;
4171 } else if (coef_count_node_start
==
4172 VP9_COMP_INTER_COUNT_START
) {
4173 if (debug
& VP9_DEBUG_MERGE
)
4174 pr_info(" # merge_comp_inter_prob\n");
4175 coef_node_start
= VP9_COMP_INTER_START
;
4178 *else if (coef_count_node_start ==
4179 * VP9_COMP_REF_COUNT_START) {
4180 * pr_info(" # merge_comp_inter_prob\n");
4181 * coef_node_start = VP9_COMP_REF_START;
4183 *else if (coef_count_node_start ==
4184 * VP9_SINGLE_REF_COUNT_START) {
4185 * pr_info(" # merge_comp_inter_prob\n");
4186 * coef_node_start = VP9_SINGLE_REF_START;
4189 else if (coef_count_node_start
==
4190 VP9_TX_MODE_COUNT_START
) {
4191 if (debug
& VP9_DEBUG_MERGE
)
4192 pr_info(" # merge_tx_mode_probs\n");
4193 coef_node_start
= VP9_TX_MODE_START
;
4194 } else if (coef_count_node_start
==
4195 VP9_SKIP_COUNT_START
) {
4196 if (debug
& VP9_DEBUG_MERGE
)
4197 pr_info(" # merge_skip_probs\n");
4198 coef_node_start
= VP9_SKIP_START
;
4199 } else if (coef_count_node_start
==
4200 VP9_MV_SIGN_0_COUNT_START
) {
4201 if (debug
& VP9_DEBUG_MERGE
)
4202 pr_info(" # merge_sign_0\n");
4203 coef_node_start
= VP9_MV_SIGN_0_START
;
4204 } else if (coef_count_node_start
==
4205 VP9_MV_SIGN_1_COUNT_START
) {
4206 if (debug
& VP9_DEBUG_MERGE
)
4207 pr_info(" # merge_sign_1\n");
4208 coef_node_start
= VP9_MV_SIGN_1_START
;
4209 } else if (coef_count_node_start
==
4210 VP9_MV_BITS_0_COUNT_START
) {
4211 if (debug
& VP9_DEBUG_MERGE
)
4212 pr_info(" # merge_bits_0\n");
4213 coef_node_start
= VP9_MV_BITS_0_START
;
4214 } else if (coef_count_node_start
==
4215 VP9_MV_BITS_1_COUNT_START
) {
4216 if (debug
& VP9_DEBUG_MERGE
)
4217 pr_info(" # merge_bits_1\n");
4218 coef_node_start
= VP9_MV_BITS_1_START
;
4219 } else if (coef_count_node_start
==
4220 VP9_MV_CLASS0_HP_0_COUNT_START
) {
4221 if (debug
& VP9_DEBUG_MERGE
)
4222 pr_info(" # merge_class0_hp\n");
4223 coef_node_start
= VP9_MV_CLASS0_HP_0_START
;
4227 den
= count
[coef_count_node_start
] +
4228 count
[coef_count_node_start
+ 1];
4230 prob_32
= prev_prob
[coef_node_start
/ 4 * 2];
4231 prob_res
= coef_node_start
& 3;
4232 prob_shift
= prob_res
* 8;
4233 pre_prob
= (prob_32
>> prob_shift
) & 0xff;
4236 new_prob
= pre_prob
;
4238 m_count
= (den
< MODE_MV_COUNT_SAT
) ?
4239 den
: MODE_MV_COUNT_SAT
;
4242 div_r32(((int64_t)count
[coef_count_node_start
]
4243 * 256 + (den
>> 1)),
4246 factor
= count_to_update_factor
[m_count
];
4248 ROUND_POWER_OF_TWO(pre_prob
* (256 - factor
)
4249 + get_prob
* factor
, 8);
4251 cur_prob
[coef_node_start
/ 4 * 2] =
4252 (cur_prob
[coef_node_start
/ 4 * 2] &
4253 (~(0xff << prob_shift
)))
4254 | (new_prob
<< prob_shift
);
4256 coef_node_start
= coef_node_start
+ 1;
4258 if (debug
& VP9_DEBUG_MERGE
)
4259 pr_info(" # merge_vp9_inter_mode_tree\n");
4260 coef_node_start
= VP9_INTER_MODE_START
;
4261 coef_count_node_start
= VP9_INTER_MODE_COUNT_START
;
4262 for (tree_i
= 0; tree_i
< 7; tree_i
++) {
4263 for (node
= 0; node
< 3; node
++) {
4267 count
[coef_count_node_start
+ 1];
4269 count
[coef_count_node_start
+ 3];
4273 count
[coef_count_node_start
+ 0];
4275 count
[coef_count_node_start
+ 1]
4276 + count
[coef_count_node_start
+ 3];
4280 count
[coef_count_node_start
+ 2];
4282 count
[coef_count_node_start
+ 0]
4283 + count
[coef_count_node_start
+ 1]
4284 + count
[coef_count_node_start
+ 3];
4289 vp9_tree_merge_probs(prev_prob
, cur_prob
,
4290 coef_node_start
, tree_left
, tree_right
,
4293 coef_node_start
= coef_node_start
+ 1;
4295 coef_count_node_start
= coef_count_node_start
+ 4;
4297 if (debug
& VP9_DEBUG_MERGE
)
4298 pr_info(" # merge_vp9_intra_mode_tree\n");
4299 coef_node_start
= VP9_IF_Y_MODE_START
;
4300 coef_count_node_start
= VP9_IF_Y_MODE_COUNT_START
;
4301 for (tree_i
= 0; tree_i
< 14; tree_i
++) {
4302 for (node
= 0; node
< 9; node
++) {
4306 count
[coef_count_node_start
+D153_PRED
];
4308 count
[coef_count_node_start
+D207_PRED
];
4312 count
[coef_count_node_start
+D63_PRED
];
4314 count
[coef_count_node_start
+D207_PRED
] +
4315 count
[coef_count_node_start
+D153_PRED
];
4319 count
[coef_count_node_start
+ D45_PRED
];
4321 count
[coef_count_node_start
+D207_PRED
] +
4322 count
[coef_count_node_start
+D153_PRED
] +
4323 count
[coef_count_node_start
+D63_PRED
];
4327 count
[coef_count_node_start
+D135_PRED
];
4329 count
[coef_count_node_start
+D117_PRED
];
4333 count
[coef_count_node_start
+H_PRED
];
4335 count
[coef_count_node_start
+D117_PRED
] +
4336 count
[coef_count_node_start
+D135_PRED
];
4340 count
[coef_count_node_start
+H_PRED
] +
4341 count
[coef_count_node_start
+D117_PRED
] +
4342 count
[coef_count_node_start
+D135_PRED
];
4344 count
[coef_count_node_start
+D45_PRED
] +
4345 count
[coef_count_node_start
+D207_PRED
] +
4346 count
[coef_count_node_start
+D153_PRED
] +
4347 count
[coef_count_node_start
+D63_PRED
];
4351 count
[coef_count_node_start
+V_PRED
];
4353 count
[coef_count_node_start
+H_PRED
] +
4354 count
[coef_count_node_start
+D117_PRED
] +
4355 count
[coef_count_node_start
+D135_PRED
] +
4356 count
[coef_count_node_start
+D45_PRED
] +
4357 count
[coef_count_node_start
+D207_PRED
] +
4358 count
[coef_count_node_start
+D153_PRED
] +
4359 count
[coef_count_node_start
+D63_PRED
];
4363 count
[coef_count_node_start
+TM_PRED
];
4365 count
[coef_count_node_start
+V_PRED
] +
4366 count
[coef_count_node_start
+H_PRED
] +
4367 count
[coef_count_node_start
+D117_PRED
] +
4368 count
[coef_count_node_start
+D135_PRED
] +
4369 count
[coef_count_node_start
+D45_PRED
] +
4370 count
[coef_count_node_start
+D207_PRED
] +
4371 count
[coef_count_node_start
+D153_PRED
] +
4372 count
[coef_count_node_start
+D63_PRED
];
4376 count
[coef_count_node_start
+DC_PRED
];
4378 count
[coef_count_node_start
+TM_PRED
] +
4379 count
[coef_count_node_start
+V_PRED
] +
4380 count
[coef_count_node_start
+H_PRED
] +
4381 count
[coef_count_node_start
+D117_PRED
] +
4382 count
[coef_count_node_start
+D135_PRED
] +
4383 count
[coef_count_node_start
+D45_PRED
] +
4384 count
[coef_count_node_start
+D207_PRED
] +
4385 count
[coef_count_node_start
+D153_PRED
] +
4386 count
[coef_count_node_start
+D63_PRED
];
4391 vp9_tree_merge_probs(prev_prob
, cur_prob
,
4392 coef_node_start
, tree_left
, tree_right
,
4395 coef_node_start
= coef_node_start
+ 1;
4397 coef_count_node_start
= coef_count_node_start
+ 10;
4400 if (debug
& VP9_DEBUG_MERGE
)
4401 pr_info(" # merge_vp9_partition_tree\n");
4402 coef_node_start
= VP9_PARTITION_P_START
;
4403 coef_count_node_start
= VP9_PARTITION_P_COUNT_START
;
4404 for (tree_i
= 0; tree_i
< 16; tree_i
++) {
4405 for (node
= 0; node
< 3; node
++) {
4409 count
[coef_count_node_start
+ 2];
4411 count
[coef_count_node_start
+ 3];
4415 count
[coef_count_node_start
+ 1];
4417 count
[coef_count_node_start
+ 2] +
4418 count
[coef_count_node_start
+ 3];
4422 count
[coef_count_node_start
+ 0];
4424 count
[coef_count_node_start
+ 1] +
4425 count
[coef_count_node_start
+ 2] +
4426 count
[coef_count_node_start
+ 3];
4431 vp9_tree_merge_probs(prev_prob
, cur_prob
,
4433 tree_left
, tree_right
, tree_i
, node
);
4435 coef_node_start
= coef_node_start
+ 1;
4437 coef_count_node_start
= coef_count_node_start
+ 4;
4440 if (debug
& VP9_DEBUG_MERGE
)
4441 pr_info(" # merge_vp9_switchable_interp_tree\n");
4442 coef_node_start
= VP9_INTERP_START
;
4443 coef_count_node_start
= VP9_INTERP_COUNT_START
;
4444 for (tree_i
= 0; tree_i
< 4; tree_i
++) {
4445 for (node
= 0; node
< 2; node
++) {
4449 count
[coef_count_node_start
+ 1];
4451 count
[coef_count_node_start
+ 2];
4455 count
[coef_count_node_start
+ 0];
4457 count
[coef_count_node_start
+ 1] +
4458 count
[coef_count_node_start
+ 2];
4463 vp9_tree_merge_probs(prev_prob
, cur_prob
,
4465 tree_left
, tree_right
, tree_i
, node
);
4467 coef_node_start
= coef_node_start
+ 1;
4469 coef_count_node_start
= coef_count_node_start
+ 3;
4472 if (debug
& VP9_DEBUG_MERGE
)
4473 pr_info("# merge_vp9_mv_joint_tree\n");
4474 coef_node_start
= VP9_MV_JOINTS_START
;
4475 coef_count_node_start
= VP9_MV_JOINTS_COUNT_START
;
4476 for (tree_i
= 0; tree_i
< 1; tree_i
++) {
4477 for (node
= 0; node
< 3; node
++) {
4481 count
[coef_count_node_start
+ 2];
4483 count
[coef_count_node_start
+ 3];
4487 count
[coef_count_node_start
+ 1];
4489 count
[coef_count_node_start
+ 2] +
4490 count
[coef_count_node_start
+ 3];
4494 count
[coef_count_node_start
+ 0];
4496 count
[coef_count_node_start
+ 1] +
4497 count
[coef_count_node_start
+ 2] +
4498 count
[coef_count_node_start
+ 3];
4502 vp9_tree_merge_probs(prev_prob
, cur_prob
,
4504 tree_left
, tree_right
, tree_i
, node
);
4506 coef_node_start
= coef_node_start
+ 1;
4508 coef_count_node_start
= coef_count_node_start
+ 4;
4511 for (mvd_i
= 0; mvd_i
< 2; mvd_i
++) {
4512 if (debug
& VP9_DEBUG_MERGE
)
4513 pr_info(" # merge_vp9_mv_class_tree [%d] -\n", mvd_i
);
4515 mvd_i
? VP9_MV_CLASSES_1_START
: VP9_MV_CLASSES_0_START
;
4516 coef_count_node_start
=
4517 mvd_i
? VP9_MV_CLASSES_1_COUNT_START
4518 : VP9_MV_CLASSES_0_COUNT_START
;
4520 for (node
= 0; node
< 10; node
++) {
4524 count
[coef_count_node_start
+ 9];
4526 count
[coef_count_node_start
+ 10];
4530 count
[coef_count_node_start
+ 7];
4532 count
[coef_count_node_start
+ 8];
4536 count
[coef_count_node_start
+ 7] +
4537 count
[coef_count_node_start
+ 8];
4539 count
[coef_count_node_start
+ 9] +
4540 count
[coef_count_node_start
+ 10];
4544 count
[coef_count_node_start
+ 6];
4546 count
[coef_count_node_start
+ 7] +
4547 count
[coef_count_node_start
+ 8] +
4548 count
[coef_count_node_start
+ 9] +
4549 count
[coef_count_node_start
+ 10];
4553 count
[coef_count_node_start
+ 4];
4555 count
[coef_count_node_start
+ 5];
4559 count
[coef_count_node_start
+ 4] +
4560 count
[coef_count_node_start
+ 5];
4562 count
[coef_count_node_start
+ 6] +
4563 count
[coef_count_node_start
+ 7] +
4564 count
[coef_count_node_start
+ 8] +
4565 count
[coef_count_node_start
+ 9] +
4566 count
[coef_count_node_start
+ 10];
4570 count
[coef_count_node_start
+ 2];
4572 count
[coef_count_node_start
+ 3];
4576 count
[coef_count_node_start
+ 2] +
4577 count
[coef_count_node_start
+ 3];
4579 count
[coef_count_node_start
+ 4] +
4580 count
[coef_count_node_start
+ 5] +
4581 count
[coef_count_node_start
+ 6] +
4582 count
[coef_count_node_start
+ 7] +
4583 count
[coef_count_node_start
+ 8] +
4584 count
[coef_count_node_start
+ 9] +
4585 count
[coef_count_node_start
+ 10];
4589 count
[coef_count_node_start
+ 1];
4591 count
[coef_count_node_start
+ 2] +
4592 count
[coef_count_node_start
+ 3] +
4593 count
[coef_count_node_start
+ 4] +
4594 count
[coef_count_node_start
+ 5] +
4595 count
[coef_count_node_start
+ 6] +
4596 count
[coef_count_node_start
+ 7] +
4597 count
[coef_count_node_start
+ 8] +
4598 count
[coef_count_node_start
+ 9] +
4599 count
[coef_count_node_start
+ 10];
4603 count
[coef_count_node_start
+ 0];
4605 count
[coef_count_node_start
+ 1] +
4606 count
[coef_count_node_start
+ 2] +
4607 count
[coef_count_node_start
+ 3] +
4608 count
[coef_count_node_start
+ 4] +
4609 count
[coef_count_node_start
+ 5] +
4610 count
[coef_count_node_start
+ 6] +
4611 count
[coef_count_node_start
+ 7] +
4612 count
[coef_count_node_start
+ 8] +
4613 count
[coef_count_node_start
+ 9] +
4614 count
[coef_count_node_start
+ 10];
4619 vp9_tree_merge_probs(prev_prob
, cur_prob
,
4620 coef_node_start
, tree_left
, tree_right
,
4623 coef_node_start
= coef_node_start
+ 1;
4626 if (debug
& VP9_DEBUG_MERGE
)
4627 pr_info(" # merge_vp9_mv_class0_tree [%d] -\n", mvd_i
);
4629 mvd_i
? VP9_MV_CLASS0_1_START
: VP9_MV_CLASS0_0_START
;
4630 coef_count_node_start
=
4631 mvd_i
? VP9_MV_CLASS0_1_COUNT_START
:
4632 VP9_MV_CLASS0_0_COUNT_START
;
4635 tree_left
= count
[coef_count_node_start
+ 0];
4636 tree_right
= count
[coef_count_node_start
+ 1];
4638 vp9_tree_merge_probs(prev_prob
, cur_prob
, coef_node_start
,
4639 tree_left
, tree_right
, tree_i
, node
);
4640 if (debug
& VP9_DEBUG_MERGE
)
4641 pr_info(" # merge_vp9_mv_fp_tree_class0_fp [%d] -\n",
4644 mvd_i
? VP9_MV_CLASS0_FP_1_START
:
4645 VP9_MV_CLASS0_FP_0_START
;
4646 coef_count_node_start
=
4647 mvd_i
? VP9_MV_CLASS0_FP_1_COUNT_START
:
4648 VP9_MV_CLASS0_FP_0_COUNT_START
;
4649 for (tree_i
= 0; tree_i
< 3; tree_i
++) {
4650 for (node
= 0; node
< 3; node
++) {
4654 count
[coef_count_node_start
+ 2];
4656 count
[coef_count_node_start
+ 3];
4660 count
[coef_count_node_start
+ 1];
4662 count
[coef_count_node_start
+ 2]
4663 + count
[coef_count_node_start
+ 3];
4667 count
[coef_count_node_start
+ 0];
4669 count
[coef_count_node_start
+ 1]
4670 + count
[coef_count_node_start
+ 2]
4671 + count
[coef_count_node_start
+ 3];
4676 vp9_tree_merge_probs(prev_prob
, cur_prob
,
4677 coef_node_start
, tree_left
, tree_right
,
4680 coef_node_start
= coef_node_start
+ 1;
4682 coef_count_node_start
= coef_count_node_start
+ 4;
4685 } /* for mvd_i (mvd_y or mvd_x)*/
4690 static bool v4l_is_there_vframe_bound(struct VP9Decoder_s
*pbi
)
4693 struct VP9_Common_s
*const cm
= &pbi
->common
;
4694 struct RefCntBuffer_s
*frame_bufs
= cm
->buffer_pool
->frame_bufs
;
4696 for (i
= 0; i
< pbi
->used_buf_num
; ++i
) {
4697 if (frame_bufs
[i
].buf
.vframe_bound
)
4704 static void v4l_mmu_buffer_release(struct VP9Decoder_s
*pbi
)
4706 struct VP9_Common_s
*const cm
= &pbi
->common
;
4707 struct RefCntBuffer_s
*frame_bufs
= cm
->buffer_pool
->frame_bufs
;
4710 /* release workspace */
4712 decoder_bmmu_box_free_idx(pbi
->bmmu_box
,
4715 * it's only when vframe get back to driver, right now we can be sure
4716 * that vframe and fd are related. if the playback exits, the capture
4717 * requires the upper app to release when the fd is closed, and others
4718 * buffers drivers are released by driver.
4720 for (i
= 0; i
< pbi
->used_buf_num
; ++i
) {
4721 if (!frame_bufs
[i
].buf
.vframe_bound
) {
4723 decoder_bmmu_box_free_idx(pbi
->bmmu_box
,
4724 HEADER_BUFFER_IDX(i
));
4726 decoder_mmu_box_free_idx(pbi
->mmu_box
, i
);
4728 vp9_print(pbi
, PRINT_FLAG_V4L_DETAIL
,
4729 "%s free buffer[%d], bmmu_box: %p, mmu_box: %p\n",
4730 __func__
, i
, pbi
->bmmu_box
, pbi
->mmu_box
);
4735 static void uninit_mmu_buffers(struct VP9Decoder_s
*pbi
)
4737 #ifndef MV_USE_FIXED_BUF
4738 dealloc_mv_bufs(pbi
);
4740 if (pbi
->is_used_v4l
&&
4741 v4l_is_there_vframe_bound(pbi
)) {
4742 if (get_double_write_mode(pbi
) != 0x10) {
4743 v4l_mmu_buffer_release(pbi
);
4749 decoder_mmu_box_free(pbi
->mmu_box
);
4750 pbi
->mmu_box
= NULL
;
4753 decoder_bmmu_box_free(pbi
->bmmu_box
);
4754 pbi
->bmmu_box
= NULL
;
4757 static int calc_luc_quantity(u32 w
, u32 h
)
4759 int lcu_size
= 64; /*fixed 64*/
4760 int pic_width_64
= (w
+ 63) & (~0x3f);
4761 int pic_height_32
= (h
+ 31) & (~0x1f);
4762 int pic_width_lcu
= (pic_width_64
% lcu_size
) ?
4763 pic_width_64
/ lcu_size
+ 1 : pic_width_64
/ lcu_size
;
4764 int pic_height_lcu
= (pic_height_32
% lcu_size
) ?
4765 pic_height_32
/ lcu_size
+ 1 : pic_height_32
/ lcu_size
;
4767 return pic_width_lcu
* pic_height_lcu
;
4770 static int v4l_alloc_and_config_pic(struct VP9Decoder_s
*pbi
,
4771 struct PIC_BUFFER_CONFIG_s
*pic
)
4775 int dw_mode
= get_double_write_mode_init(pbi
);
4776 int lcu_total
= calc_luc_quantity(pbi
->frame_width
, pbi
->frame_height
);
4777 #ifdef MV_USE_FIXED_BUF
4778 u32 mpred_mv_end
= pbi
->work_space_buf
->mpred_mv
.buf_start
+
4779 pbi
->work_space_buf
->mpred_mv
.buf_size
;
4781 struct vdec_v4l2_buffer
*fb
= NULL
;
4783 ret
= vdec_v4l_get_buffer(pbi
->v4l2_ctx
, &fb
);
4785 vp9_print(pbi
, 0, "[%d] VP9 get buffer fail.\n",
4786 ((struct aml_vcodec_ctx
*) (pbi
->v4l2_ctx
))->id
);
4790 if (pbi
->mmu_enable
) {
4791 pbi
->m_BUF
[i
].header_addr
= decoder_bmmu_box_get_phy_addr(
4792 pbi
->bmmu_box
, HEADER_BUFFER_IDX(i
));
4793 if (debug
& VP9_DEBUG_BUFMGR_MORE
) {
4794 pr_info("MMU header_adr %d: %ld\n",
4795 i
, pbi
->m_BUF
[i
].header_addr
);
4799 #ifdef MV_USE_FIXED_BUF
4800 if ((pbi
->work_space_buf
->mpred_mv
.buf_start
+
4801 (((i
+ 1) * lcu_total
) * MV_MEM_UNIT
))
4804 pbi
->m_BUF
[i
].v4l_ref_buf_addr
= (ulong
)fb
;
4805 pic
->cma_alloc_addr
= fb
->m
.mem
[0].addr
;
4806 if (fb
->num_planes
== 1) {
4807 pbi
->m_BUF
[i
].start_adr
= fb
->m
.mem
[0].addr
;
4808 pbi
->m_BUF
[i
].size
= fb
->m
.mem
[0].size
;
4809 pbi
->m_BUF
[i
].luma_size
= fb
->m
.mem
[0].offset
;
4810 fb
->m
.mem
[0].bytes_used
= fb
->m
.mem
[0].size
;
4811 } else if (fb
->num_planes
== 2) {
4812 pbi
->m_BUF
[i
].start_adr
= fb
->m
.mem
[0].addr
;
4813 pbi
->m_BUF
[i
].size
= fb
->m
.mem
[0].size
+ fb
->m
.mem
[1].size
;
4814 pbi
->m_BUF
[i
].luma_size
= fb
->m
.mem
[0].size
;
4815 fb
->m
.mem
[0].bytes_used
= fb
->m
.mem
[0].size
;
4816 fb
->m
.mem
[1].bytes_used
= fb
->m
.mem
[1].size
;
4819 /* config frame buffer */
4820 if (pbi
->mmu_enable
)
4821 pic
->header_adr
= pbi
->m_BUF
[i
].header_addr
;
4824 pic
->lcu_total
= lcu_total
;
4825 pic
->mc_canvas_y
= pic
->index
;
4826 pic
->mc_canvas_u_v
= pic
->index
;
4828 if (dw_mode
& 0x10) {
4829 pic
->dw_y_adr
= pbi
->m_BUF
[i
].start_adr
;
4830 pic
->dw_u_v_adr
= pic
->dw_y_adr
+ pbi
->m_BUF
[i
].luma_size
;
4831 pic
->mc_canvas_y
= (pic
->index
<< 1);
4832 pic
->mc_canvas_u_v
= (pic
->index
<< 1) + 1;
4833 } else if (dw_mode
) {
4834 pic
->dw_y_adr
= pbi
->m_BUF
[i
].start_adr
;
4835 pic
->dw_u_v_adr
= pic
->dw_y_adr
+ pbi
->m_BUF
[i
].luma_size
;
4838 #ifdef MV_USE_FIXED_BUF
4839 pic
->mpred_mv_wr_start_addr
=
4840 pbi
->work_space_buf
->mpred_mv
.buf_start
+
4841 ((pic
->index
* lcu_total
) * MV_MEM_UNIT
);
4844 pr_info("%s index %d BUF_index %d ",
4845 __func__
, pic
->index
,
4847 pr_info("comp_body_size %x comp_buf_size %x ",
4848 pic
->comp_body_size
,
4850 pr_info("mpred_mv_wr_start_adr %ld\n",
4851 pic
->mpred_mv_wr_start_addr
);
4852 pr_info("dw_y_adr %d, pic_config->dw_u_v_adr =%d\n",
4856 #ifdef MV_USE_FIXED_BUF
4862 static int config_pic(struct VP9Decoder_s
*pbi
,
4863 struct PIC_BUFFER_CONFIG_s
*pic_config
)
4867 int pic_width
= pbi
->init_pic_w
;
4868 int pic_height
= pbi
->init_pic_h
;
4869 int lcu_size
= 64; /*fixed 64*/
4870 int pic_width_64
= (pic_width
+ 63) & (~0x3f);
4871 int pic_height_32
= (pic_height
+ 31) & (~0x1f);
4872 int pic_width_lcu
= (pic_width_64
% lcu_size
) ?
4873 pic_width_64
/ lcu_size
+ 1
4874 : pic_width_64
/ lcu_size
;
4875 int pic_height_lcu
= (pic_height_32
% lcu_size
) ?
4876 pic_height_32
/ lcu_size
+ 1
4877 : pic_height_32
/ lcu_size
;
4878 int lcu_total
= pic_width_lcu
* pic_height_lcu
;
4879 #ifdef MV_USE_FIXED_BUF
4880 u32 mpred_mv_end
= pbi
->work_space_buf
->mpred_mv
.buf_start
+
4881 pbi
->work_space_buf
->mpred_mv
.buf_size
;
4886 int losless_comp_header_size
=
4887 compute_losless_comp_header_size(pic_width
,
4889 int losless_comp_body_size
= compute_losless_comp_body_size(pic_width
,
4890 pic_height
, buf_alloc_depth
== 10);
4891 int mc_buffer_size
= losless_comp_header_size
+ losless_comp_body_size
;
4892 int mc_buffer_size_h
= (mc_buffer_size
+ 0xffff) >> 16;
4893 int mc_buffer_size_u_v
= 0;
4894 int mc_buffer_size_u_v_h
= 0;
4895 int dw_mode
= get_double_write_mode_init(pbi
);
4897 pbi
->lcu_total
= lcu_total
;
4900 int pic_width_dw
= pic_width
/
4901 get_double_write_ratio(pbi
, dw_mode
);
4902 int pic_height_dw
= pic_height
/
4903 get_double_write_ratio(pbi
, dw_mode
);
4905 int pic_width_64_dw
= (pic_width_dw
+ 63) & (~0x3f);
4906 int pic_height_32_dw
= (pic_height_dw
+ 31) & (~0x1f);
4907 int pic_width_lcu_dw
= (pic_width_64_dw
% lcu_size
) ?
4908 pic_width_64_dw
/ lcu_size
+ 1
4909 : pic_width_64_dw
/ lcu_size
;
4910 int pic_height_lcu_dw
= (pic_height_32_dw
% lcu_size
) ?
4911 pic_height_32_dw
/ lcu_size
+ 1
4912 : pic_height_32_dw
/ lcu_size
;
4913 int lcu_total_dw
= pic_width_lcu_dw
* pic_height_lcu_dw
;
4914 mc_buffer_size_u_v
= lcu_total_dw
* lcu_size
* lcu_size
/ 2;
4915 mc_buffer_size_u_v_h
= (mc_buffer_size_u_v
+ 0xffff) >> 16;
4917 buf_size
= ((mc_buffer_size_u_v_h
<< 16) * 3);
4918 buf_size
= ((buf_size
+ 0xffff) >> 16) << 16;
4921 if (mc_buffer_size
& 0xffff) /*64k alignment*/
4922 mc_buffer_size_h
+= 1;
4923 if ((!pbi
->mmu_enable
) && ((dw_mode
& 0x10) == 0))
4924 buf_size
+= (mc_buffer_size_h
<< 16);
4926 if (pbi
->mmu_enable
) {
4927 pic_config
->header_adr
= decoder_bmmu_box_get_phy_addr(
4928 pbi
->bmmu_box
, HEADER_BUFFER_IDX(pic_config
->index
));
4930 if (debug
& VP9_DEBUG_BUFMGR_MORE
) {
4931 pr_info("MMU header_adr %d: %ld\n",
4932 pic_config
->index
, pic_config
->header_adr
);
4936 i
= pic_config
->index
;
4937 #ifdef MV_USE_FIXED_BUF
4938 if ((pbi
->work_space_buf
->mpred_mv
.buf_start
+
4939 (((i
+ 1) * lcu_total
) * MV_MEM_UNIT
))
4944 ret
= decoder_bmmu_box_alloc_buf_phy(pbi
->bmmu_box
,
4946 buf_size
, DRIVER_NAME
,
4947 &pic_config
->cma_alloc_addr
);
4950 "decoder_bmmu_box_alloc_buf_phy idx %d size %d fail\n",
4957 if (pic_config
->cma_alloc_addr
)
4958 y_adr
= pic_config
->cma_alloc_addr
;
4961 "decoder_bmmu_box_alloc_buf_phy idx %d size %d return null\n",
4969 /*ensure get_pic_by_POC()
4970 not get the buffer not decoded*/
4971 pic_config
->BUF_index
= i
;
4972 pic_config
->lcu_total
= lcu_total
;
4974 pic_config
->comp_body_size
= losless_comp_body_size
;
4975 pic_config
->buf_size
= buf_size
;
4977 pic_config
->mc_canvas_y
= pic_config
->index
;
4978 pic_config
->mc_canvas_u_v
= pic_config
->index
;
4979 if (dw_mode
& 0x10) {
4980 pic_config
->dw_y_adr
= y_adr
;
4981 pic_config
->dw_u_v_adr
= y_adr
+
4982 ((mc_buffer_size_u_v_h
<< 16) << 1);
4984 pic_config
->mc_canvas_y
=
4985 (pic_config
->index
<< 1);
4986 pic_config
->mc_canvas_u_v
=
4987 (pic_config
->index
<< 1) + 1;
4988 } else if (dw_mode
) {
4989 pic_config
->dw_y_adr
= y_adr
;
4990 pic_config
->dw_u_v_adr
= pic_config
->dw_y_adr
+
4991 ((mc_buffer_size_u_v_h
<< 16) << 1);
4993 #ifdef MV_USE_FIXED_BUF
4994 pic_config
->mpred_mv_wr_start_addr
=
4995 pbi
->work_space_buf
->mpred_mv
.buf_start
+
4996 ((pic_config
->index
* lcu_total
)
5001 ("%s index %d BUF_index %d ",
5002 __func__
, pic_config
->index
,
5003 pic_config
->BUF_index
);
5005 ("comp_body_size %x comp_buf_size %x ",
5006 pic_config
->comp_body_size
,
5007 pic_config
->buf_size
);
5009 ("mpred_mv_wr_start_adr %ld\n",
5010 pic_config
->mpred_mv_wr_start_addr
);
5011 pr_info("dw_y_adr %d, pic_config->dw_u_v_adr =%d\n",
5012 pic_config
->dw_y_adr
,
5013 pic_config
->dw_u_v_adr
);
5017 #ifdef MV_USE_FIXED_BUF
5023 static int vvp9_mmu_compress_header_size(struct VP9Decoder_s
*pbi
)
5025 if ((get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_SM1
) &&
5026 IS_8K_SIZE(pbi
->max_pic_w
, pbi
->max_pic_h
))
5027 return (MMU_COMPRESS_8K_HEADER_SIZE
);
5029 return (MMU_COMPRESS_HEADER_SIZE
);
5032 /*#define FRAME_MMU_MAP_SIZE (MAX_FRAME_4K_NUM * 4)*/
5033 static int vvp9_frame_mmu_map_size(struct VP9Decoder_s
*pbi
)
5035 if ((get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_SM1
) &&
5036 IS_8K_SIZE(pbi
->max_pic_w
, pbi
->max_pic_h
))
5037 return (MAX_FRAME_8K_NUM
* 4);
5039 return (MAX_FRAME_4K_NUM
* 4);
5042 static void init_pic_list(struct VP9Decoder_s
*pbi
)
5045 struct VP9_Common_s
*cm
= &pbi
->common
;
5046 struct PIC_BUFFER_CONFIG_s
*pic_config
;
5048 struct vdec_s
*vdec
= hw_to_vdec(pbi
);
5050 if (pbi
->mmu_enable
&& ((pbi
->double_write_mode
& 0x10) == 0)) {
5051 header_size
= vvp9_mmu_compress_header_size(pbi
);
5052 /*alloc VP9 compress header first*/
5053 for (i
= 0; i
< pbi
->used_buf_num
; i
++) {
5054 unsigned long buf_addr
;
5055 if (decoder_bmmu_box_alloc_buf_phy
5057 HEADER_BUFFER_IDX(i
), header_size
,
5060 pr_info("%s malloc compress header failed %d\n",
5061 DRIVER_HEADER_NAME
, i
);
5062 pbi
->fatal_error
|= DECODER_FATAL_ERROR_NO_MEM
;
5067 for (i
= 0; i
< pbi
->used_buf_num
; i
++) {
5068 pic_config
= &cm
->buffer_pool
->frame_bufs
[i
].buf
;
5069 pic_config
->index
= i
;
5070 pic_config
->BUF_index
= -1;
5071 pic_config
->mv_buf_index
= -1;
5072 if (vdec
->parallel_dec
== 1) {
5073 pic_config
->y_canvas_index
= -1;
5074 pic_config
->uv_canvas_index
= -1;
5076 pic_config
->y_crop_width
= pbi
->init_pic_w
;
5077 pic_config
->y_crop_height
= pbi
->init_pic_h
;
5078 pic_config
->double_write_mode
= get_double_write_mode(pbi
);
5080 if (!pbi
->is_used_v4l
) {
5081 if (config_pic(pbi
, pic_config
) < 0) {
5083 pr_info("Config_pic %d fail\n",
5085 pic_config
->index
= -1;
5089 if (pic_config
->double_write_mode
) {
5090 set_canvas(pbi
, pic_config
);
5094 for (; i
< pbi
->used_buf_num
; i
++) {
5095 pic_config
= &cm
->buffer_pool
->frame_bufs
[i
].buf
;
5096 pic_config
->index
= -1;
5097 pic_config
->BUF_index
= -1;
5098 pic_config
->mv_buf_index
= -1;
5099 if (vdec
->parallel_dec
== 1) {
5100 pic_config
->y_canvas_index
= -1;
5101 pic_config
->uv_canvas_index
= -1;
5104 pr_info("%s ok, used_buf_num = %d\n",
5105 __func__
, pbi
->used_buf_num
);
5108 static void init_pic_list_hw(struct VP9Decoder_s
*pbi
)
5111 struct VP9_Common_s
*cm
= &pbi
->common
;
5112 struct PIC_BUFFER_CONFIG_s
*pic_config
;
5113 /*WRITE_VREG(HEVCD_MPP_ANC2AXI_TBL_CONF_ADDR, 0x0);*/
5114 WRITE_VREG(HEVCD_MPP_ANC2AXI_TBL_CONF_ADDR
,
5115 (0x1 << 1) | (0x1 << 2));
5118 for (i
= 0; i
< pbi
->used_buf_num
; i
++) {
5119 pic_config
= &cm
->buffer_pool
->frame_bufs
[i
].buf
;
5120 if (pic_config
->index
< 0)
5123 if (pbi
->mmu_enable
&& ((pic_config
->double_write_mode
& 0x10) == 0)) {
5125 WRITE_VREG(HEVCD_MPP_ANC2AXI_TBL_DATA
,
5126 pic_config
->header_adr
>> 5);
5128 /*WRITE_VREG(HEVCD_MPP_ANC2AXI_TBL_CMD_ADDR,
5129 * pic_config->mc_y_adr
5130 * | (pic_config->mc_canvas_y << 8) | 0x1);
5132 WRITE_VREG(HEVCD_MPP_ANC2AXI_TBL_DATA
,
5133 pic_config
->dw_y_adr
>> 5);
5135 #ifndef LOSLESS_COMPRESS_MODE
5136 /*WRITE_VREG(HEVCD_MPP_ANC2AXI_TBL_CMD_ADDR,
5137 * pic_config->mc_u_v_adr
5138 * | (pic_config->mc_canvas_u_v << 8)| 0x1);
5140 WRITE_VREG(HEVCD_MPP_ANC2AXI_TBL_DATA
,
5141 pic_config
->header_adr
>> 5);
5143 if (pic_config
->double_write_mode
& 0x10) {
5144 WRITE_VREG(HEVCD_MPP_ANC2AXI_TBL_DATA
,
5145 pic_config
->dw_u_v_adr
>> 5);
5149 WRITE_VREG(HEVCD_MPP_ANC2AXI_TBL_CONF_ADDR
, 0x1);
5151 /*Zero out canvas registers in IPP -- avoid simulation X*/
5152 WRITE_VREG(HEVCD_MPP_ANC_CANVAS_ACCCONFIG_ADDR
,
5153 (0 << 8) | (0 << 1) | 1);
5154 for (i
= 0; i
< 32; i
++)
5155 WRITE_VREG(HEVCD_MPP_ANC_CANVAS_DATA_ADDR
, 0);
5159 static void dump_pic_list(struct VP9Decoder_s
*pbi
)
5161 struct VP9_Common_s
*const cm
= &pbi
->common
;
5162 struct PIC_BUFFER_CONFIG_s
*pic_config
;
5164 for (i
= 0; i
< FRAME_BUFFERS
; i
++) {
5165 pic_config
= &cm
->buffer_pool
->frame_bufs
[i
].buf
;
5167 "Buf(%d) index %d mv_buf_index %d ref_count %d vf_ref %d dec_idx %d slice_type %d w/h %d/%d adr%ld\n",
5170 #ifndef MV_USE_FIXED_BUF
5171 pic_config
->mv_buf_index
,
5176 frame_bufs
[i
].ref_count
,
5178 pic_config
->decode_idx
,
5179 pic_config
->slice_type
,
5180 pic_config
->y_crop_width
,
5181 pic_config
->y_crop_height
,
5182 pic_config
->cma_alloc_addr
5188 static int config_pic_size(struct VP9Decoder_s
*pbi
, unsigned short bit_depth
)
5190 #ifdef LOSLESS_COMPRESS_MODE
5191 unsigned int data32
;
5193 int losless_comp_header_size
, losless_comp_body_size
;
5194 struct VP9_Common_s
*cm
= &pbi
->common
;
5195 struct PIC_BUFFER_CONFIG_s
*cur_pic_config
= &cm
->cur_frame
->buf
;
5197 frame_width
= cur_pic_config
->y_crop_width
;
5198 frame_height
= cur_pic_config
->y_crop_height
;
5199 cur_pic_config
->bit_depth
= bit_depth
;
5200 cur_pic_config
->double_write_mode
= get_double_write_mode(pbi
);
5201 losless_comp_header_size
=
5202 compute_losless_comp_header_size(cur_pic_config
->y_crop_width
,
5203 cur_pic_config
->y_crop_height
);
5204 losless_comp_body_size
=
5205 compute_losless_comp_body_size(cur_pic_config
->y_crop_width
,
5206 cur_pic_config
->y_crop_height
, (bit_depth
== VPX_BITS_10
));
5207 cur_pic_config
->comp_body_size
= losless_comp_body_size
;
5208 #ifdef LOSLESS_COMPRESS_MODE
5209 data32
= READ_VREG(HEVC_SAO_CTRL5
);
5210 if (bit_depth
== VPX_BITS_10
)
5211 data32
&= ~(1 << 9);
5215 WRITE_VREG(HEVC_SAO_CTRL5
, data32
);
5217 if (pbi
->mmu_enable
) {
5218 /*bit[4] : paged_mem_mode*/
5219 WRITE_VREG(HEVCD_MPP_DECOMP_CTL1
, (0x1 << 4));
5221 /*bit[3] smem mdoe*/
5222 if (bit_depth
== VPX_BITS_10
)
5223 WRITE_VREG(HEVCD_MPP_DECOMP_CTL1
, (0 << 3));
5225 WRITE_VREG(HEVCD_MPP_DECOMP_CTL1
, (1 << 3));
5227 if (get_cpu_major_id() < AM_MESON_CPU_MAJOR_ID_SM1
)
5228 WRITE_VREG(HEVCD_MPP_DECOMP_CTL2
, (losless_comp_body_size
>> 5));
5229 /*WRITE_VREG(HEVCD_MPP_DECOMP_CTL3,(0xff<<20) | (0xff<<10) | 0xff);*/
5230 WRITE_VREG(HEVC_CM_BODY_LENGTH
, losless_comp_body_size
);
5231 WRITE_VREG(HEVC_CM_HEADER_OFFSET
, losless_comp_body_size
);
5232 WRITE_VREG(HEVC_CM_HEADER_LENGTH
, losless_comp_header_size
);
5233 if (get_double_write_mode(pbi
) & 0x10)
5234 WRITE_VREG(HEVCD_MPP_DECOMP_CTL1
, 0x1 << 31);
5236 WRITE_VREG(HEVCD_MPP_DECOMP_CTL1
, 0x1 << 31);
5241 static int config_mc_buffer(struct VP9Decoder_s
*pbi
, unsigned short bit_depth
)
5244 struct VP9_Common_s
*cm
= &pbi
->common
;
5245 struct PIC_BUFFER_CONFIG_s
*cur_pic_config
= &cm
->cur_frame
->buf
;
5246 uint8_t scale_enable
= 0;
5248 if (debug
&VP9_DEBUG_BUFMGR_MORE
)
5249 pr_info("config_mc_buffer entered .....\n");
5251 WRITE_VREG(HEVCD_MPP_ANC_CANVAS_ACCCONFIG_ADDR
,
5252 (0 << 8) | (0 << 1) | 1);
5253 for (i
= 0; i
< REFS_PER_FRAME
; ++i
) {
5254 struct PIC_BUFFER_CONFIG_s
*pic_config
= cm
->frame_refs
[i
].buf
;
5257 WRITE_VREG(HEVCD_MPP_ANC_CANVAS_DATA_ADDR
,
5258 (pic_config
->mc_canvas_u_v
<< 16)
5259 | (pic_config
->mc_canvas_u_v
<< 8)
5260 | pic_config
->mc_canvas_y
);
5261 if (debug
& VP9_DEBUG_BUFMGR_MORE
)
5262 pr_info("refid %x mc_canvas_u_v %x mc_canvas_y %x\n",
5263 i
, pic_config
->mc_canvas_u_v
,
5264 pic_config
->mc_canvas_y
);
5266 WRITE_VREG(HEVCD_MPP_ANC_CANVAS_ACCCONFIG_ADDR
,
5267 (16 << 8) | (0 << 1) | 1);
5268 for (i
= 0; i
< REFS_PER_FRAME
; ++i
) {
5269 struct PIC_BUFFER_CONFIG_s
*pic_config
= cm
->frame_refs
[i
].buf
;
5272 WRITE_VREG(HEVCD_MPP_ANC_CANVAS_DATA_ADDR
,
5273 (pic_config
->mc_canvas_u_v
<< 16)
5274 | (pic_config
->mc_canvas_u_v
<< 8)
5275 | pic_config
->mc_canvas_y
);
5278 /*auto_inc start index:0 field:0*/
5279 WRITE_VREG(VP9D_MPP_REFINFO_TBL_ACCCONFIG
, 0x1 << 2);
5280 /*index 0:last 1:golden 2:altref*/
5281 for (i
= 0; i
< REFS_PER_FRAME
; i
++) {
5282 int ref_pic_body_size
;
5283 struct PIC_BUFFER_CONFIG_s
*pic_config
= cm
->frame_refs
[i
].buf
;
5286 WRITE_VREG(VP9D_MPP_REFINFO_DATA
, pic_config
->y_crop_width
);
5287 WRITE_VREG(VP9D_MPP_REFINFO_DATA
, pic_config
->y_crop_height
);
5289 if (pic_config
->y_crop_width
!= cur_pic_config
->y_crop_width
||
5290 pic_config
->y_crop_height
!= cur_pic_config
->y_crop_height
) {
5291 scale_enable
|= (1 << i
);
5294 compute_losless_comp_body_size(pic_config
->y_crop_width
,
5295 pic_config
->y_crop_height
, (bit_depth
== VPX_BITS_10
));
5296 WRITE_VREG(VP9D_MPP_REFINFO_DATA
,
5297 (pic_config
->y_crop_width
<< 14)
5298 / cur_pic_config
->y_crop_width
);
5299 WRITE_VREG(VP9D_MPP_REFINFO_DATA
,
5300 (pic_config
->y_crop_height
<< 14)
5301 / cur_pic_config
->y_crop_height
);
5302 if (pbi
->mmu_enable
)
5303 WRITE_VREG(VP9D_MPP_REFINFO_DATA
, 0);
5305 WRITE_VREG(VP9D_MPP_REFINFO_DATA
, ref_pic_body_size
>> 5);
5307 WRITE_VREG(VP9D_MPP_REF_SCALE_ENBL
, scale_enable
);
5311 static void clear_mpred_hw(struct VP9Decoder_s
*pbi
)
5313 unsigned int data32
;
5315 data32
= READ_VREG(HEVC_MPRED_CTRL4
);
5316 data32
&= (~(1 << 6));
5317 WRITE_VREG(HEVC_MPRED_CTRL4
, data32
);
5320 static void config_mpred_hw(struct VP9Decoder_s
*pbi
)
5322 struct VP9_Common_s
*cm
= &pbi
->common
;
5323 struct PIC_BUFFER_CONFIG_s
*cur_pic_config
= &cm
->cur_frame
->buf
;
5324 struct PIC_BUFFER_CONFIG_s
*last_frame_pic_config
=
5325 &cm
->prev_frame
->buf
;
5327 unsigned int data32
;
5328 int mpred_curr_lcu_x
;
5329 int mpred_curr_lcu_y
;
5330 int mpred_mv_rd_end_addr
;
5333 mpred_mv_rd_end_addr
= last_frame_pic_config
->mpred_mv_wr_start_addr
5334 + (last_frame_pic_config
->lcu_total
* MV_MEM_UNIT
);
5336 data32
= READ_VREG(HEVC_MPRED_CURR_LCU
);
5337 mpred_curr_lcu_x
= data32
& 0xffff;
5338 mpred_curr_lcu_y
= (data32
>> 16) & 0xffff;
5340 if (debug
& VP9_DEBUG_BUFMGR
)
5341 pr_info("cur pic_config index %d col pic_config index %d\n",
5342 cur_pic_config
->index
, last_frame_pic_config
->index
);
5343 WRITE_VREG(HEVC_MPRED_CTRL3
, 0x24122412);
5344 WRITE_VREG(HEVC_MPRED_ABV_START_ADDR
,
5345 pbi
->work_space_buf
->mpred_above
.buf_start
);
5347 data32
= READ_VREG(HEVC_MPRED_CTRL4
);
5349 data32
&= (~(1 << 6));
5350 data32
|= (cm
->use_prev_frame_mvs
<< 6);
5351 WRITE_VREG(HEVC_MPRED_CTRL4
, data32
);
5353 WRITE_VREG(HEVC_MPRED_MV_WR_START_ADDR
,
5354 cur_pic_config
->mpred_mv_wr_start_addr
);
5355 WRITE_VREG(HEVC_MPRED_MV_WPTR
, cur_pic_config
->mpred_mv_wr_start_addr
);
5357 WRITE_VREG(HEVC_MPRED_MV_RD_START_ADDR
,
5358 last_frame_pic_config
->mpred_mv_wr_start_addr
);
5359 WRITE_VREG(HEVC_MPRED_MV_RPTR
,
5360 last_frame_pic_config
->mpred_mv_wr_start_addr
);
5361 /*data32 = ((pbi->lcu_x_num - pbi->tile_width_lcu)*MV_MEM_UNIT);*/
5362 /*WRITE_VREG(HEVC_MPRED_MV_WR_ROW_JUMP,data32);*/
5363 /*WRITE_VREG(HEVC_MPRED_MV_RD_ROW_JUMP,data32);*/
5364 WRITE_VREG(HEVC_MPRED_MV_RD_END_ADDR
, mpred_mv_rd_end_addr
);
5368 static void config_sao_hw(struct VP9Decoder_s
*pbi
, union param_u
*params
)
5370 struct VP9_Common_s
*cm
= &pbi
->common
;
5371 struct PIC_BUFFER_CONFIG_s
*pic_config
= &cm
->cur_frame
->buf
;
5373 unsigned int data32
;
5375 int mc_buffer_size_u_v
=
5376 pic_config
->lcu_total
* lcu_size
*lcu_size
/2;
5377 int mc_buffer_size_u_v_h
=
5378 (mc_buffer_size_u_v
+ 0xffff) >> 16;/*64k alignment*/
5379 struct aml_vcodec_ctx
* v4l2_ctx
= pbi
->v4l2_ctx
;
5381 if (get_double_write_mode(pbi
)) {
5382 WRITE_VREG(HEVC_SAO_Y_START_ADDR
, pic_config
->dw_y_adr
);
5383 WRITE_VREG(HEVC_SAO_C_START_ADDR
, pic_config
->dw_u_v_adr
);
5384 WRITE_VREG(HEVC_SAO_Y_WPTR
, pic_config
->dw_y_adr
);
5385 WRITE_VREG(HEVC_SAO_C_WPTR
, pic_config
->dw_u_v_adr
);
5387 WRITE_VREG(HEVC_SAO_Y_START_ADDR
, 0xffffffff);
5388 WRITE_VREG(HEVC_SAO_C_START_ADDR
, 0xffffffff);
5390 if (pbi
->mmu_enable
)
5391 WRITE_VREG(HEVC_CM_HEADER_START_ADDR
, pic_config
->header_adr
);
5393 data32
= (mc_buffer_size_u_v_h
<< 16) << 1;
5394 /*pr_info("data32=%x,mc_buffer_size_u_v_h=%x,lcu_total=%x\n",
5395 * data32, mc_buffer_size_u_v_h, pic_config->lcu_total);
5397 WRITE_VREG(HEVC_SAO_Y_LENGTH
, data32
);
5399 data32
= (mc_buffer_size_u_v_h
<< 16);
5400 WRITE_VREG(HEVC_SAO_C_LENGTH
, data32
);
5404 data32
= READ_VREG(HEVC_SAO_CTRL1
);
5405 data32
&= (~0x3000);
5406 /*[13:12] axi_aformat, 0-Linear, 1-32x32, 2-64x32*/
5407 data32
|= (pbi
->mem_map_mode
<< 12);
5409 data32
|= 0x1; /* [1]:dw_disable [0]:cm_disable*/
5410 WRITE_VREG(HEVC_SAO_CTRL1
, data32
);
5411 /*[23:22] dw_v1_ctrl [21:20] dw_v0_ctrl [19:18] dw_h1_ctrl
5412 * [17:16] dw_h0_ctrl
5414 data32
= READ_VREG(HEVC_SAO_CTRL5
);
5415 /*set them all 0 for H265_NV21 (no down-scale)*/
5416 data32
&= ~(0xff << 16);
5417 WRITE_VREG(HEVC_SAO_CTRL5
, data32
);
5418 data32
= READ_VREG(HEVCD_IPP_AXIIF_CONFIG
);
5420 /*[5:4] address_format 00:linear 01:32x32 10:64x32*/
5421 data32
|= (pbi
->mem_map_mode
<< 4);
5422 WRITE_VREG(HEVCD_IPP_AXIIF_CONFIG
, data32
);
5425 data32
= READ_VREG(HEVC_SAO_CTRL1
);
5426 data32
&= (~0x3000);
5427 /*[13:12] axi_aformat, 0-Linear, 1-32x32, 2-64x32*/
5428 data32
|= (pbi
->mem_map_mode
<< 12);
5430 /*data32 |= 0x670;*/ /*Big-Endian per 64-bit*/
5431 data32
|= 0x880; /*.Big-Endian per 64-bit */
5433 data32
|= 0x1; /*[1]:dw_disable [0]:cm_disable*/
5434 WRITE_VREG(HEVC_SAO_CTRL1
, data32
);
5435 /* [23:22] dw_v1_ctrl [21:20] dw_v0_ctrl
5436 *[19:18] dw_h1_ctrl [17:16] dw_h0_ctrl
5438 data32
= READ_VREG(HEVC_SAO_CTRL5
);
5439 /* set them all 0 for H265_NV21 (no down-scale)*/
5440 data32
&= ~(0xff << 16);
5441 WRITE_VREG(HEVC_SAO_CTRL5
, data32
);
5443 data32
= READ_VREG(HEVCD_IPP_AXIIF_CONFIG
);
5445 /*[5:4] address_format 00:linear 01:32x32 10:64x32*/
5446 data32
|= (pbi
->mem_map_mode
<< 4);
5448 data32
|= 0x8; /*Big-Endian per 64-bit*/
5449 WRITE_VREG(HEVCD_IPP_AXIIF_CONFIG
, data32
);
5452 data32
= READ_VREG(HEVC_SAO_CTRL1
);
5453 data32
&= (~0x3000);
5454 data32
|= (pbi
->mem_map_mode
<<
5457 /* [13:12] axi_aformat, 0-Linear,
5461 /* data32 |= 0x670; // Big-Endian per 64-bit */
5462 data32
|= endian
; /* Big-Endian per 64-bit */
5463 if (get_cpu_major_id() < AM_MESON_CPU_MAJOR_ID_G12A
) {
5464 data32
&= (~0x3); /*[1]:dw_disable [0]:cm_disable*/
5465 if (get_double_write_mode(pbi
) == 0)
5466 data32
|= 0x2; /*disable double write*/
5467 else if (get_double_write_mode(pbi
) & 0x10)
5468 data32
|= 0x1; /*disable cm*/
5469 } else { /* >= G12A dw write control */
5471 data
= READ_VREG(HEVC_DBLK_CFGB
);
5472 data
&= (~0x300); /*[8]:first write enable (compress) [9]:double write enable (uncompress)*/
5473 if (get_double_write_mode(pbi
) == 0)
5474 data
|= (0x1 << 8); /*enable first write*/
5475 else if (get_double_write_mode(pbi
) & 0x10)
5476 data
|= (0x1 << 9); /*double write only*/
5478 data
|= ((0x1 << 8) |(0x1 << 9));
5479 WRITE_VREG(HEVC_DBLK_CFGB
, data
);
5483 if (pbi
->is_used_v4l
) {
5484 if ((v4l2_ctx
->q_data
[AML_Q_DATA_DST
].fmt
->fourcc
== V4L2_PIX_FMT_NV21
) ||
5485 (v4l2_ctx
->q_data
[AML_Q_DATA_DST
].fmt
->fourcc
== V4L2_PIX_FMT_NV21M
))
5486 data32
&= ~(1 << 8); /* NV21 */
5488 data32
|= (1 << 8); /* NV12 */
5492 * [31:24] ar_fifo1_axi_thred
5493 * [23:16] ar_fifo0_axi_thred
5494 * [15:14] axi_linealign, 0-16bytes, 1-32bytes, 2-64bytes
5495 * [13:12] axi_aformat, 0-Linear, 1-32x32, 2-64x32
5496 * [11:08] axi_lendian_C
5497 * [07:04] axi_lendian_Y
5500 * [1] dw_disable:disable double write output
5501 * [0] cm_disable:disable compress output
5503 WRITE_VREG(HEVC_SAO_CTRL1
, data32
);
5505 if (get_double_write_mode(pbi
) & 0x10) {
5506 /* [23:22] dw_v1_ctrl
5511 data32
= READ_VREG(HEVC_SAO_CTRL5
);
5512 /*set them all 0 for H265_NV21 (no down-scale)*/
5513 data32
&= ~(0xff << 16);
5514 WRITE_VREG(HEVC_SAO_CTRL5
, data32
);
5516 data32
= READ_VREG(HEVC_SAO_CTRL5
);
5517 data32
&= (~(0xff << 16));
5518 if (get_double_write_mode(pbi
) == 2 ||
5519 get_double_write_mode(pbi
) == 3)
5520 data32
|= (0xff<<16);
5521 else if (get_double_write_mode(pbi
) == 4)
5522 data32
|= (0x33<<16);
5523 WRITE_VREG(HEVC_SAO_CTRL5
, data32
);
5526 data32
= READ_VREG(HEVCD_IPP_AXIIF_CONFIG
);
5528 /* [5:4] -- address_format 00:linear 01:32x32 10:64x32 */
5529 data32
|= (pbi
->mem_map_mode
<<
5532 data32
|= 0xf; /* valid only when double write only */
5533 /*data32 |= 0x8;*/ /* Big-Endian per 64-bit */
5536 if (pbi
->is_used_v4l
) {
5537 if ((v4l2_ctx
->q_data
[AML_Q_DATA_DST
].fmt
->fourcc
== V4L2_PIX_FMT_NV21
) ||
5538 (v4l2_ctx
->q_data
[AML_Q_DATA_DST
].fmt
->fourcc
== V4L2_PIX_FMT_NV21M
))
5539 data32
|= (1 << 12); /* NV21 */
5541 data32
&= ~(1 << 12); /* NV12 */
5545 * [3:0] little_endian
5546 * [5:4] address_format 00:linear 01:32x32 10:64x32
5548 * [9:8] Linear_LineAlignment 00:16byte 01:32byte 10:64byte
5550 * [12] CbCr_byte_swap
5553 WRITE_VREG(HEVCD_IPP_AXIIF_CONFIG
, data32
);
5557 static void vp9_config_work_space_hw(struct VP9Decoder_s
*pbi
, u32 mask
)
5559 struct BuffInfo_s
*buf_spec
= pbi
->work_space_buf
;
5560 unsigned int data32
;
5562 if (debug
&& pbi
->init_flag
== 0)
5563 pr_info("%s %x %x %x %x %x %x %x %x %x %x %x %x\n",
5565 buf_spec
->ipp
.buf_start
,
5566 buf_spec
->start_adr
,
5567 buf_spec
->short_term_rps
.buf_start
,
5568 buf_spec
->vps
.buf_start
,
5569 buf_spec
->sps
.buf_start
,
5570 buf_spec
->pps
.buf_start
,
5571 buf_spec
->sao_up
.buf_start
,
5572 buf_spec
->swap_buf
.buf_start
,
5573 buf_spec
->swap_buf2
.buf_start
,
5574 buf_spec
->scalelut
.buf_start
,
5575 buf_spec
->dblk_para
.buf_start
,
5576 buf_spec
->dblk_data
.buf_start
);
5578 if (mask
& HW_MASK_FRONT
) {
5579 if ((debug
& VP9_DEBUG_SEND_PARAM_WITH_REG
) == 0)
5580 WRITE_VREG(HEVC_RPM_BUFFER
, (u32
)pbi
->rpm_phy_addr
);
5582 WRITE_VREG(HEVC_SHORT_TERM_RPS
,
5583 buf_spec
->short_term_rps
.buf_start
);
5584 /*WRITE_VREG(HEVC_VPS_BUFFER, buf_spec->vps.buf_start);*/
5585 /*WRITE_VREG(HEVC_SPS_BUFFER, buf_spec->sps.buf_start);*/
5586 WRITE_VREG(HEVC_PPS_BUFFER
, buf_spec
->pps
.buf_start
);
5587 WRITE_VREG(HEVC_STREAM_SWAP_BUFFER
,
5588 buf_spec
->swap_buf
.buf_start
);
5589 WRITE_VREG(HEVC_STREAM_SWAP_BUFFER2
,
5590 buf_spec
->swap_buf2
.buf_start
);
5591 WRITE_VREG(LMEM_DUMP_ADR
, (u32
)pbi
->lmem_phy_addr
);
5595 if (mask
& HW_MASK_BACK
) {
5596 #ifdef LOSLESS_COMPRESS_MODE
5597 int losless_comp_header_size
=
5598 compute_losless_comp_header_size(pbi
->init_pic_w
,
5600 int losless_comp_body_size
=
5601 compute_losless_comp_body_size(pbi
->init_pic_w
,
5602 pbi
->init_pic_h
, buf_alloc_depth
== 10);
5604 WRITE_VREG(HEVCD_IPP_LINEBUFF_BASE
,
5605 buf_spec
->ipp
.buf_start
);
5606 WRITE_VREG(HEVC_SAO_UP
, buf_spec
->sao_up
.buf_start
);
5607 WRITE_VREG(HEVC_SCALELUT
, buf_spec
->scalelut
.buf_start
);
5608 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_G12A
) {
5610 WRITE_VREG(HEVC_DBLK_CFGE
, buf_spec
->dblk_para
.buf_start
);
5611 if (debug
& VP9_DEBUG_BUFMGR_MORE
)
5612 pr_info("Write HEVC_DBLK_CFGE\n");
5615 WRITE_VREG(HEVC_DBLK_CFG4
, buf_spec
->dblk_para
.buf_start
);
5617 WRITE_VREG(HEVC_DBLK_CFG5
, buf_spec
->dblk_data
.buf_start
);
5619 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_SM1
) {
5621 * data32 = (READ_VREG(P_HEVC_DBLK_CFG3)>>8) & 0xff; // xio left offset, default is 0x40
5622 * data32 = data32 * 2;
5623 * data32 = (READ_VREG(P_HEVC_DBLK_CFG3)>>16) & 0xff; // adp left offset, default is 0x040
5624 * data32 = data32 * 2;
5626 WRITE_VREG(HEVC_DBLK_CFG3
, 0x808010); // make left storage 2 x 4k]
5628 #ifdef LOSLESS_COMPRESS_MODE
5629 if (pbi
->mmu_enable
) {
5630 /*bit[4] : paged_mem_mode*/
5631 WRITE_VREG(HEVCD_MPP_DECOMP_CTL1
, (0x1 << 4));
5632 if (get_cpu_major_id() < AM_MESON_CPU_MAJOR_ID_SM1
)
5633 WRITE_VREG(HEVCD_MPP_DECOMP_CTL2
, 0);
5635 /*if(cur_pic_config->bit_depth == VPX_BITS_10)
5636 * WRITE_VREG(P_HEVCD_MPP_DECOMP_CTL1, (0<<3));
5638 /*bit[3] smem mdoe*/
5639 /*else WRITE_VREG(P_HEVCD_MPP_DECOMP_CTL1, (1<<3));*/
5640 /*bit[3] smem mdoe*/
5641 WRITE_VREG(HEVCD_MPP_DECOMP_CTL2
,
5642 (losless_comp_body_size
>> 5));
5644 /*WRITE_VREG(HEVCD_MPP_DECOMP_CTL2,
5645 (losless_comp_body_size >> 5));*/
5646 /*WRITE_VREG(HEVCD_MPP_DECOMP_CTL3,
5647 (0xff<<20) | (0xff<<10) | 0xff);*/
5649 WRITE_VREG(HEVC_CM_BODY_LENGTH
, losless_comp_body_size
);
5650 WRITE_VREG(HEVC_CM_HEADER_OFFSET
, losless_comp_body_size
);
5651 WRITE_VREG(HEVC_CM_HEADER_LENGTH
, losless_comp_header_size
);
5652 if (get_double_write_mode(pbi
) & 0x10)
5653 WRITE_VREG(HEVCD_MPP_DECOMP_CTL1
, 0x1 << 31);
5655 WRITE_VREG(HEVCD_MPP_DECOMP_CTL1
, 0x1 << 31);
5658 if (pbi
->mmu_enable
) {
5659 WRITE_VREG(HEVC_SAO_MMU_VH0_ADDR
, buf_spec
->mmu_vbh
.buf_start
);
5660 WRITE_VREG(HEVC_SAO_MMU_VH1_ADDR
, buf_spec
->mmu_vbh
.buf_start
5661 + buf_spec
->mmu_vbh
.buf_size
/2);
5662 /*data32 = READ_VREG(P_HEVC_SAO_CTRL9);*/
5664 /*WRITE_VREG(P_HEVC_SAO_CTRL9, data32);*/
5666 /* use HEVC_CM_HEADER_START_ADDR */
5667 data32
= READ_VREG(HEVC_SAO_CTRL5
);
5669 WRITE_VREG(HEVC_SAO_CTRL5
, data32
);
5672 WRITE_VREG(VP9_SEG_MAP_BUFFER
, buf_spec
->seg_map
.buf_start
);
5674 WRITE_VREG(LMEM_DUMP_ADR
, (u32
)pbi
->lmem_phy_addr
);
5676 WRITE_VREG(VP9_PROB_SWAP_BUFFER
, pbi
->prob_buffer_phy_addr
);
5677 WRITE_VREG(VP9_COUNT_SWAP_BUFFER
, pbi
->count_buffer_phy_addr
);
5678 if (pbi
->mmu_enable
) {
5679 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_G12A
)
5680 WRITE_VREG(HEVC_ASSIST_MMU_MAP_ADDR
, pbi
->frame_mmu_map_phy_addr
);
5682 WRITE_VREG(VP9_MMU_MAP_BUFFER
, pbi
->frame_mmu_map_phy_addr
);
5688 #ifdef VP9_LPF_LVL_UPDATE
5690 * Defines, declarations, sub-functions for vp9 de-block loop
5691 filter Thr/Lvl table update
5692 * - struct segmentation is for loop filter only (removed something)
5693 * - function "vp9_loop_filter_init" and "vp9_loop_filter_frame_init" will
5694 be instantiated in C_Entry
5695 * - vp9_loop_filter_init run once before decoding start
5696 * - vp9_loop_filter_frame_init run before every frame decoding start
5697 * - set video format to VP9 is in vp9_loop_filter_init
5699 #define MAX_LOOP_FILTER 63
5700 #define MAX_REF_LF_DELTAS 4
5701 #define MAX_MODE_LF_DELTAS 2
5702 /*#define INTRA_FRAME 0*/
5703 /*#define LAST_FRAME 1*/
5704 /*#define MAX_REF_FRAMES 4*/
5705 #define SEGMENT_DELTADATA 0
5706 #define SEGMENT_ABSDATA 1
5707 #define MAX_SEGMENTS 8
5708 /*.#define SEG_TREE_PROBS (MAX_SEGMENTS-1)*/
5709 /*no use for loop filter, if this struct for common use, pls add it back*/
5710 /*#define PREDICTION_PROBS 3*/
5711 /* no use for loop filter, if this struct for common use, pls add it back*/
5713 enum SEG_LVL_FEATURES
{
5714 SEG_LVL_ALT_Q
= 0, /*Use alternate Quantizer ....*/
5715 SEG_LVL_ALT_LF
= 1, /*Use alternate loop filter value...*/
5716 SEG_LVL_REF_FRAME
= 2, /*Optional Segment reference frame*/
5717 SEG_LVL_SKIP
= 3, /*Optional Segment (0,0) + skip mode*/
5718 SEG_LVL_MAX
= 4 /*Number of features supported*/
5721 struct segmentation
{
5724 uint8_t update_data
;
5726 uint8_t temporal_update
;
5728 /*no use for loop filter, if this struct
5729 *for common use, pls add it back
5731 /*vp9_prob tree_probs[SEG_TREE_PROBS]; */
5732 /* no use for loop filter, if this struct
5733 * for common use, pls add it back
5735 /*vp9_prob pred_probs[PREDICTION_PROBS];*/
5737 int16_t feature_data
[MAX_SEGMENTS
][SEG_LVL_MAX
];
5738 unsigned int feature_mask
[MAX_SEGMENTS
];
5741 struct loop_filter_thresh
{
5747 struct loop_filter_info_n
{
5748 struct loop_filter_thresh lfthr
[MAX_LOOP_FILTER
+ 1];
5749 uint8_t lvl
[MAX_SEGMENTS
][MAX_REF_FRAMES
][MAX_MODE_LF_DELTAS
];
5755 int sharpness_level
;
5756 int last_sharpness_level
;
5758 uint8_t mode_ref_delta_enabled
;
5759 uint8_t mode_ref_delta_update
;
5761 /*0 = Intra, Last, GF, ARF*/
5762 signed char ref_deltas
[MAX_REF_LF_DELTAS
];
5763 signed char last_ref_deltas
[MAX_REF_LF_DELTAS
];
5766 signed char mode_deltas
[MAX_MODE_LF_DELTAS
];
5767 signed char last_mode_deltas
[MAX_MODE_LF_DELTAS
];
5770 static int vp9_clamp(int value
, int low
, int high
)
5772 return value
< low
? low
: (value
> high
? high
: value
);
5775 int segfeature_active(struct segmentation
*seg
,
5777 enum SEG_LVL_FEATURES feature_id
) {
5778 return seg
->enabled
&&
5779 (seg
->feature_mask
[segment_id
] & (1 << feature_id
));
5782 int get_segdata(struct segmentation
*seg
, int segment_id
,
5783 enum SEG_LVL_FEATURES feature_id
) {
5784 return seg
->feature_data
[segment_id
][feature_id
];
5787 static void vp9_update_sharpness(struct loop_filter_info_n
*lfi
,
5791 /*For each possible value for the loop filter fill out limits*/
5792 for (lvl
= 0; lvl
<= MAX_LOOP_FILTER
; lvl
++) {
5793 /*Set loop filter parameters that control sharpness.*/
5794 int block_inside_limit
= lvl
>> ((sharpness_lvl
> 0) +
5795 (sharpness_lvl
> 4));
5797 if (sharpness_lvl
> 0) {
5798 if (block_inside_limit
> (9 - sharpness_lvl
))
5799 block_inside_limit
= (9 - sharpness_lvl
);
5802 if (block_inside_limit
< 1)
5803 block_inside_limit
= 1;
5805 lfi
->lfthr
[lvl
].lim
= (uint8_t)block_inside_limit
;
5806 lfi
->lfthr
[lvl
].mblim
= (uint8_t)(2 * (lvl
+ 2) +
5807 block_inside_limit
);
5811 /*instantiate this function once when decode is started*/
5812 void vp9_loop_filter_init(struct VP9Decoder_s
*pbi
)
5814 struct loop_filter_info_n
*lfi
= pbi
->lfi
;
5815 struct loopfilter
*lf
= pbi
->lf
;
5816 struct segmentation
*seg_4lf
= pbi
->seg_4lf
;
5818 unsigned int data32
;
5820 memset(lfi
, 0, sizeof(struct loop_filter_info_n
));
5821 memset(lf
, 0, sizeof(struct loopfilter
));
5822 memset(seg_4lf
, 0, sizeof(struct segmentation
));
5823 lf
->sharpness_level
= 0; /*init to 0 */
5824 /*init limits for given sharpness*/
5825 vp9_update_sharpness(lfi
, lf
->sharpness_level
);
5826 lf
->last_sharpness_level
= lf
->sharpness_level
;
5827 /*init hev threshold const vectors (actually no use)
5828 *for (i = 0; i <= MAX_LOOP_FILTER; i++)
5829 * lfi->lfthr[i].hev_thr = (uint8_t)(i >> 4);
5832 /*Write to register*/
5833 for (i
= 0; i
< 32; i
++) {
5836 thr
= ((lfi
->lfthr
[i
* 2 + 1].lim
& 0x3f)<<8) |
5837 (lfi
->lfthr
[i
* 2 + 1].mblim
& 0xff);
5838 thr
= (thr
<<16) | ((lfi
->lfthr
[i
*2].lim
& 0x3f)<<8) |
5839 (lfi
->lfthr
[i
* 2].mblim
& 0xff);
5840 WRITE_VREG(HEVC_DBLK_CFG9
, thr
);
5843 /*video format is VP9*/
5844 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_SM1
) {
5845 data32
= (0x3 << 14) | // (dw fifo thres r and b)
5846 (0x3 << 12) | // (dw fifo thres r or b)
5847 (0x3 << 10) | // (dw fifo thres not r/b)
5848 (0x3 << 8) | // 1st/2nd write both enable
5849 (0x1 << 0); // vp9 video format
5850 } else if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_G12A
) {
5851 data32
= (0x57 << 8) | /*1st/2nd write both enable*/
5852 (0x1 << 0); /*vp9 video format*/
5854 data32
= 0x40400001;
5856 WRITE_VREG(HEVC_DBLK_CFGB
, data32
);
5857 if (debug
& VP9_DEBUG_BUFMGR_MORE
)
5858 pr_info("[DBLK DEBUG] CFGB : 0x%x\n", data32
);
5860 /* perform this function per frame*/
5861 void vp9_loop_filter_frame_init(struct segmentation
*seg
,
5862 struct loop_filter_info_n
*lfi
, struct loopfilter
*lf
,
5863 int default_filt_lvl
) {
5866 /*n_shift is the multiplier for lf_deltas
5867 *the multiplier is 1 for when filter_lvl is between 0 and 31;
5868 *2 when filter_lvl is between 32 and 63
5870 const int scale
= 1 << (default_filt_lvl
>> 5);
5872 /*update limits if sharpness has changed*/
5873 if (lf
->last_sharpness_level
!= lf
->sharpness_level
) {
5874 vp9_update_sharpness(lfi
, lf
->sharpness_level
);
5875 lf
->last_sharpness_level
= lf
->sharpness_level
;
5877 /*Write to register*/
5878 for (i
= 0; i
< 32; i
++) {
5881 thr
= ((lfi
->lfthr
[i
* 2 + 1].lim
& 0x3f) << 8)
5882 | (lfi
->lfthr
[i
* 2 + 1].mblim
& 0xff);
5883 thr
= (thr
<< 16) | ((lfi
->lfthr
[i
* 2].lim
& 0x3f) << 8)
5884 | (lfi
->lfthr
[i
* 2].mblim
& 0xff);
5885 WRITE_VREG(HEVC_DBLK_CFG9
, thr
);
5889 for (seg_id
= 0; seg_id
< MAX_SEGMENTS
; seg_id
++) {/*MAX_SEGMENTS = 8*/
5890 int lvl_seg
= default_filt_lvl
;
5892 if (segfeature_active(seg
, seg_id
, SEG_LVL_ALT_LF
)) {
5893 const int data
= get_segdata(seg
, seg_id
,
5895 lvl_seg
= vp9_clamp(seg
->abs_delta
== SEGMENT_ABSDATA
?
5896 data
: default_filt_lvl
+ data
,
5897 0, MAX_LOOP_FILTER
);
5899 pr_info("segfeature_active!!!seg_id=%d,lvl_seg=%d\n", seg_id
, lvl_seg
);
5903 if (!lf
->mode_ref_delta_enabled
) {
5904 /*we could get rid of this if we assume that deltas are set to
5905 *zero when not in use; encoder always uses deltas
5907 memset(lfi
->lvl
[seg_id
], lvl_seg
, sizeof(lfi
->lvl
[seg_id
]));
5910 const int intra_lvl
= lvl_seg
+ lf
->ref_deltas
[INTRA_FRAME
]
5913 pr_info("LF_PRINT:vp9_loop_filter_frame_init,seg_id=%d\n", seg_id
);
5914 pr_info("ref_deltas[INTRA_FRAME]=%d\n", lf
->ref_deltas
[INTRA_FRAME
]);
5916 lfi
->lvl
[seg_id
][INTRA_FRAME
][0] =
5917 vp9_clamp(intra_lvl
, 0, MAX_LOOP_FILTER
);
5919 for (ref
= LAST_FRAME
; ref
< MAX_REF_FRAMES
; ++ref
) {
5920 /* LAST_FRAME = 1, MAX_REF_FRAMES = 4*/
5921 for (mode
= 0; mode
< MAX_MODE_LF_DELTAS
; ++mode
) {
5922 /*MAX_MODE_LF_DELTAS = 2*/
5923 const int inter_lvl
=
5924 lvl_seg
+ lf
->ref_deltas
[ref
] * scale
5925 + lf
->mode_deltas
[mode
] * scale
;
5928 lfi
->lvl
[seg_id
][ref
][mode
] =
5929 vp9_clamp(inter_lvl
, 0,
5937 /*print out thr/lvl table per frame*/
5938 for (i
= 0; i
<= MAX_LOOP_FILTER
; i
++) {
5939 pr_info("LF_PRINT:(%d)thr=%d,blim=%d,lim=%d\n",
5940 i
, lfi
->lfthr
[i
].hev_thr
, lfi
->lfthr
[i
].mblim
,
5943 for (seg_id
= 0; seg_id
< MAX_SEGMENTS
; seg_id
++) {
5944 pr_info("LF_PRINT:lvl(seg_id=%d)(mode=0,%d,%d,%d,%d)\n",
5945 seg_id
, lfi
->lvl
[seg_id
][0][0],
5946 lfi
->lvl
[seg_id
][1][0], lfi
->lvl
[seg_id
][2][0],
5947 lfi
->lvl
[seg_id
][3][0]);
5948 pr_info("i(mode=1,%d,%d,%d,%d)\n", lfi
->lvl
[seg_id
][0][1],
5949 lfi
->lvl
[seg_id
][1][1], lfi
->lvl
[seg_id
][2][1],
5950 lfi
->lvl
[seg_id
][3][1]);
5954 /*Write to register */
5955 for (i
= 0; i
< 16; i
++) {
5958 level
= ((lfi
->lvl
[i
>> 1][3][i
& 1] & 0x3f) << 24) |
5959 ((lfi
->lvl
[i
>> 1][2][i
& 1] & 0x3f) << 16) |
5960 ((lfi
->lvl
[i
>> 1][1][i
& 1] & 0x3f) << 8) |
5961 (lfi
->lvl
[i
>> 1][0][i
& 1] & 0x3f);
5962 if (!default_filt_lvl
)
5964 WRITE_VREG(HEVC_DBLK_CFGA
, level
);
5967 /* VP9_LPF_LVL_UPDATE */
5970 static void vp9_init_decoder_hw(struct VP9Decoder_s
*pbi
, u32 mask
)
5972 unsigned int data32
;
5974 const unsigned short parser_cmd
[PARSER_CMD_NUMBER
] = {
5975 0x0401, 0x8401, 0x0800, 0x0402, 0x9002, 0x1423,
5976 0x8CC3, 0x1423, 0x8804, 0x9825, 0x0800, 0x04FE,
5977 0x8406, 0x8411, 0x1800, 0x8408, 0x8409, 0x8C2A,
5978 0x9C2B, 0x1C00, 0x840F, 0x8407, 0x8000, 0x8408,
5979 0x2000, 0xA800, 0x8410, 0x04DE, 0x840C, 0x840D,
5980 0xAC00, 0xA000, 0x08C0, 0x08E0, 0xA40E, 0xFC00,
5984 if (get_cpu_major_id() >= MESON_CPU_MAJOR_ID_G12A
) {
5985 /* Set MCR fetch priorities*/
5986 data32
= 0x1 | (0x1 << 2) | (0x1 <<3) |
5987 (24 << 4) | (32 << 11) | (24 << 18) | (32 << 25);
5988 WRITE_VREG(HEVCD_MPP_DECOMP_AXIURG_CTL
, data32
);
5991 /*if (debug & VP9_DEBUG_BUFMGR_MORE)
5992 pr_info("%s\n", __func__);*/
5993 if (mask
& HW_MASK_FRONT
) {
5994 data32
= READ_VREG(HEVC_PARSER_INT_CONTROL
);
5996 /* set bit 31~29 to 3 if HEVC_STREAM_FIFO_CTL[29] is 1 */
5997 data32
&= ~(7 << 29);
5998 data32
|= (3 << 29);
6001 (1 << 24) |/*stream_buffer_empty_int_amrisc_enable*/
6002 (1 << 22) |/*stream_fifo_empty_int_amrisc_enable*/
6003 (1 << 7) |/*dec_done_int_cpu_enable*/
6004 (1 << 4) |/*startcode_found_int_cpu_enable*/
6005 (0 << 3) |/*startcode_found_int_amrisc_enable*/
6006 (1 << 0) /*parser_int_enable*/
6008 #ifdef SUPPORT_FB_DECODING
6009 #ifndef FB_DECODING_TEST_SCHEDULE
6010 /*fed_fb_slice_done_int_cpu_enable*/
6011 if (pbi
->used_stage_buf_num
> 0)
6012 data32
|= (1 << 10);
6015 WRITE_VREG(HEVC_PARSER_INT_CONTROL
, data32
);
6017 data32
= READ_VREG(HEVC_SHIFT_STATUS
);
6019 (0 << 1) |/*emulation_check_off VP9
6020 do not have emulation*/
6021 (1 << 0)/*startcode_check_on*/
6023 WRITE_VREG(HEVC_SHIFT_STATUS
, data32
);
6024 WRITE_VREG(HEVC_SHIFT_CONTROL
,
6025 (0 << 14) | /*disable_start_code_protect*/
6026 (1 << 10) | /*length_zero_startcode_en for VP9*/
6027 (1 << 9) | /*length_valid_startcode_en for VP9*/
6028 (3 << 6) | /*sft_valid_wr_position*/
6029 (2 << 4) | /*emulate_code_length_sub_1*/
6030 (3 << 1) | /*start_code_length_sub_1
6031 VP9 use 0x00000001 as startcode (4 Bytes)*/
6032 (1 << 0) /*stream_shift_enable*/
6035 WRITE_VREG(HEVC_CABAC_CONTROL
,
6036 (1 << 0)/*cabac_enable*/
6039 WRITE_VREG(HEVC_PARSER_CORE_CONTROL
,
6040 (1 << 0)/* hevc_parser_core_clk_en*/
6044 WRITE_VREG(HEVC_DEC_STATUS_REG
, 0);
6048 if (mask
& HW_MASK_BACK
) {
6049 /*Initial IQIT_SCALELUT memory
6050 -- just to avoid X in simulation*/
6052 WRITE_VREG(HEVC_IQIT_SCALELUT_WR_ADDR
, 0);/*cfg_p_addr*/
6053 for (i
= 0; i
< 1024; i
++)
6054 WRITE_VREG(HEVC_IQIT_SCALELUT_DATA
, 0);
6057 if (mask
& HW_MASK_FRONT
) {
6059 #ifdef ENABLE_SWAP_TEST
6060 WRITE_VREG(HEVC_STREAM_SWAP_TEST
, 100);
6062 WRITE_VREG(HEVC_STREAM_SWAP_TEST
, 0);
6064 #ifdef MULTI_INSTANCE_SUPPORT
6065 if (!pbi
->m_ins_flag
) {
6066 if (pbi
->low_latency_flag
)
6067 decode_mode
= DECODE_MODE_SINGLE_LOW_LATENCY
;
6069 decode_mode
= DECODE_MODE_SINGLE
;
6070 } else if (vdec_frame_based(hw_to_vdec(pbi
)))
6071 decode_mode
= pbi
->no_head
?
6072 DECODE_MODE_MULTI_FRAMEBASE_NOHEAD
:
6073 DECODE_MODE_MULTI_FRAMEBASE
;
6075 decode_mode
= DECODE_MODE_MULTI_STREAMBASE
;
6076 #ifdef SUPPORT_FB_DECODING
6077 #ifndef FB_DECODING_TEST_SCHEDULE
6078 if (pbi
->used_stage_buf_num
> 0)
6079 decode_mode
|= (0x01 << 24);
6082 WRITE_VREG(DECODE_MODE
, decode_mode
);
6083 WRITE_VREG(HEVC_DECODE_SIZE
, 0);
6084 WRITE_VREG(HEVC_DECODE_COUNT
, 0);
6086 WRITE_VREG(DECODE_MODE
, DECODE_MODE_SINGLE
);
6087 WRITE_VREG(HEVC_DECODE_PIC_BEGIN_REG
, 0);
6088 WRITE_VREG(HEVC_DECODE_PIC_NUM_REG
, 0x7fffffff); /*to remove*/
6091 WRITE_VREG(HEVC_PARSER_CMD_WRITE
, (1 << 16) | (0 << 0));
6092 for (i
= 0; i
< PARSER_CMD_NUMBER
; i
++)
6093 WRITE_VREG(HEVC_PARSER_CMD_WRITE
, parser_cmd
[i
]);
6094 WRITE_VREG(HEVC_PARSER_CMD_SKIP_0
, PARSER_CMD_SKIP_CFG_0
);
6095 WRITE_VREG(HEVC_PARSER_CMD_SKIP_1
, PARSER_CMD_SKIP_CFG_1
);
6096 WRITE_VREG(HEVC_PARSER_CMD_SKIP_2
, PARSER_CMD_SKIP_CFG_2
);
6099 WRITE_VREG(HEVC_PARSER_IF_CONTROL
,
6100 /* (1 << 8) |*/ /*sao_sw_pred_enable*/
6101 (1 << 5) | /*parser_sao_if_en*/
6102 (1 << 2) | /*parser_mpred_if_en*/
6103 (1 << 0) /*parser_scaler_if_en*/
6107 if (mask
& HW_MASK_BACK
) {
6108 /*Changed to Start MPRED in microcode*/
6110 pr_info("[test.c] Start MPRED\n");
6111 WRITE_VREG(HEVC_MPRED_INT_STATUS,
6115 WRITE_VREG(HEVCD_IPP_TOP_CNTL
,
6116 (0 << 1) | /*enable ipp*/
6117 (1 << 0) /*software reset ipp and mpp*/
6119 WRITE_VREG(HEVCD_IPP_TOP_CNTL
,
6120 (1 << 1) | /*enable ipp*/
6121 (0 << 0) /*software reset ipp and mpp*/
6123 if (get_double_write_mode(pbi
) & 0x10) {
6124 /*Enable NV21 reference read mode for MC*/
6125 WRITE_VREG(HEVCD_MPP_DECOMP_CTL1
, 0x1 << 31);
6128 /*Initialize mcrcc and decomp perf counters*/
6129 if (mcrcc_cache_alg_flag
&&
6130 pbi
->init_flag
== 0) {
6131 mcrcc_perfcount_reset();
6132 decomp_perfcount_reset();
6139 #ifdef CONFIG_HEVC_CLK_FORCED_ON
6140 static void config_vp9_clk_forced_on(void)
6142 unsigned int rdata32
;
6144 rdata32
= READ_VREG(HEVC_IQIT_CLK_RST_CTRL
);
6145 WRITE_VREG(HEVC_IQIT_CLK_RST_CTRL
, rdata32
| (0x1 << 2));
6148 rdata32
= READ_VREG(HEVC_DBLK_CFG0
);
6149 WRITE_VREG(HEVC_DBLK_CFG0
, rdata32
| (0x1 << 2));
6152 rdata32
= READ_VREG(HEVC_SAO_CTRL1
);
6153 WRITE_VREG(HEVC_SAO_CTRL1
, rdata32
| (0x1 << 2));
6156 rdata32
= READ_VREG(HEVC_MPRED_CTRL1
);
6157 WRITE_VREG(HEVC_MPRED_CTRL1
, rdata32
| (0x1 << 24));
6160 rdata32
= READ_VREG(HEVC_STREAM_CONTROL
);
6161 WRITE_VREG(HEVC_STREAM_CONTROL
, rdata32
| (0x1 << 15));
6162 rdata32
= READ_VREG(HEVC_SHIFT_CONTROL
);
6163 WRITE_VREG(HEVC_SHIFT_CONTROL
, rdata32
| (0x1 << 15));
6164 rdata32
= READ_VREG(HEVC_CABAC_CONTROL
);
6165 WRITE_VREG(HEVC_CABAC_CONTROL
, rdata32
| (0x1 << 13));
6166 rdata32
= READ_VREG(HEVC_PARSER_CORE_CONTROL
);
6167 WRITE_VREG(HEVC_PARSER_CORE_CONTROL
, rdata32
| (0x1 << 15));
6168 rdata32
= READ_VREG(HEVC_PARSER_INT_CONTROL
);
6169 WRITE_VREG(HEVC_PARSER_INT_CONTROL
, rdata32
| (0x1 << 15));
6170 rdata32
= READ_VREG(HEVC_PARSER_IF_CONTROL
);
6171 WRITE_VREG(HEVC_PARSER_IF_CONTROL
,
6172 rdata32
| (0x1 << 6) | (0x1 << 3) | (0x1 << 1));
6175 rdata32
= READ_VREG(HEVCD_IPP_DYNCLKGATE_CONFIG
);
6176 WRITE_VREG(HEVCD_IPP_DYNCLKGATE_CONFIG
, rdata32
| 0xffffffff);
6179 rdata32
= READ_VREG(HEVCD_MCRCC_CTL1
);
6180 WRITE_VREG(HEVCD_MCRCC_CTL1
, rdata32
| (0x1 << 3));
6186 static void dump_hit_rate(struct VP9Decoder_s
*pbi
)
6188 if (debug
& VP9_DEBUG_CACHE_HIT_RATE
) {
6189 mcrcc_get_hitrate(pbi
->m_ins_flag
);
6190 decomp_get_hitrate();
6191 decomp_get_comprate();
6195 static void config_mcrcc_axi_hw(struct VP9Decoder_s
*pbi
)
6197 unsigned int rdata32
;
6198 unsigned short is_inter
;
6199 /*pr_info("Entered config_mcrcc_axi_hw...\n");*/
6200 WRITE_VREG(HEVCD_MCRCC_CTL1
, 0x2);/* reset mcrcc*/
6201 is_inter
= ((pbi
->common
.frame_type
!= KEY_FRAME
) &&
6202 (!pbi
->common
.intra_only
)) ? 1 : 0;
6203 if (!is_inter
) { /* I-PIC*/
6204 /*remove reset -- disables clock*/
6205 WRITE_VREG(HEVCD_MCRCC_CTL1
, 0x0);
6209 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_SM1
) {
6210 mcrcc_get_hitrate(pbi
->m_ins_flag
);
6211 decomp_get_hitrate();
6212 decomp_get_comprate();
6215 WRITE_VREG(HEVCD_MPP_ANC_CANVAS_ACCCONFIG_ADDR
,
6216 (0 << 8) | (1 << 1) | 0);
6217 rdata32
= READ_VREG(HEVCD_MPP_ANC_CANVAS_DATA_ADDR
);
6218 rdata32
= rdata32
& 0xffff;
6219 rdata32
= rdata32
| (rdata32
<< 16);
6220 WRITE_VREG(HEVCD_MCRCC_CTL2
, rdata32
);
6221 /*Programme canvas1 */
6222 rdata32
= READ_VREG(HEVCD_MPP_ANC_CANVAS_DATA_ADDR
);
6223 rdata32
= rdata32
& 0xffff;
6224 rdata32
= rdata32
| (rdata32
<< 16);
6225 WRITE_VREG(HEVCD_MCRCC_CTL3
, rdata32
);
6226 /*enable mcrcc progressive-mode*/
6227 WRITE_VREG(HEVCD_MCRCC_CTL1
, 0xff0);
6230 static void config_mcrcc_axi_hw_new(struct VP9Decoder_s
*pbi
)
6232 u32 curr_picnum
= -1;
6233 u32 lastref_picnum
= -1;
6234 u32 goldenref_picnum
= -1;
6235 u32 altref_picnum
= -1;
6237 u32 lastref_delta_picnum
;
6238 u32 goldenref_delta_picnum
;
6239 u32 altref_delta_picnum
;
6249 u16 goldenref_inref
;
6252 u32 refcanvas_array
[3], utmp
;
6253 int deltapicnum_array
[3], tmp
;
6255 struct VP9_Common_s
*cm
= &pbi
->common
;
6256 struct PIC_BUFFER_CONFIG_s
*cur_pic_config
6257 = &cm
->cur_frame
->buf
;
6258 curr_picnum
= cur_pic_config
->decode_idx
;
6259 if (cm
->frame_refs
[0].buf
)
6260 lastref_picnum
= cm
->frame_refs
[0].buf
->decode_idx
;
6261 if (cm
->frame_refs
[1].buf
)
6262 goldenref_picnum
= cm
->frame_refs
[1].buf
->decode_idx
;
6263 if (cm
->frame_refs
[2].buf
)
6264 altref_picnum
= cm
->frame_refs
[2].buf
->decode_idx
;
6266 lastref_delta_picnum
= (lastref_picnum
>= curr_picnum
) ?
6267 (lastref_picnum
- curr_picnum
) : (curr_picnum
- lastref_picnum
);
6268 goldenref_delta_picnum
= (goldenref_picnum
>= curr_picnum
) ?
6269 (goldenref_picnum
- curr_picnum
) :
6270 (curr_picnum
- goldenref_picnum
);
6271 altref_delta_picnum
=
6272 (altref_picnum
>= curr_picnum
) ?
6273 (altref_picnum
- curr_picnum
) : (curr_picnum
- altref_picnum
);
6275 lastref_inref
= (cm
->frame_refs
[0].idx
!= INVALID_IDX
) ? 1 : 0;
6276 goldenref_inref
= (cm
->frame_refs
[1].idx
!= INVALID_IDX
) ? 1 : 0;
6277 altref_inref
= (cm
->frame_refs
[2].idx
!= INVALID_IDX
) ? 1 : 0;
6279 if (debug
& VP9_DEBUG_CACHE
)
6280 pr_info("%s--0--lastref_inref:%d goldenref_inref:%d altref_inref:%d\n",
6281 __func__
, lastref_inref
, goldenref_inref
, altref_inref
);
6283 WRITE_VREG(HEVCD_MCRCC_CTL1
, 0x2); /* reset mcrcc */
6285 is_inter
= ((pbi
->common
.frame_type
!= KEY_FRAME
)
6286 && (!pbi
->common
.intra_only
)) ? 1 : 0;
6288 if (!is_inter
) { /* I-PIC */
6289 /* remove reset -- disables clock */
6290 WRITE_VREG(HEVCD_MCRCC_CTL1
, 0x0);
6294 if (!pbi
->m_ins_flag
)
6297 WRITE_VREG(HEVCD_MPP_ANC_CANVAS_ACCCONFIG_ADDR
, (0 << 8) | (1<<1) | 0);
6298 lastcanvas
= READ_VREG(HEVCD_MPP_ANC_CANVAS_DATA_ADDR
);
6299 goldencanvas
= READ_VREG(HEVCD_MPP_ANC_CANVAS_DATA_ADDR
);
6300 altrefcanvas
= READ_VREG(HEVCD_MPP_ANC_CANVAS_DATA_ADDR
);
6302 if (debug
& VP9_DEBUG_CACHE
)
6303 pr_info("[test.c] lastref_canv:%x goldenref_canv:%x altref_canv:%x\n",
6304 lastcanvas
, goldencanvas
, altrefcanvas
);
6306 altref_inref
= ((altref_inref
== 1) &&
6307 (altrefcanvas
!= (goldenref_inref
6308 ? goldencanvas
: 0xffffffff)) &&
6309 (altrefcanvas
!= (lastref_inref
?
6310 lastcanvas
: 0xffffffff))) ? 1 : 0;
6311 goldenref_inref
= ((goldenref_inref
== 1) &&
6312 (goldencanvas
!= (lastref_inref
?
6313 lastcanvas
: 0xffffffff))) ? 1 : 0;
6314 if (debug
& VP9_DEBUG_CACHE
)
6315 pr_info("[test.c]--1--lastref_inref:%d goldenref_inref:%d altref_inref:%d\n",
6316 lastref_inref
, goldenref_inref
, altref_inref
);
6318 altref_delta_picnum
= altref_inref
? altref_delta_picnum
: 0x7fffffff;
6319 goldenref_delta_picnum
= goldenref_inref
?
6320 goldenref_delta_picnum
: 0x7fffffff;
6321 lastref_delta_picnum
= lastref_inref
?
6322 lastref_delta_picnum
: 0x7fffffff;
6323 if (debug
& VP9_DEBUG_CACHE
)
6324 pr_info("[test.c]--1--lastref_delta_picnum:%d goldenref_delta_picnum:%d altref_delta_picnum:%d\n",
6325 lastref_delta_picnum
, goldenref_delta_picnum
,
6326 altref_delta_picnum
);
6327 /*ARRAY SORT HERE DELTA/CANVAS ARRAY SORT -- use DELTA*/
6329 refcanvas_array
[0] = lastcanvas
;
6330 refcanvas_array
[1] = goldencanvas
;
6331 refcanvas_array
[2] = altrefcanvas
;
6333 deltapicnum_array
[0] = lastref_delta_picnum
;
6334 deltapicnum_array
[1] = goldenref_delta_picnum
;
6335 deltapicnum_array
[2] = altref_delta_picnum
;
6337 /* sort0 : 2-to-1 */
6338 if (deltapicnum_array
[2] < deltapicnum_array
[1]) {
6339 utmp
= refcanvas_array
[2];
6340 refcanvas_array
[2] = refcanvas_array
[1];
6341 refcanvas_array
[1] = utmp
;
6342 tmp
= deltapicnum_array
[2];
6343 deltapicnum_array
[2] = deltapicnum_array
[1];
6344 deltapicnum_array
[1] = tmp
;
6346 /* sort1 : 1-to-0 */
6347 if (deltapicnum_array
[1] < deltapicnum_array
[0]) {
6348 utmp
= refcanvas_array
[1];
6349 refcanvas_array
[1] = refcanvas_array
[0];
6350 refcanvas_array
[0] = utmp
;
6351 tmp
= deltapicnum_array
[1];
6352 deltapicnum_array
[1] = deltapicnum_array
[0];
6353 deltapicnum_array
[0] = tmp
;
6355 /* sort2 : 2-to-1 */
6356 if (deltapicnum_array
[2] < deltapicnum_array
[1]) {
6357 utmp
= refcanvas_array
[2]; refcanvas_array
[2] =
6358 refcanvas_array
[1]; refcanvas_array
[1] = utmp
;
6359 tmp
= deltapicnum_array
[2]; deltapicnum_array
[2] =
6360 deltapicnum_array
[1]; deltapicnum_array
[1] = tmp
;
6362 if (mcrcc_cache_alg_flag
==
6363 THODIYIL_MCRCC_CANVAS_ALGX
) { /*09/15/2017*/
6364 /* lowest delta_picnum */
6365 rdata32
= refcanvas_array
[0];
6366 rdata32
= rdata32
& 0xffff;
6367 rdata32
= rdata32
| (rdata32
<< 16);
6368 WRITE_VREG(HEVCD_MCRCC_CTL2
, rdata32
);
6370 /* 2nd-lowest delta_picnum */
6371 rdata32
= refcanvas_array
[1];
6372 rdata32
= rdata32
& 0xffff;
6373 rdata32
= rdata32
| (rdata32
<< 16);
6374 WRITE_VREG(HEVCD_MCRCC_CTL3
, rdata32
);
6376 /* previous version -- LAST/GOLDEN ALWAYS -- before 09/13/2017*/
6377 WRITE_VREG(HEVCD_MPP_ANC_CANVAS_ACCCONFIG_ADDR
,
6378 (0 << 8) | (1<<1) | 0);
6379 rdata32
= READ_VREG(HEVCD_MPP_ANC_CANVAS_DATA_ADDR
);
6380 rdata32
= rdata32
& 0xffff;
6381 rdata32
= rdata32
| (rdata32
<< 16);
6382 WRITE_VREG(HEVCD_MCRCC_CTL2
, rdata32
);
6384 /* Programme canvas1 */
6385 rdata32
= READ_VREG(HEVCD_MPP_ANC_CANVAS_DATA_ADDR
);
6386 rdata32
= rdata32
& 0xffff;
6387 rdata32
= rdata32
| (rdata32
<< 16);
6388 WRITE_VREG(HEVCD_MCRCC_CTL3
, rdata32
);
6391 WRITE_VREG(HEVCD_MCRCC_CTL1
, 0xff0); /* enable mcrcc progressive-mode */
6398 static void free_lf_buf(struct VP9Decoder_s
*pbi
)
6405 vfree(pbi
->seg_4lf
);
6408 pbi
->seg_4lf
= NULL
;
6411 static int alloc_lf_buf(struct VP9Decoder_s
*pbi
)
6413 pbi
->lfi
= vmalloc(sizeof(struct loop_filter_info_n
));
6414 pbi
->lf
= vmalloc(sizeof(struct loopfilter
));
6415 pbi
->seg_4lf
= vmalloc(sizeof(struct segmentation
));
6416 if (pbi
->lfi
== NULL
|| pbi
->lf
== NULL
|| pbi
->seg_4lf
== NULL
) {
6418 pr_err("[test.c] vp9_loop_filter init malloc error!!!\n");
6424 static void vp9_local_uninit(struct VP9Decoder_s
*pbi
)
6426 pbi
->rpm_ptr
= NULL
;
6427 pbi
->lmem_ptr
= NULL
;
6428 if (pbi
->rpm_addr
) {
6429 dma_free_coherent(amports_get_dma_device(),
6433 pbi
->rpm_addr
= NULL
;
6435 if (pbi
->lmem_addr
) {
6436 if (pbi
->lmem_phy_addr
)
6437 dma_free_coherent(amports_get_dma_device(),
6438 LMEM_BUF_SIZE
, pbi
->lmem_addr
,
6439 pbi
->lmem_phy_addr
);
6440 pbi
->lmem_addr
= NULL
;
6442 if (pbi
->prob_buffer_addr
) {
6443 if (pbi
->prob_buffer_phy_addr
)
6444 dma_free_coherent(amports_get_dma_device(),
6445 PROB_BUF_SIZE
, pbi
->prob_buffer_addr
,
6446 pbi
->prob_buffer_phy_addr
);
6448 pbi
->prob_buffer_addr
= NULL
;
6450 if (pbi
->count_buffer_addr
) {
6451 if (pbi
->count_buffer_phy_addr
)
6452 dma_free_coherent(amports_get_dma_device(),
6453 COUNT_BUF_SIZE
, pbi
->count_buffer_addr
,
6454 pbi
->count_buffer_phy_addr
);
6456 pbi
->count_buffer_addr
= NULL
;
6458 if (pbi
->mmu_enable
) {
6459 u32 mmu_map_size
= vvp9_frame_mmu_map_size(pbi
);
6460 if (pbi
->frame_mmu_map_addr
) {
6461 if (pbi
->frame_mmu_map_phy_addr
)
6462 dma_free_coherent(amports_get_dma_device(),
6464 pbi
->frame_mmu_map_addr
,
6465 pbi
->frame_mmu_map_phy_addr
);
6466 pbi
->frame_mmu_map_addr
= NULL
;
6469 #ifdef SUPPORT_FB_DECODING
6470 if (pbi
->stage_mmu_map_addr
) {
6471 if (pbi
->stage_mmu_map_phy_addr
)
6472 dma_free_coherent(amports_get_dma_device(),
6473 STAGE_MMU_MAP_SIZE
* STAGE_MAX_BUFFERS
,
6474 pbi
->stage_mmu_map_addr
,
6475 pbi
->stage_mmu_map_phy_addr
);
6476 pbi
->stage_mmu_map_addr
= NULL
;
6479 uninit_stage_buf(pbi
);
6482 #ifdef VP9_LPF_LVL_UPDATE
6490 static int vp9_local_init(struct VP9Decoder_s
*pbi
)
6493 /*int losless_comp_header_size, losless_comp_body_size;*/
6495 struct BuffInfo_s
*cur_buf_info
= NULL
;
6497 memset(&pbi
->param
, 0, sizeof(union param_u
));
6498 memset(&pbi
->common
, 0, sizeof(struct VP9_Common_s
));
6499 #ifdef MULTI_INSTANCE_SUPPORT
6500 cur_buf_info
= &pbi
->work_space_buf_store
;
6502 if (vdec_is_support_4k()) {
6503 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_SM1
) {
6504 memcpy(cur_buf_info
, &amvvp9_workbuff_spec
[2], /* 8k */
6505 sizeof(struct BuffInfo_s
));
6507 memcpy(cur_buf_info
, &amvvp9_workbuff_spec
[1], /* 4k */
6508 sizeof(struct BuffInfo_s
));
6510 memcpy(cur_buf_info
, &amvvp9_workbuff_spec
[0],/* 1080p */
6511 sizeof(struct BuffInfo_s
));
6513 cur_buf_info
->start_adr
= pbi
->buf_start
;
6514 if (!pbi
->mmu_enable
)
6515 pbi
->mc_buf_spec
.buf_end
= pbi
->buf_start
+ pbi
->buf_size
;
6518 /*! MULTI_INSTANCE_SUPPORT*/
6519 if (vdec_is_support_4k()) {
6520 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_SM1
)
6521 cur_buf_info
= &amvvp9_workbuff_spec
[2];/* 8k work space */
6523 cur_buf_info
= &amvvp9_workbuff_spec
[1];/* 4k2k work space */
6525 cur_buf_info
= &amvvp9_workbuff_spec
[0];/* 1080p work space */
6529 init_buff_spec(pbi
, cur_buf_info
);
6530 vp9_bufmgr_init(pbi
, cur_buf_info
, NULL
);
6532 if (!vdec_is_support_4k()
6533 && (buf_alloc_width
> 1920 && buf_alloc_height
> 1088)) {
6534 buf_alloc_width
= 1920;
6535 buf_alloc_height
= 1088;
6536 if (pbi
->max_pic_w
> 1920 && pbi
->max_pic_h
> 1088) {
6537 pbi
->max_pic_w
= 1920;
6538 pbi
->max_pic_h
= 1088;
6540 } else if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_SM1
) {
6541 buf_alloc_width
= 8192;
6542 buf_alloc_height
= 4608;
6544 pbi
->init_pic_w
= pbi
->max_pic_w
? pbi
->max_pic_w
:
6545 (buf_alloc_width
? buf_alloc_width
:
6546 (pbi
->vvp9_amstream_dec_info
.width
?
6547 pbi
->vvp9_amstream_dec_info
.width
:
6548 pbi
->work_space_buf
->max_width
));
6549 pbi
->init_pic_h
= pbi
->max_pic_h
? pbi
->max_pic_h
:
6550 (buf_alloc_height
? buf_alloc_height
:
6551 (pbi
->vvp9_amstream_dec_info
.height
?
6552 pbi
->vvp9_amstream_dec_info
.height
:
6553 pbi
->work_space_buf
->max_height
));
6555 /* video is not support unaligned with 64 in tl1
6556 ** vdec canvas mode will be linear when dump yuv is set
6558 if ((get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_G12A
) &&
6559 (pbi
->double_write_mode
!= 0) &&
6560 (((pbi
->max_pic_w
% 64) != 0) ||
6561 (pbi
->vvp9_amstream_dec_info
.width
% 64) != 0)) {
6562 if (hw_to_vdec(pbi
)->canvas_mode
!=
6563 CANVAS_BLKMODE_LINEAR
)
6564 pbi
->mem_map_mode
= 2;
6566 pbi
->mem_map_mode
= 0;
6567 pr_info("vdec blkmod linear, force mem_map_mode 0\n");
6571 #ifndef MV_USE_FIXED_BUF
6572 if (init_mv_buf_list(pbi
) < 0) {
6573 pr_err("%s: init_mv_buf_list fail\n", __func__
);
6577 if (pbi
->save_buffer_mode
)
6578 pbi
->used_buf_num
= MAX_BUF_NUM_SAVE_BUF
;
6580 if (pbi
->is_used_v4l
)
6581 pbi
->used_buf_num
= 5 + pbi
->dynamic_buf_num_margin
;
6583 pbi
->used_buf_num
= max_buf_num
;
6586 if (pbi
->used_buf_num
> MAX_BUF_NUM
)
6587 pbi
->used_buf_num
= MAX_BUF_NUM
;
6588 if (pbi
->used_buf_num
> FRAME_BUFFERS
)
6589 pbi
->used_buf_num
= FRAME_BUFFERS
;
6591 pbi
->pts_unstable
= ((unsigned long)(pbi
->vvp9_amstream_dec_info
.param
)
6594 if ((debug
& VP9_DEBUG_SEND_PARAM_WITH_REG
) == 0) {
6595 pbi
->rpm_addr
= dma_alloc_coherent(amports_get_dma_device(),
6597 &pbi
->rpm_phy_addr
, GFP_KERNEL
);
6598 if (pbi
->rpm_addr
== NULL
) {
6599 pr_err("%s: failed to alloc rpm buffer\n", __func__
);
6603 pbi
->rpm_ptr
= pbi
->rpm_addr
;
6606 pbi
->lmem_addr
= dma_alloc_coherent(amports_get_dma_device(),
6608 &pbi
->lmem_phy_addr
, GFP_KERNEL
);
6609 if (pbi
->lmem_addr
== NULL
) {
6610 pr_err("%s: failed to alloc lmem buffer\n", __func__
);
6613 pbi
->lmem_ptr
= pbi
->lmem_addr
;
6615 pbi
->prob_buffer_addr
= dma_alloc_coherent(amports_get_dma_device(),
6617 &pbi
->prob_buffer_phy_addr
, GFP_KERNEL
);
6618 if (pbi
->prob_buffer_addr
== NULL
) {
6619 pr_err("%s: failed to alloc prob_buffer\n", __func__
);
6622 memset(pbi
->prob_buffer_addr
, 0, PROB_BUF_SIZE
);
6623 pbi
->count_buffer_addr
= dma_alloc_coherent(amports_get_dma_device(),
6625 &pbi
->count_buffer_phy_addr
, GFP_KERNEL
);
6626 if (pbi
->count_buffer_addr
== NULL
) {
6627 pr_err("%s: failed to alloc count_buffer\n", __func__
);
6630 memset(pbi
->count_buffer_addr
, 0, COUNT_BUF_SIZE
);
6632 if (pbi
->mmu_enable
) {
6633 u32 mmu_map_size
= vvp9_frame_mmu_map_size(pbi
);
6634 pbi
->frame_mmu_map_addr
=
6635 dma_alloc_coherent(amports_get_dma_device(),
6637 &pbi
->frame_mmu_map_phy_addr
, GFP_KERNEL
);
6638 if (pbi
->frame_mmu_map_addr
== NULL
) {
6639 pr_err("%s: failed to alloc count_buffer\n", __func__
);
6642 memset(pbi
->frame_mmu_map_addr
, 0, COUNT_BUF_SIZE
);
6644 #ifdef SUPPORT_FB_DECODING
6645 if (pbi
->m_ins_flag
&& stage_buf_num
> 0) {
6646 pbi
->stage_mmu_map_addr
=
6647 dma_alloc_coherent(amports_get_dma_device(),
6648 STAGE_MMU_MAP_SIZE
* STAGE_MAX_BUFFERS
,
6649 &pbi
->stage_mmu_map_phy_addr
, GFP_KERNEL
);
6650 if (pbi
->stage_mmu_map_addr
== NULL
) {
6651 pr_err("%s: failed to alloc count_buffer\n", __func__
);
6654 memset(pbi
->stage_mmu_map_addr
,
6655 0, STAGE_MMU_MAP_SIZE
* STAGE_MAX_BUFFERS
);
6657 init_stage_buf(pbi
);
6665 /********************************************
6667 ********************************************/
6668 #define CMD_FINISHED 0
6669 #define CMD_ALLOC_VIEW 1
6670 #define CMD_FRAME_DISPLAY 3
6671 #define CMD_DEBUG 10
6674 #define DECODE_BUFFER_NUM_MAX 32
6675 #define DISPLAY_BUFFER_NUM 6
6677 #define video_domain_addr(adr) (adr&0x7fffffff)
6678 #define DECODER_WORK_SPACE_SIZE 0x800000
6680 #define spec2canvas(x) \
6681 (((x)->uv_canvas_index << 16) | \
6682 ((x)->uv_canvas_index << 8) | \
6683 ((x)->y_canvas_index << 0))
6686 static void set_canvas(struct VP9Decoder_s
*pbi
,
6687 struct PIC_BUFFER_CONFIG_s
*pic_config
)
6689 struct vdec_s
*vdec
= hw_to_vdec(pbi
);
6690 int canvas_w
= ALIGN(pic_config
->y_crop_width
, 64)/4;
6691 int canvas_h
= ALIGN(pic_config
->y_crop_height
, 32)/4;
6692 int blkmode
= pbi
->mem_map_mode
;
6693 /*CANVAS_BLKMODE_64X32*/
6694 if (pic_config
->double_write_mode
) {
6695 canvas_w
= pic_config
->y_crop_width
/
6696 get_double_write_ratio(pbi
,
6697 pic_config
->double_write_mode
);
6698 canvas_h
= pic_config
->y_crop_height
/
6699 get_double_write_ratio(pbi
,
6700 pic_config
->double_write_mode
);
6702 if (pbi
->mem_map_mode
== 0)
6703 canvas_w
= ALIGN(canvas_w
, 32);
6705 canvas_w
= ALIGN(canvas_w
, 64);
6706 canvas_h
= ALIGN(canvas_h
, 32);
6708 if (vdec
->parallel_dec
== 1) {
6709 if (pic_config
->y_canvas_index
== -1)
6710 pic_config
->y_canvas_index
=
6711 vdec
->get_canvas_ex(CORE_MASK_HEVC
, vdec
->id
);
6712 if (pic_config
->uv_canvas_index
== -1)
6713 pic_config
->uv_canvas_index
=
6714 vdec
->get_canvas_ex(CORE_MASK_HEVC
, vdec
->id
);
6716 pic_config
->y_canvas_index
= 128 + pic_config
->index
* 2;
6717 pic_config
->uv_canvas_index
= 128 + pic_config
->index
* 2 + 1;
6720 canvas_config_ex(pic_config
->y_canvas_index
,
6721 pic_config
->dw_y_adr
, canvas_w
, canvas_h
,
6722 CANVAS_ADDR_NOWRAP
, blkmode
, pbi
->is_used_v4l
? 0 : 7);
6723 canvas_config_ex(pic_config
->uv_canvas_index
,
6724 pic_config
->dw_u_v_adr
, canvas_w
, canvas_h
,
6725 CANVAS_ADDR_NOWRAP
, blkmode
, pbi
->is_used_v4l
? 0 : 7);
6727 #ifdef MULTI_INSTANCE_SUPPORT
6728 pic_config
->canvas_config
[0].phy_addr
=
6729 pic_config
->dw_y_adr
;
6730 pic_config
->canvas_config
[0].width
=
6732 pic_config
->canvas_config
[0].height
=
6734 pic_config
->canvas_config
[0].block_mode
=
6736 pic_config
->canvas_config
[0].endian
= pbi
->is_used_v4l
? 0 : 7;
6738 pic_config
->canvas_config
[1].phy_addr
=
6739 pic_config
->dw_u_v_adr
;
6740 pic_config
->canvas_config
[1].width
=
6742 pic_config
->canvas_config
[1].height
=
6744 pic_config
->canvas_config
[1].block_mode
=
6746 pic_config
->canvas_config
[1].endian
= pbi
->is_used_v4l
? 0 : 7;
6752 static void set_frame_info(struct VP9Decoder_s
*pbi
, struct vframe_s
*vf
)
6755 vf
->duration
= pbi
->frame_dur
;
6756 vf
->duration_pulldown
= 0;
6758 vf
->prop
.master_display_colour
= pbi
->vf_dp
;
6759 vf
->signal_type
= pbi
->video_signal_type
;
6760 if (vf
->compWidth
&& vf
->compHeight
)
6761 pbi
->frame_ar
= vf
->compHeight
* 0x100 / vf
->compWidth
;
6762 ar
= min_t(u32
, pbi
->frame_ar
, DISP_RATIO_ASPECT_RATIO_MAX
);
6763 vf
->ratio_control
= (ar
<< DISP_RATIO_ASPECT_RATIO_BIT
);
6765 if (pbi
->is_used_v4l
&& pbi
->vf_dp
.present_flag
) {
6766 struct aml_vdec_hdr_infos hdr
;
6767 struct aml_vcodec_ctx
*ctx
=
6768 (struct aml_vcodec_ctx
*)(pbi
->v4l2_ctx
);
6770 memset(&hdr
, 0, sizeof(hdr
));
6771 hdr
.signal_type
= vf
->signal_type
;
6772 hdr
.color_parms
= pbi
->vf_dp
;
6773 vdec_v4l_set_hdr_infos(ctx
, &hdr
);
6777 static int vvp9_vf_states(struct vframe_states
*states
, void *op_arg
)
6779 struct VP9Decoder_s
*pbi
= (struct VP9Decoder_s
*)op_arg
;
6781 states
->vf_pool_size
= VF_POOL_SIZE
;
6782 states
->buf_free_num
= kfifo_len(&pbi
->newframe_q
);
6783 states
->buf_avail_num
= kfifo_len(&pbi
->display_q
);
6786 states
->buf_avail_num
= 0;
6790 static struct vframe_s
*vvp9_vf_peek(void *op_arg
)
6792 struct vframe_s
*vf
[2] = {0, 0};
6793 struct VP9Decoder_s
*pbi
= (struct VP9Decoder_s
*)op_arg
;
6798 if (kfifo_out_peek(&pbi
->display_q
, (void *)&vf
, 2)) {
6800 vf
[0]->next_vf_pts_valid
= true;
6801 vf
[0]->next_vf_pts
= vf
[1]->pts
;
6803 vf
[0]->next_vf_pts_valid
= false;
6810 static struct vframe_s
*vvp9_vf_get(void *op_arg
)
6812 struct vframe_s
*vf
;
6813 struct VP9Decoder_s
*pbi
= (struct VP9Decoder_s
*)op_arg
;
6820 if (kfifo_get(&pbi
->display_q
, &vf
)) {
6821 struct vframe_s
*next_vf
;
6822 uint8_t index
= vf
->index
& 0xff;
6823 if (index
< pbi
->used_buf_num
||
6824 (vf
->type
& VIDTYPE_V4L_EOS
)) {
6825 vf
->index_disp
= pbi
->vf_get_count
;
6826 pbi
->vf_get_count
++;
6827 if (debug
& VP9_DEBUG_BUFMGR
)
6828 pr_info("%s type 0x%x w/h %d/%d, pts %d, %lld\n",
6830 vf
->width
, vf
->height
,
6834 if (kfifo_peek(&pbi
->display_q
, &next_vf
)) {
6835 vf
->next_vf_pts_valid
= true;
6836 vf
->next_vf_pts
= next_vf
->pts
;
6838 vf
->next_vf_pts_valid
= false;
6846 static void vvp9_vf_put(struct vframe_s
*vf
, void *op_arg
)
6848 struct VP9Decoder_s
*pbi
= (struct VP9Decoder_s
*)op_arg
;
6849 uint8_t index
= vf
->index
& 0xff;
6851 if (vf
== (&pbi
->vframe_dummy
))
6854 kfifo_put(&pbi
->newframe_q
, (const struct vframe_s
*)vf
);
6855 pbi
->vf_put_count
++;
6856 if (index
< pbi
->used_buf_num
) {
6857 struct VP9_Common_s
*cm
= &pbi
->common
;
6858 struct BufferPool_s
*pool
= cm
->buffer_pool
;
6859 unsigned long flags
;
6861 lock_buffer_pool(pool
, flags
);
6862 if (pool
->frame_bufs
[index
].buf
.vf_ref
> 0)
6863 pool
->frame_bufs
[index
].buf
.vf_ref
--;
6865 if (pbi
->is_used_v4l
)
6866 pool
->frame_bufs
[index
].buf
.vframe_bound
= true;
6869 WRITE_VREG(HEVC_ASSIST_MBOX0_IRQ_REG
,
6871 pbi
->last_put_idx
= index
;
6872 pbi
->new_frame_displayed
++;
6873 unlock_buffer_pool(pool
, flags
);
6874 #ifdef SUPPORT_FB_DECODING
6875 if (pbi
->used_stage_buf_num
> 0 &&
6876 pbi
->back_not_run_ready
)
6877 trigger_schedule(pbi
);
6883 static int vvp9_event_cb(int type
, void *data
, void *private_data
)
6885 if (type
& VFRAME_EVENT_RECEIVER_RESET
) {
6887 unsigned long flags
;
6890 #ifndef CONFIG_AMLOGIC_POST_PROCESS_MANAGER
6891 vf_light_unreg_provider(&vvp9_vf_prov
);
6893 spin_lock_irqsave(&pbi
->lock
, flags
);
6896 spin_unlock_irqrestore(&pbi
->lock
, flags
);
6897 #ifndef CONFIG_AMLOGIC_POST_PROCESS_MANAGER
6898 vf_reg_provider(&vvp9_vf_prov
);
6907 void inc_vf_ref(struct VP9Decoder_s
*pbi
, int index
)
6909 struct VP9_Common_s
*cm
= &pbi
->common
;
6911 cm
->buffer_pool
->frame_bufs
[index
].buf
.vf_ref
++;
6913 if (debug
& VP9_DEBUG_BUFMGR_MORE
)
6914 pr_info("%s index = %d new vf_ref = %d\r\n",
6916 cm
->buffer_pool
->frame_bufs
[index
].buf
.vf_ref
);
6919 static int frame_duration_adapt(struct VP9Decoder_s
*pbi
, struct vframe_s
*vf
, u32 valid
)
6921 u32 old_duration
, pts_duration
= 0;
6924 if (pbi
->get_frame_dur
== true)
6927 pbi
->frame_cnt_window
++;
6928 if (!(pbi
->vp9_first_pts_ready
== 1)) {
6931 pbi
->frame_cnt_window
= 0;
6932 pbi
->duration_from_pts_done
= 0;
6933 pbi
->vp9_first_pts_ready
= 1;
6938 if (pts
< pbi
->pts1
) {
6939 if (pbi
->frame_cnt_window
> FRAME_CNT_WINDOW_SIZE
) {
6941 pbi
->frame_cnt_window
= 0;
6945 if (valid
&& (pbi
->frame_cnt_window
> FRAME_CNT_WINDOW_SIZE
) &&
6946 (pts
> pbi
->pts1
) && (pbi
->duration_from_pts_done
== 0)) {
6947 old_duration
= pbi
->frame_dur
;
6949 pts_duration
= (((pbi
->pts2
- pbi
->pts1
) * 16) /
6950 (pbi
->frame_cnt_window
* 15));
6952 if (close_to(pts_duration
, old_duration
, 2000)) {
6953 pbi
->frame_dur
= pts_duration
;
6954 if ((debug
& VP9_DEBUG_OUT_PTS
) != 0)
6955 pr_info("use calc duration %d\n", pts_duration
);
6958 if (pbi
->duration_from_pts_done
== 0) {
6959 if (close_to(pts_duration
, old_duration
, RATE_CORRECTION_THRESHOLD
)) {
6960 pbi
->duration_from_pts_done
= 1;
6962 if (!close_to(pts_duration
,
6963 old_duration
, 1000) &&
6964 !close_to(pts_duration
,
6965 pbi
->frame_dur
, 1000) &&
6966 close_to(pts_duration
,
6967 pbi
->last_duration
, 200)) {
6971 pbi
->frame_dur
= pts_duration
;
6973 pbi
->pts1
= pbi
->pts2
;
6974 pbi
->frame_cnt_window
= 0;
6975 pbi
->duration_from_pts_done
= 0;
6978 pbi
->last_duration
= pts_duration
;
6984 static void update_vf_memhandle(struct VP9Decoder_s
*pbi
,
6985 struct vframe_s
*vf
, struct PIC_BUFFER_CONFIG_s
*pic
)
6987 if (pic
->index
< 0) {
6988 vf
->mem_handle
= NULL
;
6989 vf
->mem_head_handle
= NULL
;
6990 } else if (vf
->type
& VIDTYPE_SCATTER
) {
6992 decoder_mmu_box_get_mem_handle(
6993 pbi
->mmu_box
, pic
->index
);
6994 vf
->mem_head_handle
=
6995 decoder_bmmu_box_get_mem_handle(
6997 HEADER_BUFFER_IDX(pic
->BUF_index
));
7000 decoder_bmmu_box_get_mem_handle(
7001 pbi
->bmmu_box
, VF_BUFFER_IDX(pic
->BUF_index
));
7002 vf
->mem_head_handle
= NULL
;
7003 /*vf->mem_head_handle =
7004 *decoder_bmmu_box_get_mem_handle(
7005 *hevc->bmmu_box, VF_BUFFER_IDX(BUF_index));
7010 static int prepare_display_buf(struct VP9Decoder_s
*pbi
,
7011 struct PIC_BUFFER_CONFIG_s
*pic_config
)
7013 struct vframe_s
*vf
= NULL
;
7014 int stream_offset
= pic_config
->stream_offset
;
7015 unsigned short slice_type
= pic_config
->slice_type
;
7016 u32 pts_valid
= 0, pts_us64_valid
= 0;
7021 if (debug
& VP9_DEBUG_BUFMGR
)
7022 pr_info("%s index = %d\r\n", __func__
, pic_config
->index
);
7023 if (kfifo_get(&pbi
->newframe_q
, &vf
) == 0) {
7024 pr_info("fatal error, no available buffer slot.");
7028 if (pic_config
->double_write_mode
)
7029 set_canvas(pbi
, pic_config
);
7031 display_frame_count
[pbi
->index
]++;
7033 if (pbi
->is_used_v4l
) {
7035 = pbi
->m_BUF
[pic_config
->BUF_index
].v4l_ref_buf_addr
;
7036 if (pbi
->mmu_enable
) {
7037 vf
->mm_box
.bmmu_box
= pbi
->bmmu_box
;
7038 vf
->mm_box
.bmmu_idx
= HEADER_BUFFER_IDX(pic_config
->BUF_index
);
7039 vf
->mm_box
.mmu_box
= pbi
->mmu_box
;
7040 vf
->mm_box
.mmu_idx
= pic_config
->index
;
7044 #ifdef MULTI_INSTANCE_SUPPORT
7045 if (vdec_frame_based(hw_to_vdec(pbi
))) {
7046 vf
->pts
= pic_config
->pts
;
7047 vf
->pts_us64
= pic_config
->pts64
;
7048 vf
->timestamp
= pic_config
->timestamp
;
7049 if (vf
->pts
!= 0 || vf
->pts_us64
!= 0) {
7058 /* if (pts_lookup_offset(PTS_TYPE_VIDEO,
7059 * stream_offset, &vf->pts, 0) != 0) {
7061 if (pts_lookup_offset_us64
7062 (PTS_TYPE_VIDEO
, stream_offset
, &vf
->pts
,
7064 &vf
->pts_us64
) != 0) {
7080 fill_frame_info(pbi
, pic_config
, frame_size
, vf
->pts
);
7083 pts_us64_save
= vf
->pts_us64
;
7084 if (pbi
->pts_unstable
) {
7085 frame_duration_adapt(pbi
, vf
, pts_valid
);
7086 if (pbi
->duration_from_pts_done
) {
7087 pbi
->pts_mode
= PTS_NONE_REF_USE_DURATION
;
7089 if (pts_valid
|| pts_us64_valid
)
7090 pbi
->pts_mode
= PTS_NORMAL
;
7094 if ((pbi
->pts_mode
== PTS_NORMAL
) && (vf
->pts
!= 0)
7095 && pbi
->get_frame_dur
) {
7096 int pts_diff
= (int)vf
->pts
- pbi
->last_lookup_pts
;
7099 pbi
->pts_mode_switching_count
++;
7100 pbi
->pts_mode_recovery_count
= 0;
7102 if (pbi
->pts_mode_switching_count
>=
7103 PTS_MODE_SWITCHING_THRESHOLD
) {
7105 PTS_NONE_REF_USE_DURATION
;
7107 ("HEVC: switch to n_d mode.\n");
7111 int p
= PTS_MODE_SWITCHING_RECOVERY_THREASHOLD
;
7113 pbi
->pts_mode_recovery_count
++;
7114 if (pbi
->pts_mode_recovery_count
> p
) {
7115 pbi
->pts_mode_switching_count
= 0;
7116 pbi
->pts_mode_recovery_count
= 0;
7122 pbi
->last_lookup_pts
= vf
->pts
;
7124 if ((pbi
->pts_mode
== PTS_NONE_REF_USE_DURATION
)
7125 && (slice_type
!= KEY_FRAME
))
7126 vf
->pts
= pbi
->last_pts
+ DUR2PTS(pbi
->frame_dur
);
7127 pbi
->last_pts
= vf
->pts
;
7129 if (vf
->pts_us64
!= 0)
7130 pbi
->last_lookup_pts_us64
= vf
->pts_us64
;
7132 if ((pbi
->pts_mode
== PTS_NONE_REF_USE_DURATION
)
7133 && (slice_type
!= KEY_FRAME
)) {
7135 pbi
->last_pts_us64
+
7136 (DUR2PTS(pbi
->frame_dur
) * 100 / 9);
7138 pbi
->last_pts_us64
= vf
->pts_us64
;
7139 if ((debug
& VP9_DEBUG_OUT_PTS
) != 0) {
7141 ("VP9 dec out pts: pts_mode=%d,dur=%d,pts(%d,%lld)(%d,%lld)\n",
7142 pbi
->pts_mode
, pbi
->frame_dur
, vf
->pts
,
7143 vf
->pts_us64
, pts_save
, pts_us64_save
);
7146 if (pbi
->pts_mode
== PTS_NONE_REF_USE_DURATION
) {
7147 vf
->disp_pts
= vf
->pts
;
7148 vf
->disp_pts_us64
= vf
->pts_us64
;
7150 vf
->pts_us64
= pts_us64_save
;
7153 vf
->disp_pts_us64
= 0;
7156 vf
->index
= 0xff00 | pic_config
->index
;
7158 if (pic_config
->double_write_mode
& 0x10) {
7159 /* double write only */
7160 vf
->compBodyAddr
= 0;
7161 vf
->compHeadAddr
= 0;
7163 if (pbi
->mmu_enable
) {
7164 vf
->compBodyAddr
= 0;
7165 vf
->compHeadAddr
= pic_config
->header_adr
;
7167 /*vf->compBodyAddr = pic_config->mc_y_adr;
7168 *vf->compHeadAddr = pic_config->mc_y_adr +
7169 *pic_config->comp_body_size; */
7172 vf
->canvas0Addr
= vf
->canvas1Addr
= 0;
7174 if (pic_config
->double_write_mode
) {
7175 vf
->type
= VIDTYPE_PROGRESSIVE
|
7177 vf
->type
|= VIDTYPE_VIU_NV21
;
7178 if ((pic_config
->double_write_mode
== 3) &&
7179 (!IS_8K_SIZE(pic_config
->y_crop_width
,
7180 pic_config
->y_crop_height
))) {
7181 vf
->type
|= VIDTYPE_COMPRESS
;
7182 if (pbi
->mmu_enable
)
7183 vf
->type
|= VIDTYPE_SCATTER
;
7185 #ifdef MULTI_INSTANCE_SUPPORT
7186 if (pbi
->m_ins_flag
) {
7187 vf
->canvas0Addr
= vf
->canvas1Addr
= -1;
7189 vf
->canvas0_config
[0] =
7190 pic_config
->canvas_config
[0];
7191 vf
->canvas0_config
[1] =
7192 pic_config
->canvas_config
[1];
7193 vf
->canvas1_config
[0] =
7194 pic_config
->canvas_config
[0];
7195 vf
->canvas1_config
[1] =
7196 pic_config
->canvas_config
[1];
7200 vf
->canvas0Addr
= vf
->canvas1Addr
=
7201 spec2canvas(pic_config
);
7203 vf
->canvas0Addr
= vf
->canvas1Addr
= 0;
7204 vf
->type
= VIDTYPE_COMPRESS
| VIDTYPE_VIU_FIELD
;
7205 if (pbi
->mmu_enable
)
7206 vf
->type
|= VIDTYPE_SCATTER
;
7209 switch (pic_config
->bit_depth
) {
7211 vf
->bitdepth
= BITDEPTH_Y8
|
7212 BITDEPTH_U8
| BITDEPTH_V8
;
7216 vf
->bitdepth
= BITDEPTH_Y10
|
7217 BITDEPTH_U10
| BITDEPTH_V10
;
7220 vf
->bitdepth
= BITDEPTH_Y10
|
7221 BITDEPTH_U10
| BITDEPTH_V10
;
7224 if ((vf
->type
& VIDTYPE_COMPRESS
) == 0)
7226 BITDEPTH_Y8
| BITDEPTH_U8
| BITDEPTH_V8
;
7227 if (pic_config
->bit_depth
== VPX_BITS_8
)
7228 vf
->bitdepth
|= BITDEPTH_SAVING_MODE
;
7230 /* if((vf->width!=pic_config->width)|
7231 * (vf->height!=pic_config->height))
7233 /* pr_info("aaa: %d/%d, %d/%d\n",
7234 vf->width,vf->height, pic_config->width,
7235 pic_config->height); */
7236 vf
->width
= pic_config
->y_crop_width
/
7237 get_double_write_ratio(pbi
,
7238 pic_config
->double_write_mode
);
7239 vf
->height
= pic_config
->y_crop_height
/
7240 get_double_write_ratio(pbi
,
7241 pic_config
->double_write_mode
);
7242 if (force_w_h
!= 0) {
7243 vf
->width
= (force_w_h
>> 16) & 0xffff;
7244 vf
->height
= force_w_h
& 0xffff;
7246 vf
->compWidth
= pic_config
->y_crop_width
;
7247 vf
->compHeight
= pic_config
->y_crop_height
;
7248 set_frame_info(pbi
, vf
);
7249 if (force_fps
& 0x100) {
7250 u32 rate
= force_fps
& 0xff;
7253 vf
->duration
= 96000/rate
;
7257 update_vf_memhandle(pbi
, vf
, pic_config
);
7258 if (!(pic_config
->y_crop_width
== 196
7259 && pic_config
->y_crop_height
== 196
7260 && (debug
& VP9_DEBUG_NO_TRIGGER_FRAME
) == 0
7261 && (get_cpu_major_id() < AM_MESON_CPU_MAJOR_ID_TXLX
))) {
7262 inc_vf_ref(pbi
, pic_config
->index
);
7263 decoder_do_frame_check(hw_to_vdec(pbi
), vf
);
7264 kfifo_put(&pbi
->display_q
, (const struct vframe_s
*)vf
);
7265 ATRACE_COUNTER(MODULE_NAME
, vf
->pts
);
7266 pbi
->vf_pre_count
++;
7267 #ifndef CONFIG_AMLOGIC_MEDIA_MULTI_DEC
7269 gvs
->frame_dur
= pbi
->frame_dur
;
7270 vdec_count_info(gvs
, 0, stream_offset
);
7272 hw_to_vdec(pbi
)->vdec_fps_detec(hw_to_vdec(pbi
)->id
);
7273 if (without_display_mode
== 0) {
7274 vf_notify_receiver(pbi
->provider_name
,
7275 VFRAME_EVENT_PROVIDER_VFRAME_READY
, NULL
);
7277 vvp9_vf_put(vvp9_vf_get(pbi
), pbi
);
7279 pbi
->stat
|= VP9_TRIGGER_FRAME_DONE
;
7280 hevc_source_changed(VFORMAT_VP9
, 196, 196, 30);
7281 pr_debug("[%s %d] drop trigger frame width %d height %d state 0x%x\n",
7282 __func__
, __LINE__
, vf
->width
,
7283 vf
->height
, pbi
->stat
);
7290 static int notify_v4l_eos(struct vdec_s
*vdec
)
7292 struct VP9Decoder_s
*hw
= (struct VP9Decoder_s
*)vdec
->private;
7293 struct aml_vcodec_ctx
*ctx
= (struct aml_vcodec_ctx
*)(hw
->v4l2_ctx
);
7294 struct vframe_s
*vf
= &hw
->vframe_dummy
;
7295 struct vdec_v4l2_buffer
*fb
= NULL
;
7296 int index
= INVALID_IDX
;
7299 if (hw
->is_used_v4l
&& hw
->eos
) {
7300 expires
= jiffies
+ msecs_to_jiffies(2000);
7301 while (INVALID_IDX
== (index
= v4l_get_free_fb(hw
))) {
7302 if (time_after(jiffies
, expires
) ||
7303 v4l2_m2m_num_dst_bufs_ready(ctx
->m2m_ctx
))
7307 if (index
== INVALID_IDX
) {
7308 if (vdec_v4l_get_buffer(hw
->v4l2_ctx
, &fb
) < 0) {
7309 pr_err("[%d] EOS get free buff fail.\n", ctx
->id
);
7314 vf
->type
|= VIDTYPE_V4L_EOS
;
7315 vf
->timestamp
= ULONG_MAX
;
7316 vf
->flag
= VFRAME_FLAG_EMPTY_FRAME_V4L
;
7317 vf
->v4l_mem_handle
= (index
== INVALID_IDX
) ? (ulong
)fb
:
7318 hw
->m_BUF
[index
].v4l_ref_buf_addr
;
7320 kfifo_put(&hw
->display_q
, (const struct vframe_s
*)vf
);
7321 vf_notify_receiver(vdec
->vf_provider_name
,
7322 VFRAME_EVENT_PROVIDER_VFRAME_READY
, NULL
);
7324 pr_info("[%d] VP9 EOS notify.\n", ctx
->id
);
7330 static void get_rpm_param(union param_u
*params
)
7333 unsigned int data32
;
7335 if (debug
& VP9_DEBUG_BUFMGR
)
7336 pr_info("enter %s\r\n", __func__
);
7337 for (i
= 0; i
< 128; i
++) {
7339 data32
= READ_VREG(RPM_CMD_REG
);
7340 /*pr_info("%x\n", data32);*/
7341 } while ((data32
& 0x10000) == 0);
7342 params
->l
.data
[i
] = data32
&0xffff;
7343 /*pr_info("%x\n", data32);*/
7344 WRITE_VREG(RPM_CMD_REG
, 0);
7346 if (debug
& VP9_DEBUG_BUFMGR
)
7347 pr_info("leave %s\r\n", __func__
);
7349 static void debug_buffer_mgr_more(struct VP9Decoder_s
*pbi
)
7353 if (!(debug
& VP9_DEBUG_BUFMGR_MORE
))
7355 pr_info("vp9_param: (%d)\n", pbi
->slice_idx
);
7356 for (i
= 0; i
< (RPM_END
-RPM_BEGIN
); i
++) {
7357 pr_info("%04x ", vp9_param
.l
.data
[i
]);
7358 if (((i
+ 1) & 0xf) == 0)
7361 pr_info("=============param==========\r\n");
7362 pr_info("profile %x\r\n", vp9_param
.p
.profile
);
7363 pr_info("show_existing_frame %x\r\n",
7364 vp9_param
.p
.show_existing_frame
);
7365 pr_info("frame_to_show_idx %x\r\n",
7366 vp9_param
.p
.frame_to_show_idx
);
7367 pr_info("frame_type %x\r\n", vp9_param
.p
.frame_type
);
7368 pr_info("show_frame %x\r\n", vp9_param
.p
.show_frame
);
7369 pr_info("e.r.r.o.r_resilient_mode %x\r\n",
7370 vp9_param
.p
.error_resilient_mode
);
7371 pr_info("intra_only %x\r\n", vp9_param
.p
.intra_only
);
7372 pr_info("display_size_present %x\r\n",
7373 vp9_param
.p
.display_size_present
);
7374 pr_info("reset_frame_context %x\r\n",
7375 vp9_param
.p
.reset_frame_context
);
7376 pr_info("refresh_frame_flags %x\r\n",
7377 vp9_param
.p
.refresh_frame_flags
);
7378 pr_info("bit_depth %x\r\n", vp9_param
.p
.bit_depth
);
7379 pr_info("width %x\r\n", vp9_param
.p
.width
);
7380 pr_info("height %x\r\n", vp9_param
.p
.height
);
7381 pr_info("display_width %x\r\n", vp9_param
.p
.display_width
);
7382 pr_info("display_height %x\r\n", vp9_param
.p
.display_height
);
7383 pr_info("ref_info %x\r\n", vp9_param
.p
.ref_info
);
7384 pr_info("same_frame_size %x\r\n", vp9_param
.p
.same_frame_size
);
7385 if (!(debug
& VP9_DEBUG_DBG_LF_PRINT
))
7387 pr_info("mode_ref_delta_enabled: 0x%x\r\n",
7388 vp9_param
.p
.mode_ref_delta_enabled
);
7389 pr_info("sharpness_level: 0x%x\r\n",
7390 vp9_param
.p
.sharpness_level
);
7391 pr_info("ref_deltas: 0x%x, 0x%x, 0x%x, 0x%x\r\n",
7392 vp9_param
.p
.ref_deltas
[0], vp9_param
.p
.ref_deltas
[1],
7393 vp9_param
.p
.ref_deltas
[2], vp9_param
.p
.ref_deltas
[3]);
7394 pr_info("mode_deltas: 0x%x, 0x%x\r\n", vp9_param
.p
.mode_deltas
[0],
7395 vp9_param
.p
.mode_deltas
[1]);
7396 pr_info("filter_level: 0x%x\r\n", vp9_param
.p
.filter_level
);
7397 pr_info("seg_enabled: 0x%x\r\n", vp9_param
.p
.seg_enabled
);
7398 pr_info("seg_abs_delta: 0x%x\r\n", vp9_param
.p
.seg_abs_delta
);
7399 pr_info("seg_lf_feature_enabled: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\r\n",
7400 (vp9_param
.p
.seg_lf_info
[0]>>15 & 1),
7401 (vp9_param
.p
.seg_lf_info
[1]>>15 & 1),
7402 (vp9_param
.p
.seg_lf_info
[2]>>15 & 1),
7403 (vp9_param
.p
.seg_lf_info
[3]>>15 & 1),
7404 (vp9_param
.p
.seg_lf_info
[4]>>15 & 1),
7405 (vp9_param
.p
.seg_lf_info
[5]>>15 & 1),
7406 (vp9_param
.p
.seg_lf_info
[6]>>15 & 1),
7407 (vp9_param
.p
.seg_lf_info
[7]>>15 & 1));
7408 pr_info("seg_lf_feature_data: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\r\n",
7409 (vp9_param
.p
.seg_lf_info
[0] & 0x13f),
7410 (vp9_param
.p
.seg_lf_info
[1] & 0x13f),
7411 (vp9_param
.p
.seg_lf_info
[2] & 0x13f),
7412 (vp9_param
.p
.seg_lf_info
[3] & 0x13f),
7413 (vp9_param
.p
.seg_lf_info
[4] & 0x13f),
7414 (vp9_param
.p
.seg_lf_info
[5] & 0x13f),
7415 (vp9_param
.p
.seg_lf_info
[6] & 0x13f),
7416 (vp9_param
.p
.seg_lf_info
[7] & 0x13f));
7421 static void vp9_recycle_mmu_buf_tail(struct VP9Decoder_s
*pbi
)
7423 struct VP9_Common_s
*const cm
= &pbi
->common
;
7424 if (pbi
->double_write_mode
& 0x10)
7426 if (cm
->cur_fb_idx_mmu
!= INVALID_IDX
) {
7427 if (pbi
->used_4k_num
== -1) {
7429 (READ_VREG(HEVC_SAO_MMU_STATUS
) >> 16);
7430 if (pbi
->m_ins_flag
)
7431 hevc_mmu_dma_check(hw_to_vdec(pbi
));
7433 decoder_mmu_box_free_idx_tail(pbi
->mmu_box
,
7434 cm
->cur_fb_idx_mmu
, pbi
->used_4k_num
);
7435 cm
->cur_fb_idx_mmu
= INVALID_IDX
;
7436 pbi
->used_4k_num
= -1;
7440 #ifdef MULTI_INSTANCE_SUPPORT
7441 static void vp9_recycle_mmu_buf(struct VP9Decoder_s
*pbi
)
7443 struct VP9_Common_s
*const cm
= &pbi
->common
;
7444 if (pbi
->double_write_mode
& 0x10)
7446 if (cm
->cur_fb_idx_mmu
!= INVALID_IDX
) {
7447 decoder_mmu_box_free_idx(pbi
->mmu_box
,
7448 cm
->cur_fb_idx_mmu
);
7450 cm
->cur_fb_idx_mmu
= INVALID_IDX
;
7451 pbi
->used_4k_num
= -1;
7455 void vp9_recycle_mmu_work(struct work_struct
*work
)
7457 struct VP9Decoder_s
*pbi
= container_of(work
,
7458 struct VP9Decoder_s
, recycle_mmu_work
);
7460 vp9_recycle_mmu_buf(pbi
);
7465 static void dec_again_process(struct VP9Decoder_s
*pbi
)
7468 pbi
->dec_result
= DEC_RESULT_AGAIN
;
7469 if (pbi
->process_state
==
7470 PROC_STATE_DECODESLICE
) {
7471 pbi
->process_state
=
7472 PROC_STATE_SENDAGAIN
;
7473 if (pbi
->mmu_enable
) {
7475 * Because vp9_recycle_mmu_buf has sleep function,we can't
7476 * call it directly. Use a recycle_mmu_work to substitude it.
7478 vdec_schedule_work(&pbi
->recycle_mmu_work
);
7481 reset_process_time(pbi
);
7482 vdec_schedule_work(&pbi
->work
);
7485 int continue_decoding(struct VP9Decoder_s
*pbi
)
7489 struct VP9_Common_s
*const cm
= &pbi
->common
;
7490 debug_buffer_mgr_more(pbi
);
7492 bit_depth_luma
= vp9_param
.p
.bit_depth
;
7493 bit_depth_chroma
= vp9_param
.p
.bit_depth
;
7495 if ((vp9_param
.p
.bit_depth
>= VPX_BITS_10
) &&
7496 (get_double_write_mode(pbi
) == 0x10)) {
7497 pbi
->fatal_error
|= DECODER_FATAL_ERROR_SIZE_OVERFLOW
;
7498 pr_err("fatal err, bit_depth %d, unsupport dw 0x10\n",
7499 vp9_param
.p
.bit_depth
);
7503 if (pbi
->process_state
!= PROC_STATE_SENDAGAIN
) {
7504 ret
= vp9_bufmgr_process(pbi
, &vp9_param
);
7505 if (!pbi
->m_ins_flag
)
7508 union param_u
*params
= &vp9_param
;
7509 if (pbi
->mmu_enable
&& ((pbi
->double_write_mode
& 0x10) == 0)) {
7510 ret
= vp9_alloc_mmu(pbi
,
7514 params
->p
.bit_depth
,
7515 pbi
->frame_mmu_map_addr
);
7517 cm
->cur_fb_idx_mmu
= cm
->new_fb_idx
;
7519 pr_err("can't alloc need mmu1,idx %d ret =%d\n",
7525 WRITE_VREG(HEVC_PARSER_PICTURE_SIZE
,
7526 (params
->p
.height
<< 16) | params
->p
.width
);
7529 pr_info("vp9_bufmgr_process=> %d, VP9_10B_DISCARD_NAL\r\n",
7531 WRITE_VREG(HEVC_DEC_STATUS_REG
, VP9_10B_DISCARD_NAL
);
7533 if (pbi
->mmu_enable
)
7534 vp9_recycle_mmu_buf(pbi
);
7535 #ifdef MULTI_INSTANCE_SUPPORT
7536 if (pbi
->m_ins_flag
) {
7537 pbi
->dec_result
= DEC_RESULT_DONE
;
7538 #ifdef SUPPORT_FB_DECODING
7539 if (pbi
->used_stage_buf_num
== 0)
7542 vdec_schedule_work(&pbi
->work
);
7546 } else if (ret
== 0) {
7547 struct PIC_BUFFER_CONFIG_s
*cur_pic_config
7548 = &cm
->cur_frame
->buf
;
7549 cur_pic_config
->decode_idx
= pbi
->frame_count
;
7551 if (pbi
->process_state
!= PROC_STATE_SENDAGAIN
) {
7552 if (!pbi
->m_ins_flag
) {
7554 decode_frame_count
[pbi
->index
]
7557 #ifdef MULTI_INSTANCE_SUPPORT
7559 cur_pic_config
->pts
= pbi
->chunk
->pts
;
7560 cur_pic_config
->pts64
= pbi
->chunk
->pts64
;
7561 cur_pic_config
->timestamp
= pbi
->chunk
->timestamp
;
7565 /*pr_info("Decode Frame Data %d\n", pbi->frame_count);*/
7566 config_pic_size(pbi
, vp9_param
.p
.bit_depth
);
7568 if ((pbi
->common
.frame_type
!= KEY_FRAME
)
7569 && (!pbi
->common
.intra_only
)) {
7570 config_mc_buffer(pbi
, vp9_param
.p
.bit_depth
);
7571 #ifdef SUPPORT_FB_DECODING
7572 if (pbi
->used_stage_buf_num
== 0)
7574 config_mpred_hw(pbi
);
7576 #ifdef SUPPORT_FB_DECODING
7577 if (pbi
->used_stage_buf_num
== 0)
7579 clear_mpred_hw(pbi
);
7582 if (mcrcc_cache_alg_flag
)
7583 config_mcrcc_axi_hw_new(pbi
);
7585 config_mcrcc_axi_hw(pbi
);
7587 config_sao_hw(pbi
, &vp9_param
);
7589 #ifdef VP9_LPF_LVL_UPDATE
7591 * Get loop filter related picture level parameters from Parser
7593 pbi
->lf
->mode_ref_delta_enabled
= vp9_param
.p
.mode_ref_delta_enabled
;
7594 pbi
->lf
->sharpness_level
= vp9_param
.p
.sharpness_level
;
7595 for (i
= 0; i
< 4; i
++)
7596 pbi
->lf
->ref_deltas
[i
] = vp9_param
.p
.ref_deltas
[i
];
7597 for (i
= 0; i
< 2; i
++)
7598 pbi
->lf
->mode_deltas
[i
] = vp9_param
.p
.mode_deltas
[i
];
7599 pbi
->default_filt_lvl
= vp9_param
.p
.filter_level
;
7600 pbi
->seg_4lf
->enabled
= vp9_param
.p
.seg_enabled
;
7601 pbi
->seg_4lf
->abs_delta
= vp9_param
.p
.seg_abs_delta
;
7602 for (i
= 0; i
< MAX_SEGMENTS
; i
++)
7603 pbi
->seg_4lf
->feature_mask
[i
] = (vp9_param
.p
.seg_lf_info
[i
] &
7604 0x8000) ? (1 << SEG_LVL_ALT_LF
) : 0;
7605 for (i
= 0; i
< MAX_SEGMENTS
; i
++)
7606 pbi
->seg_4lf
->feature_data
[i
][SEG_LVL_ALT_LF
]
7607 = (vp9_param
.p
.seg_lf_info
[i
]
7608 & 0x100) ? -(vp9_param
.p
.seg_lf_info
[i
]
7609 & 0x3f) : (vp9_param
.p
.seg_lf_info
[i
] & 0x3f);
7610 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_G12A
) {
7611 /*Set pipeline mode*/
7612 uint32_t lpf_data32
= READ_VREG(HEVC_DBLK_CFGB
);
7613 /*dblk pipeline mode=1 for performance*/
7614 if (vp9_param
.p
.width
>= 1280)
7615 lpf_data32
|= (0x1 << 4);
7617 lpf_data32
&= ~(0x3 << 4);
7618 WRITE_VREG(HEVC_DBLK_CFGB
, lpf_data32
);
7621 * Update loop filter Thr/Lvl table for every frame
7624 ("vp9_loop_filter (run before every frame decoding start)\n");*/
7625 vp9_loop_filter_frame_init(pbi
->seg_4lf
,
7626 pbi
->lfi
, pbi
->lf
, pbi
->default_filt_lvl
);
7628 /*pr_info("HEVC_DEC_STATUS_REG <= VP9_10B_DECODE_SLICE\n");*/
7629 WRITE_VREG(HEVC_DEC_STATUS_REG
, VP9_10B_DECODE_SLICE
);
7631 pr_info("Skip search next start code\n");
7632 cm
->prev_fb_idx
= INVALID_IDX
;
7633 /*skip, search next start code*/
7634 WRITE_VREG(HEVC_DEC_STATUS_REG
, VP9_10B_DECODE_SLICE
);
7636 pbi
->process_state
= PROC_STATE_DECODESLICE
;
7637 if (pbi
->mmu_enable
&& ((pbi
->double_write_mode
& 0x10) == 0)) {
7638 if (pbi
->last_put_idx
< pbi
->used_buf_num
) {
7639 struct RefCntBuffer_s
*frame_bufs
=
7640 cm
->buffer_pool
->frame_bufs
;
7641 int i
= pbi
->last_put_idx
;
7642 /*free not used buffers.*/
7643 if ((frame_bufs
[i
].ref_count
== 0) &&
7644 (frame_bufs
[i
].buf
.vf_ref
== 0) &&
7645 (frame_bufs
[i
].buf
.index
!= -1)) {
7646 decoder_mmu_box_free_idx(pbi
->mmu_box
, i
);
7648 pbi
->last_put_idx
= -1;
7654 static void fill_frame_info(struct VP9Decoder_s
*pbi
,
7655 struct PIC_BUFFER_CONFIG_s
*frame
,
7656 unsigned int framesize
,
7659 struct vframe_qos_s
*vframe_qos
= &pbi
->vframe_qos
;
7661 if (frame
->slice_type
== KEY_FRAME
)
7662 vframe_qos
->type
= 1;
7663 else if (frame
->slice_type
== INTER_FRAME
)
7664 vframe_qos
->type
= 2;
7666 #define SHOW_QOS_INFO
7668 vframe_qos
->size
= framesize
;
7669 vframe_qos
->pts
= pts
;
7670 #ifdef SHOW_QOS_INFO
7671 vp9_print(pbi
, 0, "slice:%d\n", frame
->slice_type
);
7673 vframe_qos
->max_mv
= frame
->max_mv
;
7674 vframe_qos
->avg_mv
= frame
->avg_mv
;
7675 vframe_qos
->min_mv
= frame
->min_mv
;
7676 #ifdef SHOW_QOS_INFO
7677 vp9_print(pbi
, 0, "mv: max:%d, avg:%d, min:%d\n",
7680 vframe_qos
->min_mv
);
7682 vframe_qos
->max_qp
= frame
->max_qp
;
7683 vframe_qos
->avg_qp
= frame
->avg_qp
;
7684 vframe_qos
->min_qp
= frame
->min_qp
;
7685 #ifdef SHOW_QOS_INFO
7686 vp9_print(pbi
, 0, "qp: max:%d, avg:%d, min:%d\n",
7689 vframe_qos
->min_qp
);
7691 vframe_qos
->max_skip
= frame
->max_skip
;
7692 vframe_qos
->avg_skip
= frame
->avg_skip
;
7693 vframe_qos
->min_skip
= frame
->min_skip
;
7694 #ifdef SHOW_QOS_INFO
7695 vp9_print(pbi
, 0, "skip: max:%d, avg:%d, min:%d\n",
7696 vframe_qos
->max_skip
,
7697 vframe_qos
->avg_skip
,
7698 vframe_qos
->min_skip
);
7702 if (pbi
->frameinfo_enable
)
7703 vdec_fill_frame_info(vframe_qos
, 1);
7706 /* only when we decoded one field or one frame,
7707 we can call this function to get qos info*/
7708 static void get_picture_qos_info(struct VP9Decoder_s
*pbi
)
7710 struct PIC_BUFFER_CONFIG_s
*frame
= &pbi
->cur_buf
->buf
;
7715 if (get_cpu_major_id() < AM_MESON_CPU_MAJOR_ID_G12A
) {
7717 unsigned char i
, j
, t
;
7720 data
= READ_VREG(HEVC_MV_INFO
);
7721 if (frame
->slice_type
== KEY_FRAME
)
7724 a
[1] = (data
>> 8) & 0xff;
7725 a
[2] = (data
>> 16) & 0xff;
7727 for (i
= 0; i
< 3; i
++) {
7728 for (j
= i
+1; j
< 3; j
++) {
7733 } else if (a
[j
] == a
[i
]) {
7741 frame
->max_mv
= a
[2];
7742 frame
->avg_mv
= a
[1];
7743 frame
->min_mv
= a
[0];
7745 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7746 "mv data %x a[0]= %x a[1]= %x a[2]= %x\n",
7747 data
, a
[0], a
[1], a
[2]);
7749 data
= READ_VREG(HEVC_QP_INFO
);
7751 a
[1] = (data
>> 8) & 0x3f;
7752 a
[2] = (data
>> 16) & 0x7f;
7754 for (i
= 0; i
< 3; i
++) {
7755 for (j
= i
+1; j
< 3; j
++) {
7760 } else if (a
[j
] == a
[i
]) {
7768 frame
->max_qp
= a
[2];
7769 frame
->avg_qp
= a
[1];
7770 frame
->min_qp
= a
[0];
7772 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7773 "qp data %x a[0]= %x a[1]= %x a[2]= %x\n",
7774 data
, a
[0], a
[1], a
[2]);
7776 data
= READ_VREG(HEVC_SKIP_INFO
);
7778 a
[1] = (data
>> 8) & 0x3f;
7779 a
[2] = (data
>> 16) & 0x7f;
7781 for (i
= 0; i
< 3; i
++) {
7782 for (j
= i
+1; j
< 3; j
++) {
7787 } else if (a
[j
] == a
[i
]) {
7795 frame
->max_skip
= a
[2];
7796 frame
->avg_skip
= a
[1];
7797 frame
->min_skip
= a
[0];
7799 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7800 "skip data %x a[0]= %x a[1]= %x a[2]= %x\n",
7801 data
, a
[0], a
[1], a
[2]);
7803 uint32_t blk88_y_count
;
7804 uint32_t blk88_c_count
;
7805 uint32_t blk22_mv_count
;
7815 uint64_t temp_value
;
7816 int pic_number
= frame
->decode_idx
;
7822 frame
->max_skip
= 0;
7823 frame
->avg_skip
= 0;
7824 frame
->min_skip
= 0;
7830 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
, "slice_type:%d, poc:%d\n",
7834 /* set rd_idx to 0 */
7835 WRITE_VREG(HEVC_PIC_QUALITY_CTRL
, 0);
7837 blk88_y_count
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
7838 if (blk88_y_count
== 0) {
7840 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7841 "[Picture %d Quality] NO Data yet.\n",
7844 /* reset all counts */
7845 WRITE_VREG(HEVC_PIC_QUALITY_CTRL
, (1<<8));
7849 rdata32
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
7851 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7852 "[Picture %d Quality] Y QP AVG : %d (%d/%d)\n",
7853 pic_number
, rdata32
/blk88_y_count
,
7854 rdata32
, blk88_y_count
);
7856 frame
->avg_qp
= rdata32
/blk88_y_count
;
7858 rdata32
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
7860 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7861 "[Picture %d Quality] Y intra rate : %d%c (%d)\n",
7862 pic_number
, rdata32
*100/blk88_y_count
,
7865 /* skipped_y_count */
7866 rdata32
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
7868 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7869 "[Picture %d Quality] Y skipped rate : %d%c (%d)\n",
7870 pic_number
, rdata32
*100/blk88_y_count
,
7873 frame
->avg_skip
= rdata32
*100/blk88_y_count
;
7874 /* coeff_non_zero_y_count */
7875 rdata32
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
7877 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7878 "[Picture %d Quality] Y ZERO_Coeff rate : %d%c (%d)\n",
7879 pic_number
, (100 - rdata32
*100/(blk88_y_count
*1)),
7883 blk88_c_count
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
7884 if (blk88_c_count
== 0) {
7885 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7886 "[Picture %d Quality] NO Data yet.\n",
7888 /* reset all counts */
7889 WRITE_VREG(HEVC_PIC_QUALITY_CTRL
, (1<<8));
7893 rdata32
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
7895 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7896 "[Picture %d Quality] C QP AVG : %d (%d/%d)\n",
7897 pic_number
, rdata32
/blk88_c_count
,
7898 rdata32
, blk88_c_count
);
7901 rdata32
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
7903 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7904 "[Picture %d Quality] C intra rate : %d%c (%d)\n",
7905 pic_number
, rdata32
*100/blk88_c_count
,
7908 /* skipped_cu_c_count */
7909 rdata32
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
7911 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7912 "[Picture %d Quality] C skipped rate : %d%c (%d)\n",
7913 pic_number
, rdata32
*100/blk88_c_count
,
7916 /* coeff_non_zero_c_count */
7917 rdata32
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
7919 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7920 "[Picture %d Quality] C ZERO_Coeff rate : %d%c (%d)\n",
7921 pic_number
, (100 - rdata32
*100/(blk88_c_count
*1)),
7924 /* 1'h0, qp_c_max[6:0], 1'h0, qp_c_min[6:0],
7925 1'h0, qp_y_max[6:0], 1'h0, qp_y_min[6:0] */
7926 rdata32
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
7928 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7929 "[Picture %d Quality] Y QP min : %d\n",
7930 pic_number
, (rdata32
>>0)&0xff);
7932 frame
->min_qp
= (rdata32
>>0)&0xff;
7934 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7935 "[Picture %d Quality] Y QP max : %d\n",
7936 pic_number
, (rdata32
>>8)&0xff);
7938 frame
->max_qp
= (rdata32
>>8)&0xff;
7940 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7941 "[Picture %d Quality] C QP min : %d\n",
7942 pic_number
, (rdata32
>>16)&0xff);
7943 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7944 "[Picture %d Quality] C QP max : %d\n",
7945 pic_number
, (rdata32
>>24)&0xff);
7947 /* blk22_mv_count */
7948 blk22_mv_count
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
7949 if (blk22_mv_count
== 0) {
7950 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7951 "[Picture %d Quality] NO MV Data yet.\n",
7953 /* reset all counts */
7954 WRITE_VREG(HEVC_PIC_QUALITY_CTRL
, (1<<8));
7957 /* mvy_L1_count[39:32], mvx_L1_count[39:32],
7958 mvy_L0_count[39:32], mvx_L0_count[39:32] */
7959 rdata32
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
7960 /* should all be 0x00 or 0xff */
7961 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7962 "[Picture %d Quality] MV AVG High Bits: 0x%X\n",
7963 pic_number
, rdata32
);
7965 mvx_L0_hi
= ((rdata32
>>0)&0xff);
7966 mvy_L0_hi
= ((rdata32
>>8)&0xff);
7967 mvx_L1_hi
= ((rdata32
>>16)&0xff);
7968 mvy_L1_hi
= ((rdata32
>>24)&0xff);
7970 /* mvx_L0_count[31:0] */
7971 rdata32_l
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
7972 temp_value
= mvx_L0_hi
;
7973 temp_value
= (temp_value
<< 32) | rdata32_l
;
7975 if (mvx_L0_hi
& 0x80)
7976 value
= 0xFFFFFFF000000000 | temp_value
;
7980 value
= div_s64(value
, blk22_mv_count
);
7982 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
7983 "[Picture %d Quality] MVX_L0 AVG : %d (%lld/%d)\n",
7984 pic_number
, (int)value
,
7985 value
, blk22_mv_count
);
7987 frame
->avg_mv
= value
;
7989 /* mvy_L0_count[31:0] */
7990 rdata32_l
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
7991 temp_value
= mvy_L0_hi
;
7992 temp_value
= (temp_value
<< 32) | rdata32_l
;
7994 if (mvy_L0_hi
& 0x80)
7995 value
= 0xFFFFFFF000000000 | temp_value
;
7999 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
8000 "[Picture %d Quality] MVY_L0 AVG : %d (%lld/%d)\n",
8001 pic_number
, rdata32_l
/blk22_mv_count
,
8002 value
, blk22_mv_count
);
8004 /* mvx_L1_count[31:0] */
8005 rdata32_l
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
8006 temp_value
= mvx_L1_hi
;
8007 temp_value
= (temp_value
<< 32) | rdata32_l
;
8008 if (mvx_L1_hi
& 0x80)
8009 value
= 0xFFFFFFF000000000 | temp_value
;
8013 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
8014 "[Picture %d Quality] MVX_L1 AVG : %d (%lld/%d)\n",
8015 pic_number
, rdata32_l
/blk22_mv_count
,
8016 value
, blk22_mv_count
);
8018 /* mvy_L1_count[31:0] */
8019 rdata32_l
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
8020 temp_value
= mvy_L1_hi
;
8021 temp_value
= (temp_value
<< 32) | rdata32_l
;
8022 if (mvy_L1_hi
& 0x80)
8023 value
= 0xFFFFFFF000000000 | temp_value
;
8027 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
8028 "[Picture %d Quality] MVY_L1 AVG : %d (%lld/%d)\n",
8029 pic_number
, rdata32_l
/blk22_mv_count
,
8030 value
, blk22_mv_count
);
8032 /* {mvx_L0_max, mvx_L0_min} // format : {sign, abs[14:0]} */
8033 rdata32
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
8034 mv_hi
= (rdata32
>>16)&0xffff;
8036 mv_hi
= 0x8000 - mv_hi
;
8038 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
8039 "[Picture %d Quality] MVX_L0 MAX : %d\n",
8042 frame
->max_mv
= mv_hi
;
8044 mv_lo
= (rdata32
>>0)&0xffff;
8046 mv_lo
= 0x8000 - mv_lo
;
8048 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
8049 "[Picture %d Quality] MVX_L0 MIN : %d\n",
8052 frame
->min_mv
= mv_lo
;
8054 /* {mvy_L0_max, mvy_L0_min} */
8055 rdata32
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
8056 mv_hi
= (rdata32
>>16)&0xffff;
8058 mv_hi
= 0x8000 - mv_hi
;
8060 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
8061 "[Picture %d Quality] MVY_L0 MAX : %d\n",
8064 mv_lo
= (rdata32
>>0)&0xffff;
8066 mv_lo
= 0x8000 - mv_lo
;
8068 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
8069 "[Picture %d Quality] MVY_L0 MIN : %d\n",
8072 /* {mvx_L1_max, mvx_L1_min} */
8073 rdata32
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
8074 mv_hi
= (rdata32
>>16)&0xffff;
8076 mv_hi
= 0x8000 - mv_hi
;
8078 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
8079 "[Picture %d Quality] MVX_L1 MAX : %d\n",
8082 mv_lo
= (rdata32
>>0)&0xffff;
8084 mv_lo
= 0x8000 - mv_lo
;
8086 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
8087 "[Picture %d Quality] MVX_L1 MIN : %d\n",
8090 /* {mvy_L1_max, mvy_L1_min} */
8091 rdata32
= READ_VREG(HEVC_PIC_QUALITY_DATA
);
8092 mv_hi
= (rdata32
>>16)&0xffff;
8094 mv_hi
= 0x8000 - mv_hi
;
8096 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
8097 "[Picture %d Quality] MVY_L1 MAX : %d\n",
8100 mv_lo
= (rdata32
>>0)&0xffff;
8102 mv_lo
= 0x8000 - mv_lo
;
8104 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
8105 "[Picture %d Quality] MVY_L1 MIN : %d\n",
8108 rdata32
= READ_VREG(HEVC_PIC_QUALITY_CTRL
);
8110 vp9_print(pbi
, VP9_DEBUG_QOS_INFO
,
8111 "[Picture %d Quality] After Read : VDEC_PIC_QUALITY_CTRL : 0x%x\n",
8112 pic_number
, rdata32
);
8114 /* reset all counts */
8115 WRITE_VREG(HEVC_PIC_QUALITY_CTRL
, (1<<8));
8119 static irqreturn_t
vvp9_isr_thread_fn(int irq
, void *data
)
8121 struct VP9Decoder_s
*pbi
= (struct VP9Decoder_s
*)data
;
8122 unsigned int dec_status
= pbi
->dec_status
;
8125 /*if (pbi->wait_buf)
8126 * pr_info("set wait_buf to 0\r\n");
8131 #ifdef MULTI_INSTANCE_SUPPORT
8132 #ifdef SUPPORT_FB_DECODING
8133 #ifdef FB_DECODING_TEST_SCHEDULE
8134 if (pbi
->s1_test_cmd
== TEST_SET_PIC_DONE
)
8135 dec_status
= HEVC_DECPIC_DATA_DONE
;
8136 else if (pbi
->s1_test_cmd
== TEST_SET_S2_DONE
8137 && dec_status
== HEVC_DECPIC_DATA_DONE
)
8138 dec_status
= HEVC_S2_DECODING_DONE
;
8139 pbi
->s1_test_cmd
= TEST_SET_NONE
;
8141 /*if (irq != VDEC_IRQ_0)
8142 dec_status = HEVC_S2_DECODING_DONE;*/
8144 if (dec_status
== HEVC_S2_DECODING_DONE
) {
8145 pbi
->dec_result
= DEC_RESULT_DONE
;
8146 vdec_schedule_work(&pbi
->work
);
8147 #ifdef FB_DECODING_TEST_SCHEDULE
8149 pbi
->dec_s1_result
= DEC_S1_RESULT_DONE
;
8150 vdec_schedule_work(&pbi
->s1_work
);
8154 if ((dec_status
== HEVC_NAL_DECODE_DONE
) ||
8155 (dec_status
== HEVC_SEARCH_BUFEMPTY
) ||
8156 (dec_status
== HEVC_DECODE_BUFEMPTY
)
8158 if (pbi
->m_ins_flag
) {
8159 reset_process_time(pbi
);
8160 if (!vdec_frame_based(hw_to_vdec(pbi
)))
8161 dec_again_process(pbi
);
8163 pbi
->dec_result
= DEC_RESULT_GET_DATA
;
8164 vdec_schedule_work(&pbi
->work
);
8167 pbi
->process_busy
= 0;
8169 } else if (dec_status
== HEVC_DECPIC_DATA_DONE
) {
8170 if (pbi
->m_ins_flag
) {
8171 get_picture_qos_info(pbi
);
8172 #ifdef SUPPORT_FB_DECODING
8173 if (pbi
->used_stage_buf_num
> 0) {
8174 reset_process_time(pbi
);
8176 trigger_schedule(pbi
);
8177 #ifdef FB_DECODING_TEST_SCHEDULE
8178 pbi
->s1_test_cmd
= TEST_SET_S2_DONE
;
8181 pbi
->dec_s1_result
= DEC_S1_RESULT_DONE
;
8182 vdec_schedule_work(&pbi
->s1_work
);
8187 reset_process_time(pbi
);
8188 if (pbi
->vf_pre_count
== 0 || pbi
->low_latency_flag
)
8189 vp9_bufmgr_postproc(pbi
);
8191 pbi
->dec_result
= DEC_RESULT_DONE
;
8193 if (mcrcc_cache_alg_flag
)
8195 vdec_schedule_work(&pbi
->work
);
8198 if (pbi
->low_latency_flag
) {
8199 vp9_bufmgr_postproc(pbi
);
8200 WRITE_VREG(HEVC_DEC_STATUS_REG
, HEVC_ACTION_DONE
);
8201 #ifdef CONFIG_AMLOGIC_MEDIA_MULTI_DEC
8202 vdec_profile(hw_to_vdec(pbi
), VDEC_PROFILE_EVENT_CB
);
8203 if (debug
& PRINT_FLAG_VDEC_DETAIL
)
8204 pr_info("%s VP9 frame done \n", __func__
);
8209 pbi
->process_busy
= 0;
8214 if (dec_status
== VP9_EOS
) {
8215 #ifdef MULTI_INSTANCE_SUPPORT
8216 if (pbi
->m_ins_flag
)
8217 reset_process_time(pbi
);
8220 pr_info("VP9_EOS, flush buffer\r\n");
8222 vp9_bufmgr_postproc(pbi
);
8224 pr_info("send VP9_10B_DISCARD_NAL\r\n");
8225 WRITE_VREG(HEVC_DEC_STATUS_REG
, VP9_10B_DISCARD_NAL
);
8226 pbi
->process_busy
= 0;
8227 #ifdef MULTI_INSTANCE_SUPPORT
8228 if (pbi
->m_ins_flag
) {
8229 pbi
->dec_result
= DEC_RESULT_DONE
;
8231 vdec_schedule_work(&pbi
->work
);
8235 } else if (dec_status
== HEVC_DECODE_OVER_SIZE
) {
8236 pr_info("vp9 decode oversize !!\n");
8237 debug
|= (VP9_DEBUG_DIS_LOC_ERROR_PROC
|
8238 VP9_DEBUG_DIS_SYS_ERROR_PROC
);
8239 pbi
->fatal_error
|= DECODER_FATAL_ERROR_SIZE_OVERFLOW
;
8240 #ifdef MULTI_INSTANCE_SUPPORT
8241 if (pbi
->m_ins_flag
)
8242 reset_process_time(pbi
);
8247 if (dec_status
!= VP9_HEAD_PARSER_DONE
) {
8248 pbi
->process_busy
= 0;
8253 #ifdef MULTI_INSTANCE_SUPPORT
8254 #ifdef CONFIG_AMLOGIC_MEDIA_MULTI_DEC
8255 if (pbi
->m_ins_flag
==0 && pbi
->low_latency_flag
) {
8256 vdec_profile(hw_to_vdec(pbi
), VDEC_PROFILE_EVENT_RUN
);
8257 if (debug
& PRINT_FLAG_VDEC_DETAIL
)
8258 pr_info("%s VP9 frame header found \n", __func__
);
8261 if (pbi
->m_ins_flag
)
8262 reset_process_time(pbi
);
8264 if (pbi
->process_state
!= PROC_STATE_SENDAGAIN
8265 #ifdef SUPPORT_FB_DECODING
8266 && pbi
->used_stage_buf_num
== 0
8269 if (pbi
->mmu_enable
)
8270 vp9_recycle_mmu_buf_tail(pbi
);
8273 if (pbi
->frame_count
> 0)
8274 vp9_bufmgr_postproc(pbi
);
8277 if (debug
& VP9_DEBUG_SEND_PARAM_WITH_REG
) {
8278 get_rpm_param(&vp9_param
);
8280 #ifdef SUPPORT_FB_DECODING
8281 if (pbi
->used_stage_buf_num
> 0) {
8282 reset_process_time(pbi
);
8286 &pbi
->s1_mv_buf_index
,
8287 &pbi
->s1_mpred_mv_wr_start_addr
8290 "%s: Error get_mv_buf fail\n",
8294 if (pbi
->s1_buf
== NULL
) {
8296 "%s: Error get_s1_buf fail\n",
8298 pbi
->process_busy
= 0;
8302 for (i
= 0; i
< (RPM_END
- RPM_BEGIN
); i
+= 4) {
8304 for (ii
= 0; ii
< 4; ii
++) {
8305 pbi
->s1_buf
->rpm
[i
+ 3 - ii
] =
8306 pbi
->rpm_ptr
[i
+ 3 - ii
];
8307 pbi
->s1_param
.l
.data
[i
+ ii
] =
8308 pbi
->rpm_ptr
[i
+ 3 - ii
];
8313 #ifdef FB_DECODING_TEST_SCHEDULE
8314 pbi
->dec_s1_result
=
8315 DEC_S1_RESULT_TEST_TRIGGER_DONE
;
8316 vdec_schedule_work(&pbi
->s1_work
);
8318 WRITE_VREG(HEVC_ASSIST_FB_MMU_MAP_ADDR
,
8319 pbi
->stage_mmu_map_phy_addr
+
8320 pbi
->s1_buf
->index
* STAGE_MMU_MAP_SIZE
);
8322 start_s1_decoding(pbi
);
8324 start_process_time(pbi
);
8325 pbi
->process_busy
= 0;
8330 for (i
= 0; i
< (RPM_END
- RPM_BEGIN
); i
+= 4) {
8332 for (ii
= 0; ii
< 4; ii
++)
8333 vp9_param
.l
.data
[i
+ ii
] =
8334 pbi
->rpm_ptr
[i
+ 3 - ii
];
8339 if (pbi
->is_used_v4l
) {
8340 struct aml_vcodec_ctx
*ctx
=
8341 (struct aml_vcodec_ctx
*)(pbi
->v4l2_ctx
);
8343 pbi
->frame_width
= vp9_param
.p
.width
;
8344 pbi
->frame_height
= vp9_param
.p
.height
;
8345 if (ctx
->param_sets_from_ucode
&& !pbi
->v4l_params_parsed
) {
8346 struct aml_vdec_ps_infos ps
;
8348 ps
.visible_width
= pbi
->frame_width
;
8349 ps
.visible_height
= pbi
->frame_height
;
8350 ps
.coded_width
= ALIGN(pbi
->frame_width
, 32);
8351 ps
.coded_height
= ALIGN(pbi
->frame_height
, 32);
8352 ps
.dpb_size
= pbi
->used_buf_num
;
8353 pbi
->v4l_params_parsed
= true;
8354 vdec_v4l_set_ps_infos(ctx
, &ps
);
8358 if (pbi
->is_used_v4l
) {
8359 pbi
->dec_result
= DEC_V4L2_CONTINUE_DECODING
;
8360 vdec_schedule_work(&pbi
->work
);
8362 continue_decoding(pbi
);
8363 pbi
->postproc_done
= 0;
8364 pbi
->process_busy
= 0;
8367 #ifdef MULTI_INSTANCE_SUPPORT
8368 if (pbi
->m_ins_flag
)
8369 start_process_time(pbi
);
8375 static irqreturn_t
vvp9_isr(int irq
, void *data
)
8378 unsigned int dec_status
;
8379 struct VP9Decoder_s
*pbi
= (struct VP9Decoder_s
*)data
;
8380 unsigned int adapt_prob_status
;
8381 struct VP9_Common_s
*const cm
= &pbi
->common
;
8384 WRITE_VREG(HEVC_ASSIST_MBOX0_CLR_REG
, 1);
8386 dec_status
= READ_VREG(HEVC_DEC_STATUS_REG
);
8387 adapt_prob_status
= READ_VREG(VP9_ADAPT_PROB_REG
);
8390 if (pbi
->init_flag
== 0)
8392 if (pbi
->process_busy
)/*on process.*/
8394 pbi
->dec_status
= dec_status
;
8395 pbi
->process_busy
= 1;
8396 if (debug
& VP9_DEBUG_BUFMGR
)
8397 pr_info("vp9 isr (%d) dec status = 0x%x, lcu 0x%x shiftbyte 0x%x (%x %x lev %x, wr %x, rd %x)\n",
8399 dec_status
, READ_VREG(HEVC_PARSER_LCU_START
),
8400 READ_VREG(HEVC_SHIFT_BYTE_COUNT
),
8401 READ_VREG(HEVC_STREAM_START_ADDR
),
8402 READ_VREG(HEVC_STREAM_END_ADDR
),
8403 READ_VREG(HEVC_STREAM_LEVEL
),
8404 READ_VREG(HEVC_STREAM_WR_PTR
),
8405 READ_VREG(HEVC_STREAM_RD_PTR
)
8407 #ifdef SUPPORT_FB_DECODING
8408 /*if (irq != VDEC_IRQ_0)
8409 return IRQ_WAKE_THREAD;*/
8412 debug_tag
= READ_HREG(DEBUG_REG1
);
8413 if (debug_tag
& 0x10000) {
8414 pr_info("LMEM<tag %x>:\n", READ_HREG(DEBUG_REG1
));
8415 for (i
= 0; i
< 0x400; i
+= 4) {
8418 pr_info("%03x: ", i
);
8419 for (ii
= 0; ii
< 4; ii
++) {
8421 pbi
->lmem_ptr
[i
+ 3 - ii
]);
8423 if (((i
+ ii
) & 0xf) == 0)
8427 if ((udebug_pause_pos
== (debug_tag
& 0xffff)) &&
8428 (udebug_pause_decode_idx
== 0 ||
8429 udebug_pause_decode_idx
== pbi
->slice_idx
) &&
8430 (udebug_pause_val
== 0 ||
8431 udebug_pause_val
== READ_HREG(DEBUG_REG2
)))
8432 pbi
->ucode_pause_pos
= udebug_pause_pos
;
8433 else if (debug_tag
& 0x20000)
8434 pbi
->ucode_pause_pos
= 0xffffffff;
8435 if (pbi
->ucode_pause_pos
)
8436 reset_process_time(pbi
);
8438 WRITE_HREG(DEBUG_REG1
, 0);
8439 } else if (debug_tag
!= 0) {
8441 "dbg%x: %x lcu %x\n", READ_HREG(DEBUG_REG1
),
8442 READ_HREG(DEBUG_REG2
),
8443 READ_VREG(HEVC_PARSER_LCU_START
));
8444 if ((udebug_pause_pos
== (debug_tag
& 0xffff)) &&
8445 (udebug_pause_decode_idx
== 0 ||
8446 udebug_pause_decode_idx
== pbi
->slice_idx
) &&
8447 (udebug_pause_val
== 0 ||
8448 udebug_pause_val
== READ_HREG(DEBUG_REG2
)))
8449 pbi
->ucode_pause_pos
= udebug_pause_pos
;
8450 if (pbi
->ucode_pause_pos
)
8451 reset_process_time(pbi
);
8453 WRITE_HREG(DEBUG_REG1
, 0);
8454 pbi
->process_busy
= 0;
8458 #ifdef MULTI_INSTANCE_SUPPORT
8459 if (!pbi
->m_ins_flag
) {
8461 if (pbi
->error_flag
== 1) {
8462 pbi
->error_flag
= 2;
8463 pbi
->process_busy
= 0;
8465 } else if (pbi
->error_flag
== 3) {
8466 pbi
->process_busy
= 0;
8470 if (get_free_buf_count(pbi
) <= 0) {
8472 if (pbi->wait_buf == 0)
8473 pr_info("set wait_buf to 1\r\n");
8476 pbi
->process_busy
= 0;
8479 #ifdef MULTI_INSTANCE_SUPPORT
8482 if ((adapt_prob_status
& 0xff) == 0xfd) {
8483 /*VP9_REQ_ADAPT_PROB*/
8484 int pre_fc
= (cm
->frame_type
== KEY_FRAME
) ? 1 : 0;
8485 uint8_t *prev_prob_b
=
8486 ((uint8_t *)pbi
->prob_buffer_addr
) +
8487 ((adapt_prob_status
>> 8) * 0x1000);
8488 uint8_t *cur_prob_b
=
8489 ((uint8_t *)pbi
->prob_buffer_addr
) + 0x4000;
8490 uint8_t *count_b
= (uint8_t *)pbi
->count_buffer_addr
;
8491 #ifdef MULTI_INSTANCE_SUPPORT
8492 if (pbi
->m_ins_flag
)
8493 reset_process_time(pbi
);
8495 adapt_coef_probs(pbi
->pic_count
,
8496 (cm
->last_frame_type
== KEY_FRAME
),
8497 pre_fc
, (adapt_prob_status
>> 8),
8498 (unsigned int *)prev_prob_b
,
8499 (unsigned int *)cur_prob_b
, (unsigned int *)count_b
);
8501 memcpy(prev_prob_b
, cur_prob_b
, PROB_SIZE
);
8502 WRITE_VREG(VP9_ADAPT_PROB_REG
, 0);
8503 pbi
->pic_count
+= 1;
8504 #ifdef MULTI_INSTANCE_SUPPORT
8505 if (pbi
->m_ins_flag
)
8506 start_process_time(pbi
);
8509 /*return IRQ_HANDLED;*/
8511 return IRQ_WAKE_THREAD
;
8514 static void vp9_set_clk(struct work_struct
*work
)
8516 struct VP9Decoder_s
*pbi
= container_of(work
,
8517 struct VP9Decoder_s
, set_clk_work
);
8518 int fps
= 96000 / pbi
->frame_dur
;
8520 if (hevc_source_changed(VFORMAT_VP9
,
8521 frame_width
, frame_height
, fps
) > 0)
8522 pbi
->saved_resolution
= frame_width
*
8526 static void vvp9_put_timer_func(unsigned long arg
)
8528 struct VP9Decoder_s
*pbi
= (struct VP9Decoder_s
*)arg
;
8529 struct timer_list
*timer
= &pbi
->timer
;
8531 unsigned int buf_level
;
8533 enum receviver_start_e state
= RECEIVER_INACTIVE
;
8535 if (pbi
->m_ins_flag
) {
8536 if (hw_to_vdec(pbi
)->next_status
8537 == VDEC_STATUS_DISCONNECTED
) {
8538 #ifdef SUPPORT_FB_DECODING
8542 pbi
->dec_s1_result
= DEC_S1_RESULT_FORCE_EXIT
;
8543 vdec_schedule_work(&pbi
->s1_work
);
8545 pbi
->dec_result
= DEC_RESULT_FORCE_EXIT
;
8546 vdec_schedule_work(&pbi
->work
);
8548 "vdec requested to be disconnected\n");
8552 if (pbi
->init_flag
== 0) {
8553 if (pbi
->stat
& STAT_TIMER_ARM
) {
8554 timer
->expires
= jiffies
+ PUT_INTERVAL
;
8555 add_timer(&pbi
->timer
);
8559 if (pbi
->m_ins_flag
== 0) {
8560 if (vf_get_receiver(pbi
->provider_name
)) {
8562 vf_notify_receiver(pbi
->provider_name
,
8563 VFRAME_EVENT_PROVIDER_QUREY_STATE
,
8565 if ((state
== RECEIVER_STATE_NULL
)
8566 || (state
== RECEIVER_STATE_NONE
))
8567 state
= RECEIVER_INACTIVE
;
8569 state
= RECEIVER_INACTIVE
;
8571 empty_flag
= (READ_VREG(HEVC_PARSER_INT_STATUS
) >> 6) & 0x1;
8572 /* error watchdog */
8573 if (empty_flag
== 0) {
8574 /* decoder has input */
8575 if ((debug
& VP9_DEBUG_DIS_LOC_ERROR_PROC
) == 0) {
8577 buf_level
= READ_VREG(HEVC_STREAM_LEVEL
);
8578 /* receiver has no buffer to recycle */
8579 if ((state
== RECEIVER_INACTIVE
) &&
8580 (kfifo_is_empty(&pbi
->display_q
) &&
8584 (HEVC_ASSIST_MBOX0_IRQ_REG
,
8589 if ((debug
& VP9_DEBUG_DIS_SYS_ERROR_PROC
) == 0) {
8590 /* receiver has no buffer to recycle */
8591 /*if ((state == RECEIVER_INACTIVE) &&
8592 * (kfifo_is_empty(&pbi->display_q))) {
8593 *pr_info("vp9 something error,need reset\n");
8599 #ifdef MULTI_INSTANCE_SUPPORT
8602 (decode_timeout_val
> 0) &&
8603 (pbi
->start_process_time
> 0) &&
8604 ((1000 * (jiffies
- pbi
->start_process_time
) / HZ
)
8605 > decode_timeout_val
)
8607 int current_lcu_idx
=
8608 READ_VREG(HEVC_PARSER_LCU_START
)
8610 if (pbi
->last_lcu_idx
== current_lcu_idx
) {
8611 if (pbi
->decode_timeout_count
> 0)
8612 pbi
->decode_timeout_count
--;
8613 if (pbi
->decode_timeout_count
== 0) {
8614 if (input_frame_based(
8616 (READ_VREG(HEVC_STREAM_LEVEL
) > 0x200))
8617 timeout_process(pbi
);
8620 "timeout & empty, again\n");
8621 dec_again_process(pbi
);
8625 start_process_time(pbi
);
8626 pbi
->last_lcu_idx
= current_lcu_idx
;
8632 if ((pbi
->ucode_pause_pos
!= 0) &&
8633 (pbi
->ucode_pause_pos
!= 0xffffffff) &&
8634 udebug_pause_pos
!= pbi
->ucode_pause_pos
) {
8635 pbi
->ucode_pause_pos
= 0;
8636 WRITE_HREG(DEBUG_REG1
, 0);
8638 #ifdef MULTI_INSTANCE_SUPPORT
8639 if (debug
& VP9_DEBUG_FORCE_SEND_AGAIN
) {
8641 "Force Send Again\r\n");
8642 debug
&= ~VP9_DEBUG_FORCE_SEND_AGAIN
;
8643 reset_process_time(pbi
);
8644 pbi
->dec_result
= DEC_RESULT_AGAIN
;
8645 if (pbi
->process_state
==
8646 PROC_STATE_DECODESLICE
) {
8647 if (pbi
->mmu_enable
)
8648 vp9_recycle_mmu_buf(pbi
);
8649 pbi
->process_state
=
8650 PROC_STATE_SENDAGAIN
;
8654 vdec_schedule_work(&pbi
->work
);
8657 if (debug
& VP9_DEBUG_DUMP_DATA
) {
8658 debug
&= ~VP9_DEBUG_DUMP_DATA
;
8660 "%s: chunk size 0x%x off 0x%x sum 0x%x\n",
8664 get_data_check_sum(pbi
, pbi
->chunk
->size
)
8666 dump_data(pbi
, pbi
->chunk
->size
);
8669 if (debug
& VP9_DEBUG_DUMP_PIC_LIST
) {
8671 debug
&= ~VP9_DEBUG_DUMP_PIC_LIST
;
8673 if (debug
& VP9_DEBUG_TRIG_SLICE_SEGMENT_PROC
) {
8674 WRITE_VREG(HEVC_ASSIST_MBOX0_IRQ_REG
, 0x1);
8675 debug
&= ~VP9_DEBUG_TRIG_SLICE_SEGMENT_PROC
;
8677 /*if (debug & VP9_DEBUG_HW_RESET) {
8682 WRITE_VREG(radr
, rval
);
8683 pr_info("WRITE_VREG(%x,%x)\n", radr
, rval
);
8685 pr_info("READ_VREG(%x)=%x\n", radr
, READ_VREG(radr
));
8689 if (pop_shorts
!= 0) {
8693 pr_info("pop stream 0x%x shorts\r\n", pop_shorts
);
8694 for (i
= 0; i
< pop_shorts
; i
++) {
8696 (READ_HREG(HEVC_SHIFTED_DATA
) >> 16);
8697 WRITE_HREG(HEVC_SHIFT_COMMAND
,
8700 pr_info("%04x:", i
);
8701 pr_info("%04x ", data
);
8702 if (((i
+ 1) & 0xf) == 0)
8706 pr_info("\r\nsum = %x\r\n", sum
);
8713 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_GXBB
&&
8714 get_double_write_mode(pbi
) == 0) {
8716 READ_VCBUS_REG(AFBC_BODY_BADDR
) << 4;
8718 struct canvas_s cur_canvas
;
8720 canvas_read((READ_VCBUS_REG(VD1_IF0_CANVAS0
)
8721 & 0xff), &cur_canvas
);
8722 disp_laddr
= cur_canvas
.addr
;
8724 pr_info("current displayed buffer address %x\r\n",
8729 /*don't changed at start.*/
8730 if (pbi
->get_frame_dur
&& pbi
->show_frame_num
> 60 &&
8731 pbi
->frame_dur
> 0 && pbi
->saved_resolution
!=
8732 frame_width
* frame_height
*
8733 (96000 / pbi
->frame_dur
))
8734 vdec_schedule_work(&pbi
->set_clk_work
);
8736 timer
->expires
= jiffies
+ PUT_INTERVAL
;
8741 int vvp9_dec_status(struct vdec_s
*vdec
, struct vdec_info
*vstatus
)
8743 struct VP9Decoder_s
*vp9
=
8744 (struct VP9Decoder_s
*)vdec
->private;
8749 vstatus
->frame_width
= frame_width
;
8750 vstatus
->frame_height
= frame_height
;
8751 if (vp9
->frame_dur
!= 0)
8752 vstatus
->frame_rate
= 96000 / vp9
->frame_dur
;
8754 vstatus
->frame_rate
= -1;
8755 vstatus
->error_count
= 0;
8756 vstatus
->status
= vp9
->stat
| vp9
->fatal_error
;
8757 vstatus
->frame_dur
= vp9
->frame_dur
;
8758 #ifndef CONFIG_AMLOGIC_MEDIA_MULTI_DEC
8759 vstatus
->bit_rate
= gvs
->bit_rate
;
8760 vstatus
->frame_data
= gvs
->frame_data
;
8761 vstatus
->total_data
= gvs
->total_data
;
8762 vstatus
->frame_count
= gvs
->frame_count
;
8763 vstatus
->error_frame_count
= gvs
->error_frame_count
;
8764 vstatus
->drop_frame_count
= gvs
->drop_frame_count
;
8765 vstatus
->total_data
= gvs
->total_data
;
8766 vstatus
->samp_cnt
= gvs
->samp_cnt
;
8767 vstatus
->offset
= gvs
->offset
;
8768 snprintf(vstatus
->vdec_name
, sizeof(vstatus
->vdec_name
),
8774 int vvp9_set_isreset(struct vdec_s
*vdec
, int isreset
)
8781 static void VP9_DECODE_INIT(void)
8783 /* enable vp9 clocks */
8784 WRITE_VREG(DOS_GCLK_EN3
, 0xffffffff);
8785 /* *************************************************************** */
8787 /* *************************************************************** */
8789 WRITE_VREG(AO_RTI_GEN_PWR_SLEEP0
,
8790 READ_VREG(AO_RTI_GEN_PWR_SLEEP0
) & (~(0x3 << 6)));
8791 WRITE_VREG(DOS_MEM_PD_HEVC
, 0x0);
8792 WRITE_VREG(DOS_SW_RESET3
, READ_VREG(DOS_SW_RESET3
) | (0x3ffff << 2));
8793 WRITE_VREG(DOS_SW_RESET3
, READ_VREG(DOS_SW_RESET3
) & (~(0x3ffff << 2)));
8794 /* remove isolations */
8795 WRITE_VREG(AO_RTI_GEN_PWR_ISO0
,
8796 READ_VREG(AO_RTI_GEN_PWR_ISO0
) & (~(0x3 << 10)));
8801 static void vvp9_prot_init(struct VP9Decoder_s
*pbi
, u32 mask
)
8803 unsigned int data32
;
8804 /* VP9_DECODE_INIT(); */
8805 vp9_config_work_space_hw(pbi
, mask
);
8806 if (mask
& HW_MASK_BACK
)
8807 init_pic_list_hw(pbi
);
8809 vp9_init_decoder_hw(pbi
, mask
);
8811 #ifdef VP9_LPF_LVL_UPDATE
8812 if (mask
& HW_MASK_BACK
)
8813 vp9_loop_filter_init(pbi
);
8816 if ((mask
& HW_MASK_FRONT
) == 0)
8819 if (debug
& VP9_DEBUG_BUFMGR_MORE
)
8820 pr_info("%s\n", __func__
);
8821 data32
= READ_VREG(HEVC_STREAM_CONTROL
);
8823 (1 << 0)/*stream_fetch_enable*/
8825 WRITE_VREG(HEVC_STREAM_CONTROL
, data32
);
8827 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_G12A
) {
8828 if (debug
& VP9_DEBUG_BUFMGR
)
8829 pr_info("[test.c] Config STREAM_FIFO_CTL\n");
8830 data32
= READ_VREG(HEVC_STREAM_FIFO_CTL
);
8832 (1 << 29) // stream_fifo_hole
8834 WRITE_VREG(HEVC_STREAM_FIFO_CTL
, data32
);
8837 data32
= READ_VREG(HEVC_SHIFT_STARTCODE
);
8838 if (data32
!= 0x00000100) {
8839 pr_info("vp9 prot init error %d\n", __LINE__
);
8842 data32
= READ_VREG(HEVC_SHIFT_EMULATECODE
);
8843 if (data32
!= 0x00000300) {
8844 pr_info("vp9 prot init error %d\n", __LINE__
);
8847 WRITE_VREG(HEVC_SHIFT_STARTCODE
, 0x12345678);
8848 WRITE_VREG(HEVC_SHIFT_EMULATECODE
, 0x9abcdef0);
8849 data32
= READ_VREG(HEVC_SHIFT_STARTCODE
);
8850 if (data32
!= 0x12345678) {
8851 pr_info("vp9 prot init error %d\n", __LINE__
);
8854 data32
= READ_VREG(HEVC_SHIFT_EMULATECODE
);
8855 if (data32
!= 0x9abcdef0) {
8856 pr_info("vp9 prot init error %d\n", __LINE__
);
8860 WRITE_VREG(HEVC_SHIFT_STARTCODE
, 0x000000001);
8861 WRITE_VREG(HEVC_SHIFT_EMULATECODE
, 0x00000300);
8866 WRITE_VREG(HEVC_WAIT_FLAG
, 1);
8868 /* WRITE_VREG(HEVC_MPSR, 1); */
8870 /* clear mailbox interrupt */
8871 WRITE_VREG(HEVC_ASSIST_MBOX0_CLR_REG
, 1);
8873 /* enable mailbox interrupt */
8874 WRITE_VREG(HEVC_ASSIST_MBOX0_MASK
, 1);
8876 /* disable PSCALE for hardware sharing */
8877 WRITE_VREG(HEVC_PSCALE_CTRL
, 0);
8879 WRITE_VREG(DEBUG_REG1
, 0x0);
8880 /*check vps/sps/pps/i-slice in ucode*/
8881 WRITE_VREG(NAL_SEARCH_CTL
, 0x8);
8883 WRITE_VREG(DECODE_STOP_POS
, udebug_flag
);
8884 #ifdef SUPPORT_FB_DECODING
8885 #ifndef FB_DECODING_TEST_SCHEDULE
8886 if (pbi
->used_stage_buf_num
> 0) {
8887 if (mask
& HW_MASK_FRONT
) {
8889 HEVC_ASSIST_HED_FB_W_CTL
);
8891 (1 << 0) /*hed_fb_wr_en*/
8893 WRITE_VREG(HEVC_ASSIST_HED_FB_W_CTL
,
8896 if (mask
& HW_MASK_BACK
) {
8898 HEVC_ASSIST_HED_FB_R_CTL
);
8899 while (data32
& (1 << 7)) {
8902 HEVC_ASSIST_HED_FB_R_CTL
);
8904 data32
&= (~(0x1 << 0));
8905 /*hed_fb_rd_addr_auto_rd*/
8906 data32
&= (~(0x1 << 1));
8907 /*rd_id = 0, hed_rd_map_auto_halt_num,
8908 after wr 2 ready, then start reading*/
8909 data32
|= (0x2 << 16);
8910 WRITE_VREG(HEVC_ASSIST_HED_FB_R_CTL
,
8913 data32
|= (0x1 << 11); /*hed_rd_map_auto_halt_en*/
8914 data32
|= (0x1 << 1); /*hed_fb_rd_addr_auto_rd*/
8915 data32
|= (0x1 << 0); /*hed_fb_rd_en*/
8916 WRITE_VREG(HEVC_ASSIST_HED_FB_R_CTL
,
8925 static int vvp9_local_init(struct VP9Decoder_s
*pbi
)
8930 if (alloc_lf_buf(pbi
) < 0)
8933 pbi
->gvs
= vzalloc(sizeof(struct vdec_info
));
8934 if (NULL
== pbi
->gvs
) {
8935 pr_info("the struct of vdec status malloc failed.\n");
8939 pbi
->pts_missed
= 0;
8942 pbi
->new_frame_displayed
= 0;
8943 pbi
->last_put_idx
= -1;
8944 pbi
->saved_resolution
= 0;
8945 pbi
->get_frame_dur
= false;
8946 on_no_keyframe_skiped
= 0;
8947 pbi
->duration_from_pts_done
= 0;
8948 pbi
->vp9_first_pts_ready
= 0;
8949 pbi
->frame_cnt_window
= 0;
8950 width
= pbi
->vvp9_amstream_dec_info
.width
;
8951 height
= pbi
->vvp9_amstream_dec_info
.height
;
8953 (pbi
->vvp9_amstream_dec_info
.rate
==
8954 0) ? 3200 : pbi
->vvp9_amstream_dec_info
.rate
;
8955 if (width
&& height
)
8956 pbi
->frame_ar
= height
* 0x100 / width
;
8960 pr_info("vp9: ver (%d,%d) decinfo: %dx%d rate=%d\n", vp9_version
,
8961 0, width
, height
, pbi
->frame_dur
);
8963 if (pbi
->frame_dur
== 0)
8964 pbi
->frame_dur
= 96000 / 24;
8966 INIT_KFIFO(pbi
->display_q
);
8967 INIT_KFIFO(pbi
->newframe_q
);
8970 for (i
= 0; i
< VF_POOL_SIZE
; i
++) {
8971 const struct vframe_s
*vf
= &pbi
->vfpool
[i
];
8973 pbi
->vfpool
[i
].index
= -1;
8974 kfifo_put(&pbi
->newframe_q
, vf
);
8978 ret
= vp9_local_init(pbi
);
8980 if (!pbi
->pts_unstable
) {
8982 (pbi
->vvp9_amstream_dec_info
.rate
== 0)?1:0;
8983 pr_info("set pts unstable\n");
8990 #ifdef MULTI_INSTANCE_SUPPORT
8991 static s32
vvp9_init(struct vdec_s
*vdec
)
8993 struct VP9Decoder_s
*pbi
= (struct VP9Decoder_s
*)vdec
->private;
8995 static s32
vvp9_init(struct VP9Decoder_s
*pbi
)
8999 int fw_size
= 0x1000 * 16;
9000 struct firmware_s
*fw
= NULL
;
9002 pbi
->stat
|= STAT_TIMER_INIT
;
9004 if (vvp9_local_init(pbi
) < 0)
9007 fw
= vmalloc(sizeof(struct firmware_s
) + fw_size
);
9008 if (IS_ERR_OR_NULL(fw
))
9011 if (get_firmware_data(VIDEO_DEC_VP9_MMU
, fw
->data
) < 0) {
9012 pr_err("get firmware fail.\n");
9019 INIT_WORK(&pbi
->set_clk_work
, vp9_set_clk
);
9020 init_timer(&pbi
->timer
);
9022 #ifdef MULTI_INSTANCE_SUPPORT
9023 if (pbi
->m_ins_flag
) {
9024 pbi
->timer
.data
= (ulong
) pbi
;
9025 pbi
->timer
.function
= vvp9_put_timer_func
;
9026 pbi
->timer
.expires
= jiffies
+ PUT_INTERVAL
;
9028 /*add_timer(&pbi->timer);
9030 pbi->stat |= STAT_TIMER_ARM;
9031 pbi->stat |= STAT_ISR_REG;*/
9033 INIT_WORK(&pbi
->work
, vp9_work
);
9034 INIT_WORK(&pbi
->recycle_mmu_work
, vp9_recycle_mmu_work
);
9035 #ifdef SUPPORT_FB_DECODING
9036 if (pbi
->used_stage_buf_num
> 0)
9037 INIT_WORK(&pbi
->s1_work
, vp9_s1_work
);
9041 /* picture list init.*/
9042 pbi
->dec_result
= DEC_INIT_PICLIST
;
9043 vdec_schedule_work(&pbi
->work
);
9052 ret
= amhevc_loadmc_ex(VFORMAT_VP9
, NULL
, fw
->data
);
9056 pr_err("VP9: the %s fw loading failed, err: %x\n",
9057 tee_enabled() ? "TEE" : "local", ret
);
9063 pbi
->stat
|= STAT_MC_LOAD
;
9065 /* enable AMRISC side protocol */
9066 vvp9_prot_init(pbi
, HW_MASK_FRONT
| HW_MASK_BACK
);
9068 if (vdec_request_threaded_irq(VDEC_IRQ_0
,
9071 IRQF_ONESHOT
,/*run thread on this irq disabled*/
9072 "vvp9-irq", (void *)pbi
)) {
9073 pr_info("vvp9 irq register error.\n");
9078 pbi
->stat
|= STAT_ISR_REG
;
9080 pbi
->provider_name
= PROVIDER_NAME
;
9081 #ifdef MULTI_INSTANCE_SUPPORT
9082 vf_provider_init(&vvp9_vf_prov
, PROVIDER_NAME
,
9083 &vvp9_vf_provider
, pbi
);
9084 vf_reg_provider(&vvp9_vf_prov
);
9085 vf_notify_receiver(PROVIDER_NAME
, VFRAME_EVENT_PROVIDER_START
, NULL
);
9086 if (pbi
->frame_dur
!= 0) {
9088 vf_notify_receiver(pbi
->provider_name
,
9089 VFRAME_EVENT_PROVIDER_FR_HINT
,
9091 ((unsigned long)pbi
->frame_dur
));
9094 vf_provider_init(&vvp9_vf_prov
, PROVIDER_NAME
, &vvp9_vf_provider
,
9096 vf_reg_provider(&vvp9_vf_prov
);
9097 vf_notify_receiver(PROVIDER_NAME
, VFRAME_EVENT_PROVIDER_START
, NULL
);
9099 vf_notify_receiver(PROVIDER_NAME
, VFRAME_EVENT_PROVIDER_FR_HINT
,
9100 (void *)((unsigned long)pbi
->frame_dur
));
9102 pbi
->stat
|= STAT_VF_HOOK
;
9104 pbi
->timer
.data
= (ulong
)pbi
;
9105 pbi
->timer
.function
= vvp9_put_timer_func
;
9106 pbi
->timer
.expires
= jiffies
+ PUT_INTERVAL
;
9108 pbi
->stat
|= STAT_VDEC_RUN
;
9110 add_timer(&pbi
->timer
);
9112 pbi
->stat
|= STAT_TIMER_ARM
;
9117 pbi
->process_busy
= 0;
9118 pr_info("%d, vvp9_init, RP=0x%x\n",
9119 __LINE__
, READ_VREG(HEVC_STREAM_RD_PTR
));
9123 static int vmvp9_stop(struct VP9Decoder_s
*pbi
)
9127 if (pbi
->stat
& STAT_VDEC_RUN
) {
9129 pbi
->stat
&= ~STAT_VDEC_RUN
;
9131 if (pbi
->stat
& STAT_ISR_REG
) {
9132 vdec_free_irq(VDEC_IRQ_0
, (void *)pbi
);
9133 pbi
->stat
&= ~STAT_ISR_REG
;
9135 if (pbi
->stat
& STAT_TIMER_ARM
) {
9136 del_timer_sync(&pbi
->timer
);
9137 pbi
->stat
&= ~STAT_TIMER_ARM
;
9140 if (pbi
->stat
& STAT_VF_HOOK
) {
9142 vf_notify_receiver(pbi
->provider_name
,
9143 VFRAME_EVENT_PROVIDER_FR_END_HINT
,
9146 vf_unreg_provider(&vvp9_vf_prov
);
9147 pbi
->stat
&= ~STAT_VF_HOOK
;
9149 vp9_local_uninit(pbi
);
9150 reset_process_time(pbi
);
9151 cancel_work_sync(&pbi
->work
);
9152 cancel_work_sync(&pbi
->recycle_mmu_work
);
9153 #ifdef SUPPORT_FB_DECODING
9154 if (pbi
->used_stage_buf_num
> 0)
9155 cancel_work_sync(&pbi
->s1_work
);
9157 cancel_work_sync(&pbi
->set_clk_work
);
9158 uninit_mmu_buffers(pbi
);
9165 static int vvp9_stop(struct VP9Decoder_s
*pbi
)
9169 pbi
->first_sc_checked
= 0;
9170 if (pbi
->stat
& STAT_VDEC_RUN
) {
9172 pbi
->stat
&= ~STAT_VDEC_RUN
;
9175 if (pbi
->stat
& STAT_ISR_REG
) {
9176 #ifdef MULTI_INSTANCE_SUPPORT
9177 if (!pbi
->m_ins_flag
)
9179 WRITE_VREG(HEVC_ASSIST_MBOX0_MASK
, 0);
9180 vdec_free_irq(VDEC_IRQ_0
, (void *)pbi
);
9181 pbi
->stat
&= ~STAT_ISR_REG
;
9184 if (pbi
->stat
& STAT_TIMER_ARM
) {
9185 del_timer_sync(&pbi
->timer
);
9186 pbi
->stat
&= ~STAT_TIMER_ARM
;
9189 if (pbi
->stat
& STAT_VF_HOOK
) {
9191 vf_notify_receiver(pbi
->provider_name
,
9192 VFRAME_EVENT_PROVIDER_FR_END_HINT
,
9195 vf_unreg_provider(&vvp9_vf_prov
);
9196 pbi
->stat
&= ~STAT_VF_HOOK
;
9198 vp9_local_uninit(pbi
);
9200 cancel_work_sync(&pbi
->set_clk_work
);
9201 #ifdef MULTI_INSTANCE_SUPPORT
9202 if (pbi
->m_ins_flag
) {
9203 #ifdef SUPPORT_FB_DECODING
9204 if (pbi
->used_stage_buf_num
> 0)
9205 cancel_work_sync(&pbi
->s1_work
);
9207 cancel_work_sync(&pbi
->work
);
9208 cancel_work_sync(&pbi
->recycle_mmu_work
);
9214 uninit_mmu_buffers(pbi
);
9220 static int amvdec_vp9_mmu_init(struct VP9Decoder_s
*pbi
)
9222 int tvp_flag
= vdec_secure(hw_to_vdec(pbi
)) ?
9223 CODEC_MM_FLAGS_TVP
: 0;
9226 if ((pbi
->max_pic_w
* pbi
->max_pic_h
> 1280*736) &&
9227 (pbi
->max_pic_w
* pbi
->max_pic_h
<= 1920*1088)) {
9229 } else if ((pbi
->max_pic_w
* pbi
->max_pic_h
> 0) &&
9230 (pbi
->max_pic_w
* pbi
->max_pic_h
<= 1280*736)) {
9233 pbi
->need_cache_size
= buf_size
* SZ_1M
;
9234 pbi
->sc_start_time
= get_jiffies_64();
9235 if (pbi
->mmu_enable
&& ((pbi
->double_write_mode
& 0x10) == 0)) {
9236 pbi
->mmu_box
= decoder_mmu_box_alloc_box(DRIVER_NAME
,
9237 pbi
->index
, FRAME_BUFFERS
,
9238 pbi
->need_cache_size
,
9241 if (!pbi
->mmu_box
) {
9242 pr_err("vp9 alloc mmu box failed!!\n");
9246 pbi
->bmmu_box
= decoder_bmmu_box_alloc_box(
9249 MAX_BMMU_BUFFER_NUM
,
9251 CODEC_MM_FLAGS_CMA_CLEAR
|
9252 CODEC_MM_FLAGS_FOR_VDECODER
|
9254 if (!pbi
->bmmu_box
) {
9255 pr_err("vp9 alloc bmmu box failed!!\n");
9261 static struct VP9Decoder_s
*gHevc
;
9263 static int amvdec_vp9_probe(struct platform_device
*pdev
)
9265 struct vdec_s
*pdata
= *(struct vdec_s
**)pdev
->dev
.platform_data
;
9266 struct BUF_s BUF
[MAX_BUF_NUM
];
9267 struct VP9Decoder_s
*pbi
;
9269 #ifndef MULTI_INSTANCE_SUPPORT
9272 pr_debug("%s\n", __func__
);
9274 mutex_lock(&vvp9_mutex
);
9275 pbi
= vmalloc(sizeof(struct VP9Decoder_s
));
9277 pr_info("\namvdec_vp9 device data allocation failed\n");
9278 mutex_unlock(&vvp9_mutex
);
9283 memcpy(&BUF
[0], &pbi
->m_BUF
[0], sizeof(struct BUF_s
) * MAX_BUF_NUM
);
9284 memset(pbi
, 0, sizeof(struct VP9Decoder_s
));
9285 memcpy(&pbi
->m_BUF
[0], &BUF
[0], sizeof(struct BUF_s
) * MAX_BUF_NUM
);
9288 pbi
->first_sc_checked
= 0;
9289 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_SM1
) {
9290 vp9_max_pic_w
= 8192;
9291 vp9_max_pic_h
= 4608;
9293 pbi
->max_pic_w
= vp9_max_pic_w
;
9294 pbi
->max_pic_h
= vp9_max_pic_h
;
9296 #ifdef MULTI_INSTANCE_SUPPORT
9298 pbi
->start_process_time
= 0;
9299 pbi
->timeout_num
= 0;
9301 pbi
->fatal_error
= 0;
9302 pbi
->show_frame_num
= 0;
9303 if (pdata
== NULL
) {
9304 pr_info("\namvdec_vp9 memory resource undefined.\n");
9306 mutex_unlock(&vvp9_mutex
);
9309 pbi
->m_ins_flag
= 0;
9310 #ifdef MULTI_INSTANCE_SUPPORT
9311 pbi
->platform_dev
= pdev
;
9312 platform_set_drvdata(pdev
, pdata
);
9314 pbi
->double_write_mode
= double_write_mode
;
9315 pbi
->mmu_enable
= 1;
9316 if (amvdec_vp9_mmu_init(pbi
) < 0) {
9318 mutex_unlock(&vvp9_mutex
);
9319 pr_err("vp9 alloc bmmu box failed!!\n");
9323 ret
= decoder_bmmu_box_alloc_buf_phy(pbi
->bmmu_box
, WORK_SPACE_BUF_ID
,
9324 work_buf_size
, DRIVER_NAME
, &pdata
->mem_start
);
9326 uninit_mmu_buffers(pbi
);
9328 mutex_unlock(&vvp9_mutex
);
9331 pbi
->buf_size
= work_buf_size
;
9333 #ifdef MULTI_INSTANCE_SUPPORT
9334 pbi
->buf_start
= pdata
->mem_start
;
9336 if (!pbi
->mmu_enable
)
9337 pbi
->mc_buf_spec
.buf_end
= pdata
->mem_start
+ pbi
->buf_size
;
9339 for (i
= 0; i
< WORK_BUF_SPEC_NUM
; i
++)
9340 amvvp9_workbuff_spec
[i
].start_adr
= pdata
->mem_start
;
9345 pr_info("===VP9 decoder mem resource 0x%lx size 0x%x\n",
9346 pdata
->mem_start
, pbi
->buf_size
);
9349 if (pdata
->sys_info
)
9350 pbi
->vvp9_amstream_dec_info
= *pdata
->sys_info
;
9352 pbi
->vvp9_amstream_dec_info
.width
= 0;
9353 pbi
->vvp9_amstream_dec_info
.height
= 0;
9354 pbi
->vvp9_amstream_dec_info
.rate
= 30;
9356 pbi
->no_head
= no_head
;
9357 #ifdef MULTI_INSTANCE_SUPPORT
9358 pbi
->cma_dev
= pdata
->cma_dev
;
9360 cma_dev
= pdata
->cma_dev
;
9363 #ifdef MULTI_INSTANCE_SUPPORT
9364 pdata
->private = pbi
;
9365 pdata
->dec_status
= vvp9_dec_status
;
9366 pdata
->set_isreset
= vvp9_set_isreset
;
9368 if (vvp9_init(pdata
) < 0) {
9370 if (vvp9_init(pbi
) < 0) {
9372 pr_info("\namvdec_vp9 init failed.\n");
9373 vp9_local_uninit(pbi
);
9374 uninit_mmu_buffers(pbi
);
9376 pdata
->dec_status
= NULL
;
9377 mutex_unlock(&vvp9_mutex
);
9380 /*set the max clk for smooth playing...*/
9381 hevc_source_changed(VFORMAT_VP9
,
9383 mutex_unlock(&vvp9_mutex
);
9388 static int amvdec_vp9_remove(struct platform_device
*pdev
)
9390 struct VP9Decoder_s
*pbi
= gHevc
;
9391 struct vdec_s
*vdec
= hw_to_vdec(pbi
);
9395 pr_info("amvdec_vp9_remove\n");
9397 mutex_lock(&vvp9_mutex
);
9401 hevc_source_changed(VFORMAT_VP9
, 0, 0, 0);
9403 if (vdec
->parallel_dec
== 1) {
9404 for (i
= 0; i
< FRAME_BUFFERS
; i
++) {
9405 vdec
->free_canvas_ex(pbi
->common
.buffer_pool
->
9406 frame_bufs
[i
].buf
.y_canvas_index
, vdec
->id
);
9407 vdec
->free_canvas_ex(pbi
->common
.buffer_pool
->
9408 frame_bufs
[i
].buf
.uv_canvas_index
, vdec
->id
);
9413 pr_info("pts missed %ld, pts hit %ld, duration %d\n",
9414 pbi
->pts_missed
, pbi
->pts_hit
, pbi
->frame_dur
);
9419 mutex_unlock(&vvp9_mutex
);
9424 /****************************************/
9426 static int vp9_suspend(struct device
*dev
)
9428 amhevc_suspend(to_platform_device(dev
), dev
->power
.power_state
);
9432 static int vp9_resume(struct device
*dev
)
9434 amhevc_resume(to_platform_device(dev
));
9438 static const struct dev_pm_ops vp9_pm_ops
= {
9439 SET_SYSTEM_SLEEP_PM_OPS(vp9_suspend
, vp9_resume
)
9443 static struct platform_driver amvdec_vp9_driver
= {
9444 .probe
= amvdec_vp9_probe
,
9445 .remove
= amvdec_vp9_remove
,
9447 .name
= DRIVER_NAME
,
9454 static struct codec_profile_t amvdec_vp9_profile
= {
9459 static struct codec_profile_t amvdec_vp9_profile_mult
;
9461 static unsigned char get_data_check_sum
9462 (struct VP9Decoder_s
*pbi
, int size
)
9468 if (!pbi
->chunk
->block
->is_mapped
)
9469 data
= codec_mm_vmap(pbi
->chunk
->block
->start
+
9470 pbi
->chunk
->offset
, size
);
9472 data
= ((u8
*)pbi
->chunk
->block
->start_virt
) +
9475 for (jj
= 0; jj
< size
; jj
++)
9478 if (!pbi
->chunk
->block
->is_mapped
)
9479 codec_mm_unmap_phyaddr(data
);
9483 static void dump_data(struct VP9Decoder_s
*pbi
, int size
)
9487 int padding_size
= pbi
->chunk
->offset
&
9488 (VDEC_FIFO_ALIGN
- 1);
9490 if (!pbi
->chunk
->block
->is_mapped
)
9491 data
= codec_mm_vmap(pbi
->chunk
->block
->start
+
9492 pbi
->chunk
->offset
, size
);
9494 data
= ((u8
*)pbi
->chunk
->block
->start_virt
) +
9497 vp9_print(pbi
, 0, "padding: ");
9498 for (jj
= padding_size
; jj
> 0; jj
--)
9501 "%02x ", *(data
- jj
));
9502 vp9_print_cont(pbi
, 0, "data adr %p\n",
9505 for (jj
= 0; jj
< size
; jj
++) {
9506 if ((jj
& 0xf) == 0)
9513 if (((jj
+ 1) & 0xf) == 0)
9522 if (!pbi
->chunk
->block
->is_mapped
)
9523 codec_mm_unmap_phyaddr(data
);
9526 static void vp9_work(struct work_struct
*work
)
9528 struct VP9Decoder_s
*pbi
= container_of(work
,
9529 struct VP9Decoder_s
, work
);
9530 struct vdec_s
*vdec
= hw_to_vdec(pbi
);
9531 /* finished decoding one frame or error,
9532 * notify vdec core to switch context
9534 vp9_print(pbi
, PRINT_FLAG_VDEC_DETAIL
,
9535 "%s dec_result %d %x %x %x\n",
9538 READ_VREG(HEVC_STREAM_LEVEL
),
9539 READ_VREG(HEVC_STREAM_WR_PTR
),
9540 READ_VREG(HEVC_STREAM_RD_PTR
));
9542 if (pbi
->dec_result
== DEC_INIT_PICLIST
) {
9544 pbi
->pic_list_init_done
= true;
9548 if (pbi
->dec_result
== DEC_V4L2_CONTINUE_DECODING
) {
9549 struct aml_vcodec_ctx
*ctx
=
9550 (struct aml_vcodec_ctx
*)(pbi
->v4l2_ctx
);
9552 if (ctx
->param_sets_from_ucode
) {
9553 reset_process_time(pbi
);
9554 if (wait_event_interruptible_timeout(ctx
->wq
,
9555 ctx
->v4l_codec_ready
,
9556 msecs_to_jiffies(500)) < 0)
9560 continue_decoding(pbi
);
9561 pbi
->postproc_done
= 0;
9562 pbi
->process_busy
= 0;
9567 if (((pbi
->dec_result
== DEC_RESULT_GET_DATA
) ||
9568 (pbi
->dec_result
== DEC_RESULT_GET_DATA_RETRY
))
9569 && (hw_to_vdec(pbi
)->next_status
!=
9570 VDEC_STATUS_DISCONNECTED
)) {
9571 if (!vdec_has_more_input(vdec
)) {
9572 pbi
->dec_result
= DEC_RESULT_EOS
;
9573 vdec_schedule_work(&pbi
->work
);
9577 if (pbi
->dec_result
== DEC_RESULT_GET_DATA
) {
9578 vp9_print(pbi
, PRINT_FLAG_VDEC_STATUS
,
9579 "%s DEC_RESULT_GET_DATA %x %x %x\n",
9581 READ_VREG(HEVC_STREAM_LEVEL
),
9582 READ_VREG(HEVC_STREAM_WR_PTR
),
9583 READ_VREG(HEVC_STREAM_RD_PTR
));
9584 vdec_vframe_dirty(vdec
, pbi
->chunk
);
9585 vdec_clean_input(vdec
);
9588 if (get_free_buf_count(pbi
) >=
9589 run_ready_min_buf_num
) {
9592 r
= vdec_prepare_input(vdec
, &pbi
->chunk
);
9594 pbi
->dec_result
= DEC_RESULT_GET_DATA_RETRY
;
9597 PRINT_FLAG_VDEC_DETAIL
,
9598 "amvdec_vh265: Insufficient data\n");
9600 vdec_schedule_work(&pbi
->work
);
9603 pbi
->dec_result
= DEC_RESULT_NONE
;
9604 vp9_print(pbi
, PRINT_FLAG_VDEC_STATUS
,
9605 "%s: chunk size 0x%x sum 0x%x\n",
9607 (debug
& PRINT_FLAG_VDEC_STATUS
) ?
9608 get_data_check_sum(pbi
, r
) : 0
9611 if (debug
& PRINT_FLAG_VDEC_DATA
)
9612 dump_data(pbi
, pbi
->chunk
->size
);
9614 decode_size
= pbi
->chunk
->size
+
9615 (pbi
->chunk
->offset
& (VDEC_FIFO_ALIGN
- 1));
9617 WRITE_VREG(HEVC_DECODE_SIZE
,
9618 READ_VREG(HEVC_DECODE_SIZE
) + decode_size
);
9620 vdec_enable_input(vdec
);
9622 WRITE_VREG(HEVC_DEC_STATUS_REG
, HEVC_ACTION_DONE
);
9624 start_process_time(pbi
);
9627 pbi
->dec_result
= DEC_RESULT_GET_DATA_RETRY
;
9629 vp9_print(pbi
, PRINT_FLAG_VDEC_DETAIL
,
9630 "amvdec_vh265: Insufficient data\n");
9632 vdec_schedule_work(&pbi
->work
);
9635 } else if (pbi
->dec_result
== DEC_RESULT_DONE
) {
9636 #ifdef SUPPORT_FB_DECODING
9637 if (pbi
->used_stage_buf_num
> 0) {
9638 #ifndef FB_DECODING_TEST_SCHEDULE
9639 if (!is_s2_decoding_finished(pbi
)) {
9640 vp9_print(pbi
, PRINT_FLAG_VDEC_DETAIL
,
9641 "s2 decoding not done, check again later\n");
9642 vdec_schedule_work(&pbi
->work
);
9646 if (mcrcc_cache_alg_flag
)
9650 /* if (!pbi->ctx_valid)
9651 pbi->ctx_valid = 1; */
9654 pbi
->process_state
= PROC_STATE_INIT
;
9655 decode_frame_count
[pbi
->index
] = pbi
->frame_count
;
9657 if (pbi
->mmu_enable
)
9659 (READ_VREG(HEVC_SAO_MMU_STATUS
) >> 16);
9660 vp9_print(pbi
, PRINT_FLAG_VDEC_STATUS
,
9661 "%s (===> %d) dec_result %d %x %x %x shiftbytes 0x%x decbytes 0x%x\n",
9665 READ_VREG(HEVC_STREAM_LEVEL
),
9666 READ_VREG(HEVC_STREAM_WR_PTR
),
9667 READ_VREG(HEVC_STREAM_RD_PTR
),
9668 READ_VREG(HEVC_SHIFT_BYTE_COUNT
),
9669 READ_VREG(HEVC_SHIFT_BYTE_COUNT
) -
9670 pbi
->start_shift_bytes
9672 vdec_vframe_dirty(hw_to_vdec(pbi
), pbi
->chunk
);
9673 } else if (pbi
->dec_result
== DEC_RESULT_AGAIN
) {
9675 stream base: stream buf empty or timeout
9676 frame base: vdec_prepare_input fail
9678 if (!vdec_has_more_input(vdec
)) {
9679 pbi
->dec_result
= DEC_RESULT_EOS
;
9680 vdec_schedule_work(&pbi
->work
);
9683 } else if (pbi
->dec_result
== DEC_RESULT_EOS
) {
9684 vp9_print(pbi
, PRINT_FLAG_VDEC_STATUS
,
9685 "%s: end of stream\n",
9688 vp9_bufmgr_postproc(pbi
);
9690 if (pbi
->is_used_v4l
)
9691 notify_v4l_eos(hw_to_vdec(pbi
));
9693 vdec_vframe_dirty(hw_to_vdec(pbi
), pbi
->chunk
);
9694 } else if (pbi
->dec_result
== DEC_RESULT_FORCE_EXIT
) {
9695 vp9_print(pbi
, PRINT_FLAG_VDEC_STATUS
,
9698 if (pbi
->stat
& STAT_VDEC_RUN
) {
9700 pbi
->stat
&= ~STAT_VDEC_RUN
;
9703 if (pbi
->stat
& STAT_ISR_REG
) {
9704 #ifdef MULTI_INSTANCE_SUPPORT
9705 if (!pbi
->m_ins_flag
)
9707 WRITE_VREG(HEVC_ASSIST_MBOX0_MASK
, 0);
9708 vdec_free_irq(VDEC_IRQ_0
, (void *)pbi
);
9709 pbi
->stat
&= ~STAT_ISR_REG
;
9712 if (pbi
->stat
& STAT_VDEC_RUN
) {
9714 pbi
->stat
&= ~STAT_VDEC_RUN
;
9717 if (pbi
->stat
& STAT_TIMER_ARM
) {
9718 del_timer_sync(&pbi
->timer
);
9719 pbi
->stat
&= ~STAT_TIMER_ARM
;
9721 /* mark itself has all HW resource released and input released */
9722 #ifdef SUPPORT_FB_DECODING
9723 if (pbi
->used_stage_buf_num
> 0)
9724 vdec_core_finish_run(hw_to_vdec(pbi
), CORE_MASK_HEVC_BACK
);
9726 vdec_core_finish_run(hw_to_vdec(pbi
), CORE_MASK_VDEC_1
9728 | CORE_MASK_HEVC_FRONT
9729 | CORE_MASK_HEVC_BACK
9732 if (vdec
->parallel_dec
== 1)
9733 vdec_core_finish_run(vdec
, CORE_MASK_HEVC
);
9735 vdec_core_finish_run(hw_to_vdec(pbi
), CORE_MASK_VDEC_1
9738 trigger_schedule(pbi
);
9741 static int vp9_hw_ctx_restore(struct VP9Decoder_s
*pbi
)
9744 #if (!defined SUPPORT_FB_DECODING)
9745 vvp9_prot_init(pbi
, HW_MASK_FRONT
| HW_MASK_BACK
);
9746 #elif (defined FB_DECODING_TEST_SCHEDULE)
9747 vvp9_prot_init(pbi
, HW_MASK_FRONT
| HW_MASK_BACK
);
9749 if (pbi
->used_stage_buf_num
> 0)
9750 vvp9_prot_init(pbi
, HW_MASK_FRONT
);
9752 vvp9_prot_init(pbi
, HW_MASK_FRONT
| HW_MASK_BACK
);
9756 static unsigned long run_ready(struct vdec_s
*vdec
, unsigned long mask
)
9758 struct VP9Decoder_s
*pbi
=
9759 (struct VP9Decoder_s
*)vdec
->private;
9760 int tvp
= vdec_secure(hw_to_vdec(pbi
)) ?
9761 CODEC_MM_FLAGS_TVP
: 0;
9762 unsigned long ret
= 0;
9764 if (!(pbi
->pic_list_init_done
&& pbi
->pic_list_init_done2
) || pbi
->eos
)
9766 if (!pbi
->first_sc_checked
&& pbi
->mmu_enable
) {
9767 int size
= decoder_mmu_box_sc_check(pbi
->mmu_box
, tvp
);
9768 pbi
->first_sc_checked
= 1;
9769 vp9_print(pbi
, 0, "vp9 cached=%d need_size=%d speed= %d ms\n",
9770 size
, (pbi
->need_cache_size
>> PAGE_SHIFT
),
9771 (int)(get_jiffies_64() - pbi
->sc_start_time
) * 1000/HZ
);
9774 #ifdef SUPPORT_FB_DECODING
9775 if (pbi
->used_stage_buf_num
> 0) {
9776 if (mask
& CORE_MASK_HEVC_FRONT
) {
9777 if (get_free_stage_buf_num(pbi
) > 0
9778 && mv_buf_available(pbi
))
9779 ret
|= CORE_MASK_HEVC_FRONT
;
9781 if (mask
& CORE_MASK_HEVC_BACK
) {
9782 if (s2_buf_available(pbi
) &&
9783 (get_free_buf_count(pbi
) >=
9784 run_ready_min_buf_num
)) {
9785 ret
|= CORE_MASK_HEVC_BACK
;
9786 pbi
->back_not_run_ready
= 0;
9788 pbi
->back_not_run_ready
= 1;
9790 if (get_free_buf_count(pbi
) <
9791 run_ready_min_buf_num
)
9795 } else if (get_free_buf_count(pbi
) >=
9796 run_ready_min_buf_num
)
9797 ret
= CORE_MASK_VDEC_1
| CORE_MASK_HEVC
9798 | CORE_MASK_HEVC_FRONT
9799 | CORE_MASK_HEVC_BACK
;
9801 if (ret
& CORE_MASK_HEVC_FRONT
)
9802 not_run_ready
[pbi
->index
] = 0;
9804 not_run_ready
[pbi
->index
]++;
9806 if (ret
& CORE_MASK_HEVC_BACK
)
9807 not_run2_ready
[pbi
->index
] = 0;
9809 not_run2_ready
[pbi
->index
]++;
9812 PRINT_FLAG_VDEC_DETAIL
, "%s mask %lx=>%lx (%d %d %d %d)\r\n",
9813 __func__
, mask
, ret
,
9814 get_free_stage_buf_num(pbi
),
9815 mv_buf_available(pbi
),
9816 s2_buf_available(pbi
),
9817 get_free_buf_count(pbi
)
9823 if (get_free_buf_count(pbi
) >=
9824 run_ready_min_buf_num
) {
9825 if (vdec
->parallel_dec
== 1)
9826 ret
= CORE_MASK_HEVC
;
9828 ret
= CORE_MASK_VDEC_1
| CORE_MASK_HEVC
;
9831 if (pbi
->is_used_v4l
) {
9832 struct aml_vcodec_ctx
*ctx
=
9833 (struct aml_vcodec_ctx
*)(pbi
->v4l2_ctx
);
9835 if (ctx
->param_sets_from_ucode
&&
9836 !ctx
->v4l_codec_ready
&&
9837 pbi
->v4l_params_parsed
) {
9838 ret
= 0; /*the params has parsed.*/
9839 } else if (!ctx
->v4l_codec_dpb_ready
) {
9840 if (v4l2_m2m_num_dst_bufs_ready(ctx
->m2m_ctx
) <
9841 run_ready_min_buf_num
)
9847 not_run_ready
[pbi
->index
] = 0;
9849 not_run_ready
[pbi
->index
]++;
9852 PRINT_FLAG_VDEC_DETAIL
, "%s mask %lx=>%lx\r\n",
9853 __func__
, mask
, ret
);
9858 static void run_front(struct vdec_s
*vdec
)
9860 struct VP9Decoder_s
*pbi
=
9861 (struct VP9Decoder_s
*)vdec
->private;
9864 run_count
[pbi
->index
]++;
9865 /* pbi->chunk = vdec_prepare_input(vdec); */
9866 #if (!defined SUPPORT_FB_DECODING)
9867 hevc_reset_core(vdec
);
9868 #elif (defined FB_DECODING_TEST_SCHEDULE)
9869 hevc_reset_core(vdec
);
9871 if (pbi
->used_stage_buf_num
> 0)
9872 fb_reset_core(vdec
, HW_MASK_FRONT
);
9874 hevc_reset_core(vdec
);
9877 size
= vdec_prepare_input(vdec
, &pbi
->chunk
);
9879 input_empty
[pbi
->index
]++;
9881 pbi
->dec_result
= DEC_RESULT_AGAIN
;
9883 vp9_print(pbi
, PRINT_FLAG_VDEC_DETAIL
,
9884 "ammvdec_vh265: Insufficient data\n");
9886 vdec_schedule_work(&pbi
->work
);
9890 input_empty
[pbi
->index
] = 0;
9891 pbi
->dec_result
= DEC_RESULT_NONE
;
9892 pbi
->start_shift_bytes
= READ_VREG(HEVC_SHIFT_BYTE_COUNT
);
9894 if (debug
& PRINT_FLAG_VDEC_STATUS
) {
9897 "%s (%d): size 0x%x (0x%x 0x%x) sum 0x%x (%x %x %x %x %x) bytes 0x%x",
9899 pbi
->frame_count
, size
,
9900 pbi
->chunk
? pbi
->chunk
->size
: 0,
9901 pbi
->chunk
? pbi
->chunk
->offset
: 0,
9902 pbi
->chunk
? ((vdec_frame_based(vdec
) &&
9903 (debug
& PRINT_FLAG_VDEC_STATUS
)) ?
9904 get_data_check_sum(pbi
, size
) : 0) : 0,
9905 READ_VREG(HEVC_STREAM_START_ADDR
),
9906 READ_VREG(HEVC_STREAM_END_ADDR
),
9907 READ_VREG(HEVC_STREAM_LEVEL
),
9908 READ_VREG(HEVC_STREAM_WR_PTR
),
9909 READ_VREG(HEVC_STREAM_RD_PTR
),
9910 pbi
->start_shift_bytes
);
9911 if (vdec_frame_based(vdec
) && pbi
->chunk
) {
9914 if (!pbi
->chunk
->block
->is_mapped
)
9915 data
= codec_mm_vmap(pbi
->chunk
->block
->start
+
9916 pbi
->chunk
->offset
, 8);
9918 data
= ((u8
*)pbi
->chunk
->block
->start_virt
) +
9921 vp9_print_cont(pbi
, 0, "data adr %p:",
9923 for (ii
= 0; ii
< 8; ii
++)
9924 vp9_print_cont(pbi
, 0, "%02x ",
9927 if (!pbi
->chunk
->block
->is_mapped
)
9928 codec_mm_unmap_phyaddr(data
);
9930 vp9_print_cont(pbi
, 0, "\r\n");
9932 if (vdec
->mc_loaded
) {
9933 /*firmware have load before,
9934 and not changes to another.
9938 ret
= amhevc_loadmc_ex(VFORMAT_VP9
, NULL
, pbi
->fw
->data
);
9941 vp9_print(pbi
, PRINT_FLAG_ERROR
,
9942 "VP9: the %s fw loading failed, err: %x\n",
9943 tee_enabled() ? "TEE" : "local", ret
);
9944 pbi
->dec_result
= DEC_RESULT_FORCE_EXIT
;
9945 vdec_schedule_work(&pbi
->work
);
9948 vdec
->mc_loaded
= 1;
9949 vdec
->mc_type
= VFORMAT_VP9
;
9952 if (vp9_hw_ctx_restore(pbi
) < 0) {
9953 vdec_schedule_work(&pbi
->work
);
9957 vdec_enable_input(vdec
);
9959 WRITE_VREG(HEVC_DEC_STATUS_REG
, HEVC_ACTION_DONE
);
9961 if (vdec_frame_based(vdec
)) {
9962 if (debug
& PRINT_FLAG_VDEC_DATA
)
9963 dump_data(pbi
, pbi
->chunk
->size
);
9965 WRITE_VREG(HEVC_SHIFT_BYTE_COUNT
, 0);
9966 size
= pbi
->chunk
->size
+
9967 (pbi
->chunk
->offset
& (VDEC_FIFO_ALIGN
- 1));
9969 WRITE_VREG(HEVC_DECODE_SIZE
, size
);
9970 WRITE_VREG(HEVC_DECODE_COUNT
, pbi
->slice_idx
);
9973 vp9_print(pbi
, PRINT_FLAG_VDEC_DETAIL
,
9974 "%s: start hevc (%x %x %x)\n",
9976 READ_VREG(HEVC_DEC_STATUS_REG
),
9977 READ_VREG(HEVC_MPC_E
),
9978 READ_VREG(HEVC_MPSR
));
9980 start_process_time(pbi
);
9981 mod_timer(&pbi
->timer
, jiffies
);
9982 pbi
->stat
|= STAT_TIMER_ARM
;
9983 pbi
->stat
|= STAT_ISR_REG
;
9985 pbi
->stat
|= STAT_VDEC_RUN
;
9988 #ifdef SUPPORT_FB_DECODING
9989 static void mpred_process(struct VP9Decoder_s
*pbi
)
9991 union param_u
*params
= &pbi
->s1_param
;
9992 unsigned char use_prev_frame_mvs
=
9993 !params
->p
.error_resilient_mode
&&
9994 params
->p
.width
== pbi
->s1_width
&&
9995 params
->p
.height
== pbi
->s1_height
&&
9996 !pbi
->s1_intra_only
&&
9997 pbi
->s1_last_show_frame
&&
9998 (pbi
->s1_frame_type
!= KEY_FRAME
);
9999 pbi
->s1_width
= params
->p
.width
;
10000 pbi
->s1_height
= params
->p
.height
;
10001 pbi
->s1_frame_type
= params
->p
.frame_type
;
10002 pbi
->s1_intra_only
=
10003 (params
->p
.show_frame
||
10004 params
->p
.show_existing_frame
)
10005 ? 0 : params
->p
.intra_only
;
10006 if ((pbi
->s1_frame_type
!= KEY_FRAME
)
10007 && (!pbi
->s1_intra_only
)) {
10008 unsigned int data32
;
10009 int mpred_mv_rd_end_addr
;
10011 mpred_mv_rd_end_addr
=
10012 pbi
->s1_mpred_mv_wr_start_addr_pre
10013 + (pbi
->lcu_total
* MV_MEM_UNIT
);
10015 WRITE_VREG(HEVC_MPRED_CTRL3
, 0x24122412);
10016 WRITE_VREG(HEVC_MPRED_ABV_START_ADDR
,
10017 pbi
->work_space_buf
->
10018 mpred_above
.buf_start
);
10020 data32
= READ_VREG(HEVC_MPRED_CTRL4
);
10022 data32
&= (~(1 << 6));
10023 data32
|= (use_prev_frame_mvs
<< 6);
10024 WRITE_VREG(HEVC_MPRED_CTRL4
, data32
);
10026 WRITE_VREG(HEVC_MPRED_MV_WR_START_ADDR
,
10027 pbi
->s1_mpred_mv_wr_start_addr
);
10028 WRITE_VREG(HEVC_MPRED_MV_WPTR
,
10029 pbi
->s1_mpred_mv_wr_start_addr
);
10031 WRITE_VREG(HEVC_MPRED_MV_RD_START_ADDR
,
10032 pbi
->s1_mpred_mv_wr_start_addr_pre
);
10033 WRITE_VREG(HEVC_MPRED_MV_RPTR
,
10034 pbi
->s1_mpred_mv_wr_start_addr_pre
);
10036 WRITE_VREG(HEVC_MPRED_MV_RD_END_ADDR
,
10037 mpred_mv_rd_end_addr
);
10040 clear_mpred_hw(pbi
);
10042 if (!params
->p
.show_existing_frame
) {
10043 pbi
->s1_mpred_mv_wr_start_addr_pre
=
10044 pbi
->s1_mpred_mv_wr_start_addr
;
10045 pbi
->s1_last_show_frame
=
10046 params
->p
.show_frame
;
10047 if (pbi
->s1_mv_buf_index_pre_pre
!= MV_BUFFER_NUM
)
10048 put_mv_buf(pbi
, &pbi
->s1_mv_buf_index_pre_pre
);
10049 pbi
->s1_mv_buf_index_pre_pre
=
10050 pbi
->s1_mv_buf_index_pre
;
10051 pbi
->s1_mv_buf_index_pre
= pbi
->s1_mv_buf_index
;
10053 put_mv_buf(pbi
, &pbi
->s1_mv_buf_index
);
10056 static void vp9_s1_work(struct work_struct
*s1_work
)
10058 struct VP9Decoder_s
*pbi
= container_of(s1_work
,
10059 struct VP9Decoder_s
, s1_work
);
10060 vp9_print(pbi
, PRINT_FLAG_VDEC_DETAIL
,
10061 "%s dec_s1_result %d\n",
10063 pbi
->dec_s1_result
);
10065 #ifdef FB_DECODING_TEST_SCHEDULE
10066 if (pbi
->dec_s1_result
==
10067 DEC_S1_RESULT_TEST_TRIGGER_DONE
) {
10068 pbi
->s1_test_cmd
= TEST_SET_PIC_DONE
;
10069 WRITE_VREG(HEVC_ASSIST_MBOX0_IRQ_REG
, 0x1);
10072 if (pbi
->dec_s1_result
== DEC_S1_RESULT_DONE
||
10073 pbi
->dec_s1_result
== DEC_S1_RESULT_FORCE_EXIT
) {
10075 vdec_core_finish_run(hw_to_vdec(pbi
),
10076 CORE_MASK_HEVC_FRONT
);
10078 trigger_schedule(pbi
);
10079 /*pbi->dec_s1_result = DEC_S1_RESULT_NONE;*/
10084 static void run_back(struct vdec_s
*vdec
)
10086 struct VP9Decoder_s
*pbi
=
10087 (struct VP9Decoder_s
*)vdec
->private;
10089 run2_count
[pbi
->index
]++;
10090 if (debug
& PRINT_FLAG_VDEC_STATUS
) {
10094 pbi
->run2_busy
= 1;
10095 #ifndef FB_DECODING_TEST_SCHEDULE
10096 fb_reset_core(vdec
, HW_MASK_BACK
);
10098 vvp9_prot_init(pbi
, HW_MASK_BACK
);
10100 vp9_recycle_mmu_buf_tail(pbi
);
10102 if (pbi
->frame_count
> 0)
10103 vp9_bufmgr_postproc(pbi
);
10105 if (get_s2_buf(pbi
) >= 0) {
10106 for (i
= 0; i
< (RPM_END
- RPM_BEGIN
); i
+= 4) {
10108 for (ii
= 0; ii
< 4; ii
++)
10109 vp9_param
.l
.data
[i
+ ii
] =
10110 pbi
->s2_buf
->rpm
[i
+ 3 - ii
];
10112 #ifndef FB_DECODING_TEST_SCHEDULE
10113 WRITE_VREG(HEVC_ASSIST_FBD_MMU_MAP_ADDR
,
10114 pbi
->stage_mmu_map_phy_addr
+
10115 pbi
->s2_buf
->index
* STAGE_MMU_MAP_SIZE
);
10117 continue_decoding(pbi
);
10119 pbi
->run2_busy
= 0;
10123 static void run(struct vdec_s
*vdec
, unsigned long mask
,
10124 void (*callback
)(struct vdec_s
*, void *), void *arg
)
10126 struct VP9Decoder_s
*pbi
=
10127 (struct VP9Decoder_s
*)vdec
->private;
10130 PRINT_FLAG_VDEC_DETAIL
, "%s mask %lx\r\n",
10133 run_count
[pbi
->index
]++;
10134 pbi
->vdec_cb_arg
= arg
;
10135 pbi
->vdec_cb
= callback
;
10136 #ifdef SUPPORT_FB_DECODING
10137 if ((mask
& CORE_MASK_HEVC
) ||
10138 (mask
& CORE_MASK_HEVC_FRONT
))
10141 if ((pbi
->used_stage_buf_num
> 0)
10142 && (mask
& CORE_MASK_HEVC_BACK
))
10149 static void init_frame_bufs(struct VP9Decoder_s
*pbi
)
10151 struct vdec_s
*vdec
= hw_to_vdec(pbi
);
10152 struct VP9_Common_s
*const cm
= &pbi
->common
;
10153 struct RefCntBuffer_s
*const frame_bufs
= cm
->buffer_pool
->frame_bufs
;
10156 for (i
= 0; i
< pbi
->used_buf_num
; ++i
) {
10157 frame_bufs
[i
].ref_count
= 0;
10158 frame_bufs
[i
].buf
.vf_ref
= 0;
10159 frame_bufs
[i
].buf
.decode_idx
= 0;
10160 frame_bufs
[i
].buf
.cma_alloc_addr
= 0;
10161 frame_bufs
[i
].buf
.index
= i
;
10164 if (vdec
->parallel_dec
== 1) {
10165 for (i
= 0; i
< FRAME_BUFFERS
; i
++) {
10166 vdec
->free_canvas_ex
10167 (pbi
->common
.buffer_pool
->frame_bufs
[i
].buf
.y_canvas_index
,
10169 vdec
->free_canvas_ex
10170 (pbi
->common
.buffer_pool
->frame_bufs
[i
].buf
.uv_canvas_index
,
10176 static void reset(struct vdec_s
*vdec
)
10178 struct VP9Decoder_s
*pbi
=
10179 (struct VP9Decoder_s
*)vdec
->private;
10181 cancel_work_sync(&pbi
->work
);
10182 if (pbi
->stat
& STAT_VDEC_RUN
) {
10184 pbi
->stat
&= ~STAT_VDEC_RUN
;
10187 if (pbi
->stat
& STAT_TIMER_ARM
) {
10188 del_timer_sync(&pbi
->timer
);
10189 pbi
->stat
&= ~STAT_TIMER_ARM
;
10191 pbi
->dec_result
= DEC_RESULT_NONE
;
10192 reset_process_time(pbi
);
10193 vp9_local_uninit(pbi
);
10194 if (vvp9_local_init(pbi
) < 0)
10195 vp9_print(pbi
, 0, "%s local_init failed \r\n", __func__
);
10196 init_frame_bufs(pbi
);
10200 vp9_print(pbi
, PRINT_FLAG_VDEC_DETAIL
, "%s\r\n", __func__
);
10203 static irqreturn_t
vp9_irq_cb(struct vdec_s
*vdec
, int irq
)
10205 struct VP9Decoder_s
*pbi
=
10206 (struct VP9Decoder_s
*)vdec
->private;
10207 return vvp9_isr(0, pbi
);
10210 static irqreturn_t
vp9_threaded_irq_cb(struct vdec_s
*vdec
, int irq
)
10212 struct VP9Decoder_s
*pbi
=
10213 (struct VP9Decoder_s
*)vdec
->private;
10214 return vvp9_isr_thread_fn(0, pbi
);
10217 static void vp9_dump_state(struct vdec_s
*vdec
)
10219 struct VP9Decoder_s
*pbi
=
10220 (struct VP9Decoder_s
*)vdec
->private;
10221 struct VP9_Common_s
*const cm
= &pbi
->common
;
10223 vp9_print(pbi
, 0, "====== %s\n", __func__
);
10226 "width/height (%d/%d), used_buf_num %d\n",
10233 "is_framebase(%d), eos %d, dec_result 0x%x dec_frm %d disp_frm %d run %d not_run_ready %d input_empty %d low_latency %d no_head %d \n",
10234 input_frame_based(vdec
),
10237 decode_frame_count
[pbi
->index
],
10238 display_frame_count
[pbi
->index
],
10239 run_count
[pbi
->index
],
10240 not_run_ready
[pbi
->index
],
10241 input_empty
[pbi
->index
],
10242 pbi
->low_latency_flag
,
10246 if (vf_get_receiver(vdec
->vf_provider_name
)) {
10247 enum receviver_start_e state
=
10248 vf_notify_receiver(vdec
->vf_provider_name
,
10249 VFRAME_EVENT_PROVIDER_QUREY_STATE
,
10252 "\nreceiver(%s) state %d\n",
10253 vdec
->vf_provider_name
,
10258 "%s, newq(%d/%d), dispq(%d/%d), vf prepare/get/put (%d/%d/%d), free_buf_count %d (min %d for run_ready)\n",
10260 kfifo_len(&pbi
->newframe_q
),
10262 kfifo_len(&pbi
->display_q
),
10267 get_free_buf_count(pbi
),
10268 run_ready_min_buf_num
10271 dump_pic_list(pbi
);
10273 for (i
= 0; i
< MAX_BUF_NUM
; i
++) {
10275 "mv_Buf(%d) start_adr 0x%x size 0x%x used %d\n",
10277 pbi
->m_mv_BUF
[i
].start_adr
,
10278 pbi
->m_mv_BUF
[i
].size
,
10279 pbi
->m_mv_BUF
[i
].used_flag
);
10283 "HEVC_DEC_STATUS_REG=0x%x\n",
10284 READ_VREG(HEVC_DEC_STATUS_REG
));
10286 "HEVC_MPC_E=0x%x\n",
10287 READ_VREG(HEVC_MPC_E
));
10289 "DECODE_MODE=0x%x\n",
10290 READ_VREG(DECODE_MODE
));
10292 "NAL_SEARCH_CTL=0x%x\n",
10293 READ_VREG(NAL_SEARCH_CTL
));
10295 "HEVC_PARSER_LCU_START=0x%x\n",
10296 READ_VREG(HEVC_PARSER_LCU_START
));
10298 "HEVC_DECODE_SIZE=0x%x\n",
10299 READ_VREG(HEVC_DECODE_SIZE
));
10301 "HEVC_SHIFT_BYTE_COUNT=0x%x\n",
10302 READ_VREG(HEVC_SHIFT_BYTE_COUNT
));
10304 "HEVC_STREAM_START_ADDR=0x%x\n",
10305 READ_VREG(HEVC_STREAM_START_ADDR
));
10307 "HEVC_STREAM_END_ADDR=0x%x\n",
10308 READ_VREG(HEVC_STREAM_END_ADDR
));
10310 "HEVC_STREAM_LEVEL=0x%x\n",
10311 READ_VREG(HEVC_STREAM_LEVEL
));
10313 "HEVC_STREAM_WR_PTR=0x%x\n",
10314 READ_VREG(HEVC_STREAM_WR_PTR
));
10316 "HEVC_STREAM_RD_PTR=0x%x\n",
10317 READ_VREG(HEVC_STREAM_RD_PTR
));
10319 "PARSER_VIDEO_RP=0x%x\n",
10320 READ_PARSER_REG(PARSER_VIDEO_RP
));
10322 "PARSER_VIDEO_WP=0x%x\n",
10323 READ_PARSER_REG(PARSER_VIDEO_WP
));
10325 if (input_frame_based(vdec
) &&
10326 (debug
& PRINT_FLAG_VDEC_DATA
)
10329 if (pbi
->chunk
&& pbi
->chunk
->block
&&
10330 pbi
->chunk
->size
> 0) {
10333 if (!pbi
->chunk
->block
->is_mapped
)
10334 data
= codec_mm_vmap(
10335 pbi
->chunk
->block
->start
+
10336 pbi
->chunk
->offset
,
10339 data
= ((u8
*)pbi
->chunk
->block
->start_virt
)
10340 + pbi
->chunk
->offset
;
10342 "frame data size 0x%x\n",
10344 for (jj
= 0; jj
< pbi
->chunk
->size
; jj
++) {
10345 if ((jj
& 0xf) == 0)
10348 vp9_print_cont(pbi
, 0,
10349 "%02x ", data
[jj
]);
10350 if (((jj
+ 1) & 0xf) == 0)
10351 vp9_print_cont(pbi
, 0,
10355 if (!pbi
->chunk
->block
->is_mapped
)
10356 codec_mm_unmap_phyaddr(data
);
10362 static int ammvdec_vp9_probe(struct platform_device
*pdev
)
10364 struct vdec_s
*pdata
= *(struct vdec_s
**)pdev
->dev
.platform_data
;
10367 struct vframe_content_light_level_s content_light_level
;
10368 struct vframe_master_display_colour_s vf_dp
;
10370 struct BUF_s BUF
[MAX_BUF_NUM
];
10371 struct VP9Decoder_s
*pbi
= NULL
;
10372 pr_debug("%s\n", __func__
);
10374 if (pdata
== NULL
) {
10375 pr_info("\nammvdec_vp9 memory resource undefined.\n");
10378 /*pbi = (struct VP9Decoder_s *)devm_kzalloc(&pdev->dev,
10379 sizeof(struct VP9Decoder_s), GFP_KERNEL);*/
10380 memset(&vf_dp
, 0, sizeof(struct vframe_master_display_colour_s
));
10381 pbi
= vmalloc(sizeof(struct VP9Decoder_s
));
10383 pr_info("\nammvdec_vp9 device data allocation failed\n");
10386 memset(pbi
, 0, sizeof(struct VP9Decoder_s
));
10388 /* the ctx from v4l2 driver. */
10389 pbi
->v4l2_ctx
= pdata
->private;
10391 pdata
->private = pbi
;
10392 pdata
->dec_status
= vvp9_dec_status
;
10393 /* pdata->set_trickmode = set_trickmode; */
10394 pdata
->run_ready
= run_ready
;
10396 pdata
->reset
= reset
;
10397 pdata
->irq_handler
= vp9_irq_cb
;
10398 pdata
->threaded_irq_handler
= vp9_threaded_irq_cb
;
10399 pdata
->dump_state
= vp9_dump_state
;
10401 memcpy(&BUF
[0], &pbi
->m_BUF
[0], sizeof(struct BUF_s
) * MAX_BUF_NUM
);
10402 memcpy(&pbi
->m_BUF
[0], &BUF
[0], sizeof(struct BUF_s
) * MAX_BUF_NUM
);
10404 pbi
->index
= pdev
->id
;
10406 if (pdata
->use_vfm_path
)
10407 snprintf(pdata
->vf_provider_name
, VDEC_PROVIDER_NAME_SIZE
,
10408 VFM_DEC_PROVIDER_NAME
);
10410 snprintf(pdata
->vf_provider_name
, VDEC_PROVIDER_NAME_SIZE
,
10411 MULTI_INSTANCE_PROVIDER_NAME
".%02x", pdev
->id
& 0xff);
10413 vf_provider_init(&pdata
->vframe_provider
, pdata
->vf_provider_name
,
10414 &vvp9_vf_provider
, pbi
);
10416 pbi
->provider_name
= pdata
->vf_provider_name
;
10417 platform_set_drvdata(pdev
, pdata
);
10419 pbi
->platform_dev
= pdev
;
10420 pbi
->video_signal_type
= 0;
10421 pbi
->m_ins_flag
= 1;
10422 if (get_cpu_major_id() < AM_MESON_CPU_MAJOR_ID_TXLX
)
10423 pbi
->stat
|= VP9_TRIGGER_FRAME_ENABLE
;
10425 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_SM1
) {
10426 pbi
->max_pic_w
= 8192;
10427 pbi
->max_pic_h
= 4608;
10429 pbi
->max_pic_w
= 4096;
10430 pbi
->max_pic_h
= 2304;
10433 if ((debug
& IGNORE_PARAM_FROM_CONFIG
) == 0 &&
10434 pdata
->config_len
) {
10435 #ifdef MULTI_INSTANCE_SUPPORT
10436 int vp9_buf_width
= 0;
10437 int vp9_buf_height
= 0;
10438 /*use ptr config for doubel_write_mode, etc*/
10439 vp9_print(pbi
, 0, "pdata->config=%s\n", pdata
->config
);
10440 if (get_config_int(pdata
->config
, "vp9_double_write_mode",
10442 pbi
->double_write_mode
= config_val
;
10444 pbi
->double_write_mode
= double_write_mode
;
10446 if (get_config_int(pdata
->config
, "save_buffer_mode",
10448 pbi
->save_buffer_mode
= config_val
;
10450 pbi
->save_buffer_mode
= 0;
10451 if (get_config_int(pdata
->config
, "vp9_buf_width",
10452 &config_val
) == 0) {
10453 vp9_buf_width
= config_val
;
10455 if (get_config_int(pdata
->config
, "vp9_buf_height",
10456 &config_val
) == 0) {
10457 vp9_buf_height
= config_val
;
10460 if (get_config_int(pdata
->config
, "no_head",
10462 pbi
->no_head
= config_val
;
10464 pbi
->no_head
= no_head
;
10466 /*use ptr config for max_pic_w, etc*/
10467 if (get_config_int(pdata
->config
, "vp9_max_pic_w",
10468 &config_val
) == 0) {
10469 pbi
->max_pic_w
= config_val
;
10471 if (get_config_int(pdata
->config
, "vp9_max_pic_h",
10472 &config_val
) == 0) {
10473 pbi
->max_pic_h
= config_val
;
10475 if ((pbi
->max_pic_w
* pbi
->max_pic_h
)
10476 < (vp9_buf_width
* vp9_buf_height
)) {
10477 pbi
->max_pic_w
= vp9_buf_width
;
10478 pbi
->max_pic_h
= vp9_buf_height
;
10479 vp9_print(pbi
, 0, "use buf resolution\n");
10482 if (get_config_int(pdata
->config
,
10483 "parm_v4l_codec_enable",
10485 pbi
->is_used_v4l
= config_val
;
10487 if (get_config_int(pdata
->config
,
10488 "parm_v4l_buffer_margin",
10490 pbi
->dynamic_buf_num_margin
= config_val
;
10492 if (get_config_int(pdata
->config
,
10493 "parm_v4l_canvas_mem_mode",
10495 pbi
->mem_map_mode
= config_val
;
10497 if (get_config_int(pdata
->config
, "HDRStaticInfo",
10498 &vf_dp
.present_flag
) == 0
10499 && vf_dp
.present_flag
== 1) {
10500 get_config_int(pdata
->config
, "mG.x",
10501 &vf_dp
.primaries
[0][0]);
10502 get_config_int(pdata
->config
, "mG.y",
10503 &vf_dp
.primaries
[0][1]);
10504 get_config_int(pdata
->config
, "mB.x",
10505 &vf_dp
.primaries
[1][0]);
10506 get_config_int(pdata
->config
, "mB.y",
10507 &vf_dp
.primaries
[1][1]);
10508 get_config_int(pdata
->config
, "mR.x",
10509 &vf_dp
.primaries
[2][0]);
10510 get_config_int(pdata
->config
, "mR.y",
10511 &vf_dp
.primaries
[2][1]);
10512 get_config_int(pdata
->config
, "mW.x",
10513 &vf_dp
.white_point
[0]);
10514 get_config_int(pdata
->config
, "mW.y",
10515 &vf_dp
.white_point
[1]);
10516 get_config_int(pdata
->config
, "mMaxDL",
10517 &vf_dp
.luminance
[0]);
10518 get_config_int(pdata
->config
, "mMinDL",
10519 &vf_dp
.luminance
[1]);
10520 vf_dp
.content_light_level
.present_flag
= 1;
10521 get_config_int(pdata
->config
, "mMaxCLL",
10522 &content_light_level
.max_content
);
10523 get_config_int(pdata
->config
, "mMaxFALL",
10524 &content_light_level
.max_pic_average
);
10525 vf_dp
.content_light_level
= content_light_level
;
10526 pbi
->video_signal_type
= (1 << 29)
10527 | (5 << 26) /* unspecified */
10528 | (0 << 25) /* limit */
10529 | (1 << 24) /* color available */
10530 | (9 << 16) /* 2020 */
10531 | (16 << 8) /* 2084 */
10532 | (9 << 0); /* 2020 */
10534 pbi
->vf_dp
= vf_dp
;
10538 /*pbi->vvp9_amstream_dec_info.width = 0;
10539 pbi->vvp9_amstream_dec_info.height = 0;
10540 pbi->vvp9_amstream_dec_info.rate = 30;*/
10541 pbi
->double_write_mode
= double_write_mode
;
10544 if (!pbi
->is_used_v4l
) {
10545 pbi
->mem_map_mode
= mem_map_mode
;
10548 if (is_oversize(pbi
->max_pic_w
, pbi
->max_pic_h
)) {
10549 pr_err("over size: %dx%d, probe failed\n",
10550 pbi
->max_pic_w
, pbi
->max_pic_h
);
10553 pbi
->mmu_enable
= 1;
10554 video_signal_type
= pbi
->video_signal_type
;
10556 if (pdata
->sys_info
) {
10557 pbi
->vvp9_amstream_dec_info
= *pdata
->sys_info
;
10559 pbi
->vvp9_amstream_dec_info
.width
= 0;
10560 pbi
->vvp9_amstream_dec_info
.height
= 0;
10561 pbi
->vvp9_amstream_dec_info
.rate
= 30;
10563 pbi
->low_latency_flag
= 1;
10566 "no_head %d low_latency %d\n",
10567 pbi
->no_head
, pbi
->low_latency_flag
);
10569 pbi
->buf_start
= pdata
->mem_start
;
10570 pbi
->buf_size
= pdata
->mem_end
- pdata
->mem_start
+ 1;
10572 if (amvdec_vp9_mmu_init(pbi
) < 0) {
10573 pr_err("vp9 alloc bmmu box failed!!\n");
10574 /* devm_kfree(&pdev->dev, (void *)pbi); */
10575 vfree((void *)pbi
);
10576 pdata
->dec_status
= NULL
;
10580 pbi
->cma_alloc_count
= PAGE_ALIGN(work_buf_size
) / PAGE_SIZE
;
10581 ret
= decoder_bmmu_box_alloc_buf_phy(pbi
->bmmu_box
, WORK_SPACE_BUF_ID
,
10582 pbi
->cma_alloc_count
* PAGE_SIZE
, DRIVER_NAME
,
10583 &pbi
->cma_alloc_addr
);
10585 uninit_mmu_buffers(pbi
);
10586 /* devm_kfree(&pdev->dev, (void *)pbi); */
10587 vfree((void *)pbi
);
10588 pdata
->dec_status
= NULL
;
10591 pbi
->buf_start
= pbi
->cma_alloc_addr
;
10592 pbi
->buf_size
= work_buf_size
;
10595 pbi
->init_flag
= 0;
10596 pbi
->first_sc_checked
= 0;
10597 pbi
->fatal_error
= 0;
10598 pbi
->show_frame_num
= 0;
10601 pr_info("===VP9 decoder mem resource 0x%lx size 0x%x\n",
10606 pbi
->cma_dev
= pdata
->cma_dev
;
10607 if (vvp9_init(pdata
) < 0) {
10608 pr_info("\namvdec_vp9 init failed.\n");
10609 vp9_local_uninit(pbi
);
10610 uninit_mmu_buffers(pbi
);
10611 /* devm_kfree(&pdev->dev, (void *)pbi); */
10612 vfree((void *)pbi
);
10613 pdata
->dec_status
= NULL
;
10616 vdec_set_prepare_level(pdata
, start_decode_buf_level
);
10617 hevc_source_changed(VFORMAT_VP9
,
10619 #ifdef SUPPORT_FB_DECODING
10620 if (pbi
->used_stage_buf_num
> 0)
10621 vdec_core_request(pdata
,
10622 CORE_MASK_HEVC_FRONT
| CORE_MASK_HEVC_BACK
);
10624 vdec_core_request(pdata
, CORE_MASK_VDEC_1
| CORE_MASK_HEVC
10625 | CORE_MASK_HEVC_FRONT
| CORE_MASK_HEVC_BACK
10626 | CORE_MASK_COMBINE
);
10628 if (pdata
->parallel_dec
== 1)
10629 vdec_core_request(pdata
, CORE_MASK_HEVC
);
10631 vdec_core_request(pdata
, CORE_MASK_VDEC_1
| CORE_MASK_HEVC
10632 | CORE_MASK_COMBINE
);
10634 pbi
->pic_list_init_done2
= true;
10638 static int ammvdec_vp9_remove(struct platform_device
*pdev
)
10640 struct VP9Decoder_s
*pbi
= (struct VP9Decoder_s
*)
10641 (((struct vdec_s
*)(platform_get_drvdata(pdev
)))->private);
10642 struct vdec_s
*vdec
= hw_to_vdec(pbi
);
10645 pr_info("amvdec_vp9_remove\n");
10649 #ifdef SUPPORT_FB_DECODING
10650 vdec_core_release(hw_to_vdec(pbi
), CORE_MASK_VDEC_1
| CORE_MASK_HEVC
10651 | CORE_MASK_HEVC_FRONT
| CORE_MASK_HEVC_BACK
10654 if (vdec
->parallel_dec
== 1)
10655 vdec_core_release(hw_to_vdec(pbi
), CORE_MASK_HEVC
);
10657 vdec_core_release(hw_to_vdec(pbi
), CORE_MASK_VDEC_1
| CORE_MASK_HEVC
);
10659 vdec_set_status(hw_to_vdec(pbi
), VDEC_STATUS_DISCONNECTED
);
10661 if (vdec
->parallel_dec
== 1) {
10662 for (i
= 0; i
< FRAME_BUFFERS
; i
++) {
10663 vdec
->free_canvas_ex
10664 (pbi
->common
.buffer_pool
->frame_bufs
[i
].buf
.y_canvas_index
,
10666 vdec
->free_canvas_ex
10667 (pbi
->common
.buffer_pool
->frame_bufs
[i
].buf
.uv_canvas_index
,
10674 pr_info("pts missed %ld, pts hit %ld, duration %d\n",
10675 pbi
->pts_missed
, pbi
->pts_hit
, pbi
->frame_dur
);
10679 /* devm_kfree(&pdev->dev, (void *)pbi); */
10680 vfree((void *)pbi
);
10684 static struct platform_driver ammvdec_vp9_driver
= {
10685 .probe
= ammvdec_vp9_probe
,
10686 .remove
= ammvdec_vp9_remove
,
10688 .name
= MULTI_DRIVER_NAME
,
10695 static struct mconfig vp9_configs
[] = {
10696 MC_PU32("bit_depth_luma", &bit_depth_luma
),
10697 MC_PU32("bit_depth_chroma", &bit_depth_chroma
),
10698 MC_PU32("frame_width", &frame_width
),
10699 MC_PU32("frame_height", &frame_height
),
10700 MC_PU32("debug", &debug
),
10701 MC_PU32("radr", &radr
),
10702 MC_PU32("rval", &rval
),
10703 MC_PU32("pop_shorts", &pop_shorts
),
10704 MC_PU32("dbg_cmd", &dbg_cmd
),
10705 MC_PU32("dbg_skip_decode_index", &dbg_skip_decode_index
),
10706 MC_PU32("endian", &endian
),
10707 MC_PU32("step", &step
),
10708 MC_PU32("udebug_flag", &udebug_flag
),
10709 MC_PU32("decode_pic_begin", &decode_pic_begin
),
10710 MC_PU32("slice_parse_begin", &slice_parse_begin
),
10711 MC_PU32("i_only_flag", &i_only_flag
),
10712 MC_PU32("error_handle_policy", &error_handle_policy
),
10713 MC_PU32("buf_alloc_width", &buf_alloc_width
),
10714 MC_PU32("buf_alloc_height", &buf_alloc_height
),
10715 MC_PU32("buf_alloc_depth", &buf_alloc_depth
),
10716 MC_PU32("buf_alloc_size", &buf_alloc_size
),
10717 MC_PU32("buffer_mode", &buffer_mode
),
10718 MC_PU32("buffer_mode_dbg", &buffer_mode_dbg
),
10719 MC_PU32("max_buf_num", &max_buf_num
),
10720 MC_PU32("dynamic_buf_num_margin", &dynamic_buf_num_margin
),
10721 MC_PU32("mem_map_mode", &mem_map_mode
),
10722 MC_PU32("double_write_mode", &double_write_mode
),
10723 MC_PU32("enable_mem_saving", &enable_mem_saving
),
10724 MC_PU32("force_w_h", &force_w_h
),
10725 MC_PU32("force_fps", &force_fps
),
10726 MC_PU32("max_decoding_time", &max_decoding_time
),
10727 MC_PU32("on_no_keyframe_skiped", &on_no_keyframe_skiped
),
10728 MC_PU32("start_decode_buf_level", &start_decode_buf_level
),
10729 MC_PU32("decode_timeout_val", &decode_timeout_val
),
10730 MC_PU32("vp9_max_pic_w", &vp9_max_pic_w
),
10731 MC_PU32("vp9_max_pic_h", &vp9_max_pic_h
),
10733 static struct mconfig_node vp9_node
;
10735 static int __init
amvdec_vp9_driver_init_module(void)
10738 struct BuffInfo_s
*p_buf_info
;
10740 if (vdec_is_support_4k()) {
10741 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_SM1
)
10742 p_buf_info
= &amvvp9_workbuff_spec
[2];
10744 p_buf_info
= &amvvp9_workbuff_spec
[1];
10746 p_buf_info
= &amvvp9_workbuff_spec
[0];
10748 init_buff_spec(NULL
, p_buf_info
);
10750 (p_buf_info
->end_adr
- p_buf_info
->start_adr
10751 + 0xffff) & (~0xffff);
10753 pr_debug("amvdec_vp9 module init\n");
10755 error_handle_policy
= 0;
10757 #ifdef ERROR_HANDLE_DEBUG
10758 dbg_nal_skip_flag
= 0;
10759 dbg_nal_skip_count
= 0;
10762 decode_pic_begin
= 0;
10763 slice_parse_begin
= 0;
10765 buf_alloc_size
= 0;
10766 #ifdef MULTI_INSTANCE_SUPPORT
10767 if (platform_driver_register(&ammvdec_vp9_driver
))
10768 pr_err("failed to register ammvdec_vp9 driver\n");
10771 if (platform_driver_register(&amvdec_vp9_driver
)) {
10772 pr_err("failed to register amvdec_vp9 driver\n");
10776 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_SM1
) {
10777 amvdec_vp9_profile
.profile
=
10778 "8k, 10bit, dwrite, compressed, no_head";
10779 } else if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_GXL
10780 /*&& get_cpu_major_id() != MESON_CPU_MAJOR_ID_GXLX*/
10781 && get_cpu_major_id() != AM_MESON_CPU_MAJOR_ID_TXL
) {
10782 if (get_cpu_major_id() < AM_MESON_CPU_MAJOR_ID_TXLX
) {
10783 if (vdec_is_support_4k())
10784 amvdec_vp9_profile
.profile
=
10785 "4k, 10bit, dwrite, compressed";
10787 amvdec_vp9_profile
.profile
=
10788 "10bit, dwrite, compressed";
10790 if (vdec_is_support_4k())
10791 amvdec_vp9_profile
.profile
=
10792 "4k, 10bit, dwrite, compressed, no_head";
10794 amvdec_vp9_profile
.profile
=
10795 "10bit, dwrite, compressed, no_head";
10799 amvdec_vp9_profile
.name
= "vp9_unsupport";
10802 if (get_cpu_major_id() >= AM_MESON_CPU_MAJOR_ID_G12A
)
10803 max_buf_num
= MAX_BUF_NUM_LESS
;
10805 vcodec_profile_register(&amvdec_vp9_profile
);
10806 amvdec_vp9_profile_mult
= amvdec_vp9_profile
;
10807 amvdec_vp9_profile_mult
.name
= "mvp9";
10808 vcodec_profile_register(&amvdec_vp9_profile_mult
);
10809 INIT_REG_NODE_CONFIGS("media.decoder", &vp9_node
,
10810 "vp9", vp9_configs
, CONFIG_FOR_RW
);
10815 static void __exit
amvdec_vp9_driver_remove_module(void)
10817 pr_debug("amvdec_vp9 module remove.\n");
10818 #ifdef MULTI_INSTANCE_SUPPORT
10819 platform_driver_unregister(&ammvdec_vp9_driver
);
10821 platform_driver_unregister(&amvdec_vp9_driver
);
10824 /****************************************/
10826 module_param(bit_depth_luma
, uint
, 0664);
10827 MODULE_PARM_DESC(bit_depth_luma
, "\n amvdec_vp9 bit_depth_luma\n");
10829 module_param(bit_depth_chroma
, uint
, 0664);
10830 MODULE_PARM_DESC(bit_depth_chroma
, "\n amvdec_vp9 bit_depth_chroma\n");
10832 module_param(frame_width
, uint
, 0664);
10833 MODULE_PARM_DESC(frame_width
, "\n amvdec_vp9 frame_width\n");
10835 module_param(frame_height
, uint
, 0664);
10836 MODULE_PARM_DESC(frame_height
, "\n amvdec_vp9 frame_height\n");
10838 module_param(debug
, uint
, 0664);
10839 MODULE_PARM_DESC(debug
, "\n amvdec_vp9 debug\n");
10841 module_param(radr
, uint
, 0664);
10842 MODULE_PARM_DESC(radr
, "\n radr\n");
10844 module_param(rval
, uint
, 0664);
10845 MODULE_PARM_DESC(rval
, "\n rval\n");
10847 module_param(pop_shorts
, uint
, 0664);
10848 MODULE_PARM_DESC(pop_shorts
, "\n rval\n");
10850 module_param(dbg_cmd
, uint
, 0664);
10851 MODULE_PARM_DESC(dbg_cmd
, "\n dbg_cmd\n");
10853 module_param(dbg_skip_decode_index
, uint
, 0664);
10854 MODULE_PARM_DESC(dbg_skip_decode_index
, "\n dbg_skip_decode_index\n");
10856 module_param(endian
, uint
, 0664);
10857 MODULE_PARM_DESC(endian
, "\n rval\n");
10859 module_param(step
, uint
, 0664);
10860 MODULE_PARM_DESC(step
, "\n amvdec_vp9 step\n");
10862 module_param(decode_pic_begin
, uint
, 0664);
10863 MODULE_PARM_DESC(decode_pic_begin
, "\n amvdec_vp9 decode_pic_begin\n");
10865 module_param(slice_parse_begin
, uint
, 0664);
10866 MODULE_PARM_DESC(slice_parse_begin
, "\n amvdec_vp9 slice_parse_begin\n");
10868 module_param(i_only_flag
, uint
, 0664);
10869 MODULE_PARM_DESC(i_only_flag
, "\n amvdec_vp9 i_only_flag\n");
10871 module_param(low_latency_flag
, uint
, 0664);
10872 MODULE_PARM_DESC(low_latency_flag
, "\n amvdec_vp9 low_latency_flag\n");
10874 module_param(no_head
, uint
, 0664);
10875 MODULE_PARM_DESC(no_head
, "\n amvdec_vp9 no_head\n");
10877 module_param(error_handle_policy
, uint
, 0664);
10878 MODULE_PARM_DESC(error_handle_policy
, "\n amvdec_vp9 error_handle_policy\n");
10880 module_param(buf_alloc_width
, uint
, 0664);
10881 MODULE_PARM_DESC(buf_alloc_width
, "\n buf_alloc_width\n");
10883 module_param(buf_alloc_height
, uint
, 0664);
10884 MODULE_PARM_DESC(buf_alloc_height
, "\n buf_alloc_height\n");
10886 module_param(buf_alloc_depth
, uint
, 0664);
10887 MODULE_PARM_DESC(buf_alloc_depth
, "\n buf_alloc_depth\n");
10889 module_param(buf_alloc_size
, uint
, 0664);
10890 MODULE_PARM_DESC(buf_alloc_size
, "\n buf_alloc_size\n");
10892 module_param(buffer_mode
, uint
, 0664);
10893 MODULE_PARM_DESC(buffer_mode
, "\n buffer_mode\n");
10895 module_param(buffer_mode_dbg
, uint
, 0664);
10896 MODULE_PARM_DESC(buffer_mode_dbg
, "\n buffer_mode_dbg\n");
10898 module_param(max_buf_num
, uint
, 0664);
10899 MODULE_PARM_DESC(max_buf_num
, "\n max_buf_num\n");
10901 module_param(dynamic_buf_num_margin
, uint
, 0664);
10902 MODULE_PARM_DESC(dynamic_buf_num_margin
, "\n dynamic_buf_num_margin\n");
10904 module_param(mv_buf_margin
, uint
, 0664);
10905 MODULE_PARM_DESC(mv_buf_margin
, "\n mv_buf_margin\n");
10907 module_param(run_ready_min_buf_num
, uint
, 0664);
10908 MODULE_PARM_DESC(run_ready_min_buf_num
, "\n run_ready_min_buf_num\n");
10912 module_param(mem_map_mode
, uint
, 0664);
10913 MODULE_PARM_DESC(mem_map_mode
, "\n mem_map_mode\n");
10915 #ifdef SUPPORT_10BIT
10916 module_param(double_write_mode
, uint
, 0664);
10917 MODULE_PARM_DESC(double_write_mode
, "\n double_write_mode\n");
10919 module_param(enable_mem_saving
, uint
, 0664);
10920 MODULE_PARM_DESC(enable_mem_saving
, "\n enable_mem_saving\n");
10922 module_param(force_w_h
, uint
, 0664);
10923 MODULE_PARM_DESC(force_w_h
, "\n force_w_h\n");
10926 module_param(force_fps
, uint
, 0664);
10927 MODULE_PARM_DESC(force_fps
, "\n force_fps\n");
10929 module_param(max_decoding_time
, uint
, 0664);
10930 MODULE_PARM_DESC(max_decoding_time
, "\n max_decoding_time\n");
10932 module_param(on_no_keyframe_skiped
, uint
, 0664);
10933 MODULE_PARM_DESC(on_no_keyframe_skiped
, "\n on_no_keyframe_skiped\n");
10935 module_param(mcrcc_cache_alg_flag
, uint
, 0664);
10936 MODULE_PARM_DESC(mcrcc_cache_alg_flag
, "\n mcrcc_cache_alg_flag\n");
10938 #ifdef MULTI_INSTANCE_SUPPORT
10939 module_param(start_decode_buf_level
, int, 0664);
10940 MODULE_PARM_DESC(start_decode_buf_level
,
10941 "\n vp9 start_decode_buf_level\n");
10943 module_param(decode_timeout_val
, uint
, 0664);
10944 MODULE_PARM_DESC(decode_timeout_val
,
10945 "\n vp9 decode_timeout_val\n");
10947 module_param(vp9_max_pic_w
, uint
, 0664);
10948 MODULE_PARM_DESC(vp9_max_pic_w
, "\n vp9_max_pic_w\n");
10950 module_param(vp9_max_pic_h
, uint
, 0664);
10951 MODULE_PARM_DESC(vp9_max_pic_h
, "\n vp9_max_pic_h\n");
10953 module_param_array(decode_frame_count
, uint
,
10954 &max_decode_instance_num
, 0664);
10956 module_param_array(display_frame_count
, uint
,
10957 &max_decode_instance_num
, 0664);
10959 module_param_array(max_process_time
, uint
,
10960 &max_decode_instance_num
, 0664);
10962 module_param_array(run_count
, uint
,
10963 &max_decode_instance_num
, 0664);
10965 module_param_array(input_empty
, uint
,
10966 &max_decode_instance_num
, 0664);
10968 module_param_array(not_run_ready
, uint
,
10969 &max_decode_instance_num
, 0664);
10972 #ifdef SUPPORT_FB_DECODING
10973 module_param_array(not_run2_ready
, uint
,
10974 &max_decode_instance_num
, 0664);
10976 module_param_array(run2_count
, uint
,
10977 &max_decode_instance_num
, 0664);
10979 module_param(stage_buf_num
, uint
, 0664);
10980 MODULE_PARM_DESC(stage_buf_num
, "\n amvdec_h265 stage_buf_num\n");
10983 module_param(udebug_flag
, uint
, 0664);
10984 MODULE_PARM_DESC(udebug_flag
, "\n amvdec_h265 udebug_flag\n");
10986 module_param(udebug_pause_pos
, uint
, 0664);
10987 MODULE_PARM_DESC(udebug_pause_pos
, "\n udebug_pause_pos\n");
10989 module_param(udebug_pause_val
, uint
, 0664);
10990 MODULE_PARM_DESC(udebug_pause_val
, "\n udebug_pause_val\n");
10992 module_param(udebug_pause_decode_idx
, uint
, 0664);
10993 MODULE_PARM_DESC(udebug_pause_decode_idx
, "\n udebug_pause_decode_idx\n");
10995 module_param(without_display_mode
, uint
, 0664);
10996 MODULE_PARM_DESC(without_display_mode
, "\n without_display_mode\n");
10998 module_init(amvdec_vp9_driver_init_module
);
10999 module_exit(amvdec_vp9_driver_remove_module
);
11001 MODULE_DESCRIPTION("AMLOGIC vp9 Video Decoder Driver");
11002 MODULE_LICENSE("GPL");