1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94
95
96 //-------------------------------------------------------------------------------------------------
97 // Include Files
98 //-------------------------------------------------------------------------------------------------
99 // Common Definition
100 #ifdef MSOS_TYPE_LINUX_KERNEL
101 #include <linux/string.h>
102 #else
103 #include <string.h>
104 #endif
105
106 #include "MsCommon.h"
107 #include "drvMVD_EX.h"
108 #include "drvBDMA.h"
109
110 // Internal Definition
111 #include "regMVD_EX.h"
112 #include "halMVD_EX.h"
113 #include "halVPU_EX.h"
114 #include "osalMVD_EX.h"
115 #include "mvd4_interface.h" //firmware header
116 #include "asmCPU.h"
117 #include "controller.h"
118 #include "MVD_EX_Common.h"
119 #include "halCHIP.h"
120 //#include "drvCMAPool.h"
121 #include "drvCMAPool_v2.h"
122 #if defined(MSOS_TYPE_LINUX)
123 #include "msos/linux/ion_uapi.h"
124 #include "msos/linux/mdrv_cma_pool_st.h"
125 #endif
126
127 #if (!defined(MSOS_TYPE_NUTTX) && !defined(MSOS_TYPE_OPTEE)) || defined(SUPPORT_X_MODEL_FEATURE)
128
129
130 #ifdef MSOS_TYPE_LINUX_KERNEL
131 #define VPRINTF printk
132 #else
133 #ifndef ANDROID
134 #define VPRINTF printf
135 #else
136 #include <sys/mman.h>
137 #include <cutils/ashmem.h>
138 #include <cutils/log.h>
139 #define VPRINTF ALOGD
140 #endif
141 #endif
142 //-------------------------------------------------------------------------------------------------
143 // Driver Compiler Options
144 //-------------------------------------------------------------------------------------------------
145 #define SLQ_NEW_PUSH 1
146 #define VIRTUAL_CMD_TIMEOUT 50
147 #ifdef VDEC3
148 #define v3_temp 1
149 #define v3_thinplayer 0
150 #else
151 #define v3_temp 0
152 #define v3_thinplayer 0
153 #endif
154
155 //-------------------------------------------------------------------------------------------------
156 // Local Defines
157 //-------------------------------------------------------------------------------------------------
158 #define MIU1_BASEADDR pMVDHalContext->stMiuCfg.u32Miu1BaseAddr
159 #define _PA2Offset(x) (((x)>=MIU1_BASEADDR)?(x-MIU1_BASEADDR):(x))
160
161 #ifdef MSOS_TYPE_LINUX_KERNEL
162 #include <asm/div64.h>
163 #define _90K_TO_MS_U64(x) ((x!=MVD_U64_MAX)?(do_div(x,90)):(x)) //90k counter ==> ms
164 #else
165 #define _90K_TO_MS_U64(x) ((x!=MVD_U64_MAX)?(x/=90):(x)) //90k counter ==> ms
166 #endif
167
168 #ifndef MS_ASSERT
169 #ifdef MS_DEBUG
170 #define MS_ASSERT(expr) do { \
171 if(!(expr)) \
172 printf("MVD assert fail %s %d!\n", __FILE__, __LINE__); \
173 } while(0)
174 #else
175 #define MS_ASSERT(expr)
176 #endif
177 #endif
178
179 #ifndef UNUSED
180 #define UNUSED(x) (void)(x)
181 #endif
182 //constant
183 #define MVD_PollingTimes 0x40000UL
184
185 #define MVD_DEBUGVERBAL(x) if (_u8HalDbgLevel>3) { (x); }
186 #define MVD_DEBUG_FWCMD(x) if (_u8HalDbgLevel>2) { (x); }
187 #define MVD_DEBUGINFO(x) if (_u8HalDbgLevel>1) { (x); }
188 #define MVD_DEBUGERROR(x) if (_u8HalDbgLevel>0) { (x); }
189 #define MVD_ERROR(x) x
190
191 #define RIU ((unsigned short volatile *) (u32RiuBaseAdd))
192 #define RIU8 ((unsigned char volatile *) (u32RiuBaseAdd))
193
194 #define MVDCPU_ON_MIU1 ((HAL_MVD_RegReadByte(MIU0_SEL0_H) & BIT0) == BIT0)
195 //#define MVDHW_ON_MIU1 ((HAL_MVD_RegReadByte(MIU0_SEL2_L) & BIT4) == BIT4)
196 #define MVDHW_ON_MIU0 ((HAL_MVD_RegReadByte(MIU0_SEL2_L) & BIT4) == 0 && (HAL_MVD_RegReadByte(MIU2_SEL2_L) & BIT4) == 0)
197 #define MVDHW_ON_MIU1 ((HAL_MVD_RegReadByte(MIU0_SEL2_L) & BIT4) == BIT4 && (HAL_MVD_RegReadByte(MIU2_SEL2_L) & BIT4) == 0)
198 #define MVDHW_ON_MIU2 ((HAL_MVD_RegReadByte(MIU0_SEL2_L) & BIT4) == 0 && (HAL_MVD_RegReadByte(MIU2_SEL2_L) & BIT4) == BIT4)
199
200 // MVD5
201 #define SLQ_TBL_ENTRY_LEN 0x7FFFFFFF //31-bit
202
203 #define MVD_WIDTH_ALIGN_BYTE 16
204 #define MVD_WIDTH_ALIGN_MASK (MVD_WIDTH_ALIGN_BYTE - 1)
205 #define MVD_WIDTH_ALIGN_BITS 4
206
207 #define MVD_FBNUM_DEFAULT 4
208 #define MVD_FBNUM_MAX 5
209 #define MVD_FBNUM_MIN MVD_FBNUM_DEFAULT
210
211 #define MVD_DHD_FBSIZE 0x5FA000 //Framebuffer size minimum for Dual HD: (1920*2)*1088*1.5
212 #define MVD_HD_FBSIZE 0x2FD000 //Framebuffer size minimum for High Definition
213 #define MVD4_VC1_FBSIZE_HDMIN 0xEF1000 //5 * 1920 * 1088 * 1.5 = 14.95MB
214 #define MVD4_VC1_FBSIZE_HDMIN1 0xBF4000 //4 * 1920 * 1088 * 1.5 = 11.96MB
215 #define MVD4_VC1_FBSIZE_SDMIN 0x2F7600 //5 * 720 * 576 * 1.5 = 2.97MB
216 #define MVD4_MPEG_FBSIZE_HDMIN 0xBF4000 //4 * 1920 * 1088 * 1.5 = 11.96MB
217 #define MVD4_MPEG_FBSIZE_SDMIN 0x25F800 //4 * 720 * 576 * 1.5 = 2.38MB
218
219 #define _IS_VC1(x) ((x==E_MVD_CODEC_VC1_ADV) || (x==E_MVD_CODEC_VC1_MAIN))
220
221 #define SLQ_ENTRY_LEN 8 //8-byte per entry
222
223 #define MVD_U32_MAX 0xffffffffUL
224 #define MVD_U64_MAX 0xffffffffffffffffULL
225 #define MVD_GENERAL_MAX ((size_t)(-1))
226
227 #define MAX_ADD_28BIT 0x0fffffffUL
228
229 #define SLQ_ADDR_LEN SLQ_TBL_ENTRY_LEN //Slq address length is the same as SlqTbl
230
231 //Initial value for PTS table
232 #define _INIT_ADDR MVD_U32_MAX
233 #define _INIT_LEN 0
234 #define _INIT_TIMESTAMP MVD_U32_MAX
235 #define _INIT_ID MVD_U32_MAX
236
237 #define _MS_TO_90K(x) (x*90) //ms ==> 90k counter
238 #define _90K_TO_MS(x) ((x!=MVD_U32_MAX)?(x/90):(x)) //90k counter ==> ms
239
240
241 #define MVD_DBG_STS(x) {}
242 #define _SLQTBL_DUMP_PTS FALSE//TRUE
243 #define _SLQTBL_DUMP_PUSHQ FALSE//TRUE
244 #define _SLQTBL_DUMP_PKT FALSE//TRUE
245 #define MVD_TURBO_INIT FALSE//TRUE
246
247 #define SLQ_ENTRY_MAX 1024
248 #define SLQ_ENTRY_LEN 8 //8-byte per entry
249 #define SLQ_TBL_SIZE (SLQ_ENTRY_MAX * SLQ_ENTRY_LEN)
250 #define ES_TBL_SIZE (SLQ_ENTRY_MAX * 8) //8-byte per entry
251
252 #define MVD_FW_SLQTBL_PTS_LEN 32
253
254 #define SLQ_TBL_SAFERANGE (40*SLQ_ENTRY_LEN)
255 //this should be smaller than FW's lookup range (current it's 16 entries)
256
257 #define SLQTBL_CHECKVACANCY_WATERLEVEL (44*SLQ_ENTRY_LEN)
258
259
260 #define DIVX_PATTERN 0x63643030
261 #define FLV_PATTERN 0xffff0000
262 #define MPEG_PATTERN_0 0xC6010000 //this SC just for mpeg2/4
263 #if SLQ_NEW_PUSH
264 #define SLQ_PIC_START_FLAG 0x40000000
265 #define VC1_PATTERN 0x0D010000
266 #define RCV_PATTERN 0xFF00A55A
267 #endif
268 #define VC1_PATTERN_0 0xff010000
269 #define VC1_PATTERN_1 0x0000ffff
270 #define VC1_PATTERN_2 0xffffff01
271 #define VC1_PATTERN_3 0x0000ffee
272
273 #define RCV_PATTERN_0 0x00000000
274 #define RCV_PATTERN_1 0xffffffff
275 #define RCV_PATTERN_2 0x00000000
276 #define RCV_PATTERN_3 0xeeeeeeee
277
278 #define DUMMY_PATTERN 0xBE010000
279 #define DUMMY_SIZE 0x2000 //8K
280
281 #define END_PATTERN_0 0xFF010000
282 #define END_PATTERN_1 0xDDCCBBAA
283 #define END_PATTERN_2 0xBBAAFFEE
284 #define END_PATTERN_3 0xFFEEDDCC
285 #define END_PATTERN_SIZE 256
286
287 #define SKIP_PATTERN_0 0xc5010000
288 #define SKIP_PATTERN_1 0x270608ab
289 #define SKIP_PATTERN_SIZE 8
290
291 #define CMD_TIMEOUT_MS 500
292 #define SKIP_DATA_TIMEOUT_MS 15
293
294 //Length of internal buffers
295 #define MVD_FW_IAP_BUF_LEN (0x4000UL) // 16k
296 #define MVD_FW_DP_BUF_LEN (0x80000UL) //512k
297 #define MVD_FW_MV_BUF_LEN (0x48000UL) //288K
298 //Alignment of HW buffers start address
299 #define MVD_FW_IAP_BUF_ALIGN (0x4000UL) // 16k
300 #define MVD_FW_DP_BUF_ALIGN (0x8000UL) // 32k
301 #define MVD_FW_MV_BUF_ALIGN (0x8000UL) // 32k
302
303 //Three HW buffers are allocated after framebuffer, so we need to
304 //consider these buffers when checking the available framebuffer size/number.
305 #define MVD_HW_BUF_TOTAL_LEN (MVD_FW_IAP_BUF_LEN + MVD_FW_DP_BUF_LEN + MVD_FW_MV_BUF_LEN) //u32HWBuffTotalSize
306
307 #define MVD_FW_CODE_LEN (OFFSET_BASE)//refer to the define in mvd4_interface.h
308 #define MVD_FW_CODE_LEN_V00 (0x70000UL) //length for old layout
309 #define MVD_FW_MPOOL_START_OFFSET (0x90000UL) //576K
310 #define MVD_FW_TASK_OFFSET (0x100000UL) //1M
311
312 #define MVD3_FW_VOL_INFO_BUF_LEN (0x1000UL) // 4K
313 #define MVD3_FW_FRAME_INFO_BUF_LEN (0x1000UL) // 4K
314 #define MVD3_FW_DIVX_INFO_BUF_LEN (0x1000UL) // 4K
315 #define MVD3_FW_USER_DATA_BUF_LEN (0x4000UL) // 16K
316 #define MVD3_FW_USER_DATA_BUF_BACKUP_LEN MVD3_FW_USER_DATA_BUF_LEN // 16K
317 #define MVD3_FW_SLQ_TAB_TMPBUF_LEN (0x200UL)
318 #define MVD_FW_SLQTBL_PTS_BUF_LEN (SLQ_ENTRY_MAX*MVD_FW_SLQTBL_PTS_LEN)
319 #define MVD_FW_DYN_SCALE_BUF_LEN (0x2000UL) // 8K
320 #define MVD_FW_SCALER_INFO_BUF_LEN (0x100UL) // 256bytes reserved
321 #define MVD_FW_DECFRM_INFO_BUF_LEN (0x100UL) // 256bytes reserved
322 #define MVD_FW_VBBU_TABLE_LEN (0x2000UL) // 8K
323
324 #define MVD_FW_USER_DATA_HDR_LEN (6)
325 #define MVD_FW_USER_DATA_PKT_LEN (256)
326 #define MVD_FW_USER_DATA_EXT_HDR_LEN (16)
327 #define FW_BUFF_ALIGN (0x1000) //4k align
328
329 #define SLQ_ENTRY_MAX 1024
330 #define MVD_FW_SLQTBL_PTS_LEN 32
331 #define MVD_NULLPKT_PTS MVD_U32_MAX
332
333 #define MVD_HW_MAX_PIXEL (1920*1088*61000ULL) // FHD@60p
334
335 //Get the start address, and the next start address.
336 #define GET_FW_BUFFADD(cur, size, start) \
337 do { \
338 start = cur; \
339 cur += size; \
340 } while(0)
341
342 //Get the aligned start address, and the next start address.
343 #define GET_FW_BUFFADD_ALIGN(cur, align, size, alignStart) \
344 do { \
345 cur = (MemAlign(cur, align)); \
346 GET_FW_BUFFADD(cur, size, alignStart); \
347 } while(0)
348
349 //Init command arguments
350 #define SETUP_CMDARG(x) \
351 do { \
352 x.Arg0 = 0; \
353 x.Arg1 = 0; \
354 x.Arg2 = 0; \
355 x.Arg3 = 0; \
356 x.Arg4 = 0; \
357 x.Arg5 = 0; \
358 } while(0)
359
360 //Set command arguments
361 #define SET_CMDARG(cmd, u32val, u8Num) \
362 do { \
363 cmd.Arg0 = L_WORD(u32val); \
364 cmd.Arg1 = H_WORD(u32val); \
365 cmd.Arg2 = L_DWORD(u32val); \
366 cmd.Arg3 = H_DWORD(u32val); \
367 cmd.Arg4 = 0; \
368 cmd.Arg5 = u8Num; \
369 } while(0)
370
371 #define SET_CMD_RET_FALSE(_cmdVal, _pStcmdArg) \
372 do { \
373 if (HAL_MVD_MVDCommand(_cmdVal, (_pStcmdArg)) == FALSE) \
374 { \
375 MVD_DEBUGERROR(printf("Command: 0x%x fail!!\r\n", _cmdVal)); \
376 return FALSE; \
377 } \
378 } while(0)
379
380 #define SET_CMD_RET_VOID(_cmdVal, _pStcmdArg) \
381 do { \
382 if (HAL_MVD_MVDCommand(_cmdVal, (_pStcmdArg)) == FALSE) \
383 { \
384 MVD_DEBUGERROR(printf("Command: 0x%x fail!!\r\n", _cmdVal)); \
385 return; \
386 } \
387 } while(0)
388
389 #define HAL_MVD_InvalidBuffRetFalse(x) \
390 do { \
391 if ((x)==0) \
392 { \
393 MVD_DEBUGERROR(printf("%s(%d) error: NULL buffer address.\n", __FUNCTION__, __LINE__)); \
394 return FALSE; \
395 } \
396 } while(0)
397
398 #define _MVD_Memset(pDstAddr, u32value, u32Size) \
399 do { \
400 MS_U32 x = 0; \
401 for (x = 0; x < (u32Size/4); x=x+4) \
402 { \
403 HAL_MVD_Memset4Byte(pDstAddr+x,u32value); \
404 } \
405 HAL_MVD_CPU_Sync(); \
406 HAL_MVD_ReadMemory(); \
407 } while (0)
408
409 #define _MVD_MemResetBit(pDstAddr, mask_num) \
410 do{ \
411 *pDstAddr = (*pDstAddr) & (~(0x1<<mask_num)); \
412 }while(0) \
413
414
415 typedef enum
416 {
417 MVD_HKSLQ_GET_READPTR = 0,
418 MVD_HKSLQ_GET_WRITEPTR = 1,
419 MVD_HKSLQ_NONE = 2,
420 } MVD_HKSLQ_CMD;
421
422 #if SLQ_NEW_PUSH
423 typedef struct _MVD_SLQ_STATUS
424 {
425 MS_BOOL bSlqPicStart;
426 MS_BOOL bSlqPicCollect;
427 MS_BOOL bSlqPicWaitNextStart;
428 MS_BOOL bSlqFireRdy;
429 MS_BOOL bSlqCtrlBit;
430 MS_BOOL bSlqEnLastFrameShow;
431 MS_VIRT u32SlqPatternAddr;
432 MS_U32 u32SlqPushLength;
433 MS_VIRT u32VaildWptrAddr;
434 } MVD_SLQ_STATUS;
435 #endif
436
437 typedef struct _MVD_SLQ_TBL_ST
438 {
439 MS_VIRT u32StAdd;
440 MS_VIRT u32EndAdd;
441 MS_U32 u32EntryCntMax;
442
443 MS_VIRT u32RdPtr;
444 MS_VIRT u32WrPtr;
445 MS_VIRT u32Empty;
446 MS_VIRT* pu32LastEntry;
447 } MVD_SLQ_TBL_ST;
448
449 typedef struct _MVD_ALIVEInfo
450 {
451 MS_U32 u32decode_count;
452 MS_U32 u32searchbuf_count;
453 MS_U32 u32searchcode_count;
454 MS_U32 u32prebuf_count;
455 MS_U32 u32vfifobuf_count;
456 MS_U32 u32searchheader_count;
457 MS_U32 u32flashpattern_count;
458 MS_U32 u32IdleCount;
459 } MVD_ALIVEInfo;
460
461
462 typedef struct _MVD_SLQ_ES_ST
463 {
464 MS_VIRT u32StAdd;
465 MS_VIRT u32EndAdd;
466
467 MS_VIRT u32RdPtr;
468 MS_VIRT u32WrPtr;
469 } MVD_SLQ_ES_ST;
470
471 typedef struct _MVD_FWBuff
472 {
473 MS_VIRT pu8MVDGetVolBufStart;
474 MS_VIRT u32VolAdd;
475 MS_VIRT pu8MVDGetFrameInfoBufStart;
476 MS_VIRT pu8MVDSetHeaderBufStart;
477 MS_VIRT u32UserDataBuf;
478 MS_VIRT u32MVDFWSLQTABTmpbufAdr;
479 MS_VIRT u32MVDFWPtsTblAddr;
480 MS_VIRT u32DynScalingAdd;
481 MS_VIRT u32ScalerInfoAdd;
482 MS_VIRT u32DecFrmInfoAdd;
483 MS_VIRT u32VBBUTableAdd;
484 } MVD_FWBuff;
485
486 typedef enum _FW_BUFF_TYPE
487 {
488 FW_BUFF_VOLINFO,
489 FW_BUFF_FRMINFO,
490 FW_BUFF_HDR,
491 FW_BUFF_USRDATA,
492 FW_BUFF_SLQTBL,
493 FW_BUFF_FWSLQTAB,
494 FW_BUFF_PTSTBL,
495 FW_BUFF_DS,
496 FW_BUFF_XCINFO,
497 FW_BUFF_DECFRMINFO,
498 } FW_BUFF_TYPE;
499
500 typedef struct _MVD_SLQTBLInfo
501 {
502 MS_U32 u32LastPts; ///< record the last PTS to handle the repeat case
503 MS_U32 u32DummyPktCnt; ///< accumulated dummy packet counter
504 MS_U32 u32SlqByteCnt; ///< accumulated byte counter
505 MS_VIRT u32ESBuffEnd; ///< miu offset of ES buffer end, used for report TS read/write ptr.
506 MS_VIRT u32FileEndPtr; ///< write ptr of file-end
507 MS_VIRT u32PreEsRd; ///< previous ES read ptr
508 MS_VIRT u32PreEsWr; ///< previous ES write ptr
509 MS_BOOL bRdyToFireCmd; ///< TRUE after FW is ready to update write pointer
510 MS_BOOL bSlqTblHasValidData; ///< TRUE if the write ptr is not updated
511 MS_BOOL bEnSlqTblHkCtrl;
512 BDMA_CpyType bdmaCpyType;
513 MVD_SLQ_STATUS* pSlqStatus;
514 MVD_SLQ_TBL_ST* pDrvSlqTbl;
515 MVD_SLQ_ES_ST* pDrvEsTbl;
516 MVD_SLQ_ES_ST* pDrvDivxTbl;
517 } MVD_SLQTBLInfo;
518
519 //Only keep one record of MIU setting since there should be only one,
520 //even for multiple decoders.
521 typedef struct _MVDMiuCfg
522 {
523 MS_PHY u32Miu1BaseAddr;
524 MS_PHY u32Miu2BaseAddr;
525 MS_PHY u32Miu3BaseAddr;
526 MS_U8 u8FWMiuSel;
527 MS_U8 u8HWMiuSel;
528 } MVDMiuCfg;
529
530 typedef struct
531 {
532 MS_U64 u64PTS;
533 MS_U32 u32POC;
534 MS_U8 u8FrameType;
535 } MVD_PVR_Seamless_Info;
536
537 typedef enum
538 {
539 E_MVD_DEC_0 = 0,
540 E_MVD_DEC_1,
541 E_MVD_DEC_MAX
542 } MVD_DecNum;
543 #ifdef VDEC3
544 #define MAX_DEC_NUM 16
545 #else
546 #define MAX_DEC_NUM E_MVD_DEC_MAX
547 #endif
548
549 //-------------------------------------------------------------------------------------------------
550 // Local Structures
551 //-------------------------------------------------------------------------------------------------
552
553
554 //-------------------------------------------------------------------------------------------------
555 // Global Variables
556 //-------------------------------------------------------------------------------------------------
557 static MS_VIRT u32RiuBaseAdd = 0;
558 MS_U8 _u8HalDbgLevel = 0;
559 #ifdef VDEC3//#ifdef VDEC3
560 static MS_U32 u32SharememoryBase[MAX_DEC_NUM] ={MVD_U32_MAX,MVD_U32_MAX,MVD_U32_MAX,MVD_U32_MAX};
561 #else
562 static MS_U32 u32SharememoryBase[MAX_DEC_NUM] ={MVD_U32_MAX,MVD_U32_MAX};
563 #endif
564 static MS_U8 u8SHMMiuSel=0;
565 #if 0
566 static MVD_MEMCfg stMemCfg[MAX_DEC_NUM];
567 static MVD_CtrlCfg stCtrlCfg[MAX_DEC_NUM];
568 static MVD_FWCfg stFwCfg[MAX_DEC_NUM];
569
570 // For SLQ table link
571 static MVD_SLQTBLInfo stSlqTblInfo[MAX_DEC_NUM];
572 static MVD_SLQ_STATUS _SlqStatus[MAX_DEC_NUM]; //for SLQ_NEW_PUSH
573 static MVD_SLQ_TBL_ST _drvSlqTbl[MAX_DEC_NUM];
574 static MVD_SLQ_ES_ST _drvEsTbl[MAX_DEC_NUM]; //maintain to report ES read/write ptr
575 static MVD_SLQ_ES_ST _drvDivxTbl[MAX_DEC_NUM]; //header for divx311
576 static FW_DIVX_INFO gdivxInfo[MAX_DEC_NUM];
577
578 MS_BOOL bSlqTblHKCtrl = FALSE; //read/write pointer can be accessed by HK directly
579 static MS_BOOL bStopped = TRUE;
580
581 static HAL_MVD_Stream _stMVDStream[MAX_DEC_NUM] = {
582 {E_HAL_MVD_MAIN_STREAM0, FALSE},
583 {E_HAL_MVD_SUB_STREAM0, FALSE},
584 //{E_HAL_MVD_SUB_STREAM1, FALSE},
585 };
586 static MVD_FWBuff stFWBuff[MAX_DEC_NUM];
587 #endif
588
589 #define FRM_RATE_CODE_NUM 9
590
591 typedef struct
592 {
593 MVD_MEMCfg stMemCfg[MAX_DEC_NUM];
594 MVD_CtrlCfg stCtrlCfg[MAX_DEC_NUM];
595 MVD_FWCfg stFwCfg[MAX_DEC_NUM];
596
597 // For SLQ table link
598 MVD_SLQTBLInfo stSlqTblInfo[MAX_DEC_NUM];
599 MVD_SLQ_STATUS _SlqStatus[MAX_DEC_NUM]; //for SLQ_NEW_PUSH
600 MVD_SLQ_TBL_ST _drvSlqTbl[MAX_DEC_NUM];
601 MVD_SLQ_ES_ST _drvEsTbl[MAX_DEC_NUM]; //maintain to report ES read/write ptr
602 MVD_SLQ_ES_ST _drvDivxTbl[MAX_DEC_NUM]; //header for divx311
603 FW_DIVX_INFO gdivxInfo[MAX_DEC_NUM];
604
605 MS_BOOL bSlqTblHKCtrl[MAX_DEC_NUM]; //read/write pointer can be accessed by HK directly
606 MS_BOOL bStopped[MAX_DEC_NUM];
607
608 HAL_MVD_Stream _stMVDStream[MAX_DEC_NUM];
609
610 MVD_FWBuff stFWBuff[MAX_DEC_NUM];
611
612 #if _SLQTBL_DUMP_PKT
613 MS_U32 u32SendTimes[MAX_DEC_NUM];//HAL_MVD_SLQTblSendPacket
614 #endif
615
616 MS_U32 u32pqTimes[MAX_DEC_NUM];//HAL_MVD_PushQueue
617 MS_BOOL bSetSkip[MAX_DEC_NUM];//MVD_FlushTSQueue
618
619 MS_U32 u32PreVdCnt[MAX_DEC_NUM];//HAL_MVD_DbgDump
620 MS_U32 u32PreErrCnt[MAX_DEC_NUM];
621 MS_BOOL b1stDump[MAX_DEC_NUM];
622 //pre_set
623 HAL_MVD_Pre_Ctrl gMVDPreCtrl[MAX_DEC_NUM];
624 MS_BOOL bAutoInsertDummyPattern[MAX_DEC_NUM];
625 MVDMiuCfg stMiuCfg;
626 MS_BOOL bDropOnePTS[MAX_DEC_NUM];
627 MVD_ALIVEInfo aliveInfo[MAX_DEC_NUM];
628
629 MS_U32 u32DmxFrameRate[MAX_DEC_NUM];
630 MS_U32 u32DmxFrameRateBase[MAX_DEC_NUM];
631 MS_BOOL bCMAUsed;
632
633 struct CMA_Pool_Init_Param cmaInitParam; // support two MIU
634 struct CMA_Pool_Free_Param cmaFreeParam[MAX_DEC_NUM];
635 MS_BOOL bCMATwoMIU[MAX_DEC_NUM];
636 MS_U32 u32LastAliveTime[MAX_DEC_NUM];
637 MS_BOOL bTrickPlay2xAVSync[MAX_DEC_NUM];
638 } MVD_Hal_CTX;
639
640 //global variables
641 MVD_Hal_CTX* pMVDHalContext = NULL;
642 MVD_Hal_CTX gMVDHalContext;
643 const MS_U16 stFrameRateCode[FRM_RATE_CODE_NUM]=
644 {
645 NULL,23976,24000,25000,29976,30000,50000,59947,60000
646 };
647
648
649 #define GET_VOL_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].pu8MVDGetVolBufStart
650 #define GET_VOL_BUFFADD_NONCACHE(idx) pMVDHalContext->stFWBuff[(idx)].u32VolAdd
651 #define GET_FRMINFO_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].pu8MVDGetFrameInfoBufStart
652 #define GET_HDR_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].pu8MVDSetHeaderBufStart
653 #define GET_USRDATA_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].u32UserDataBuf
654 #define GET_SLQ_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].u32MVDFWSLQTABTmpbufAdr
655 #define GET_PTSTBL_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].u32MVDFWPtsTblAddr
656 #define GET_DS_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].u32DynScalingAdd
657 #define GET_XCINFO_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].u32ScalerInfoAdd
658 #define GET_DECFRMINFO_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].u32DecFrmInfoAdd
659 #define GET_VBBUTABLEADD(idx) pMVDHalContext->stFWBuff[(idx)].u32VBBUTableAdd
660
661
662
663 //-------------------------------------------------------------------------------------------------
664 // Local Variables
665 //-------------------------------------------------------------------------------------------------
666
667
668 //-------------------------------------------------------------------------------------------------
669 // Debug Functions
670 //-------------------------------------------------------------------------------------------------
671
672
673 //-------------------------------------------------------------------------------------------------
674 // Local Functions
675 //-------------------------------------------------------------------------------------------------
676
HAL_MVD_Context_Init(void)677 static void HAL_MVD_Context_Init(void)
678 {
679 #ifdef VDEC3
680 MS_U8 i;
681
682 for (i = 0; i < MAX_DEC_NUM; i++)
683 {
684 pMVDHalContext->bStopped[i] = TRUE;
685 pMVDHalContext->b1stDump[i] = TRUE;
686 pMVDHalContext->_stMVDStream[i].eStreamId = E_HAL_MVD_N_STREAM0 + i;
687 }
688 #else
689 pMVDHalContext->bStopped[0] = TRUE;
690 pMVDHalContext->bStopped[1] = TRUE;
691 pMVDHalContext->_stMVDStream[0].eStreamId = E_HAL_MVD_MAIN_STREAM0;
692 pMVDHalContext->_stMVDStream[1].eStreamId = E_HAL_MVD_SUB_STREAM0;
693
694 pMVDHalContext->b1stDump[0] = TRUE;
695 pMVDHalContext->b1stDump[1] = TRUE;
696 #endif
697 }
698
699
700
HAL_MVD_SetIsUsed(MS_U8 u8Idx,MS_BOOL bUsed)701 static void HAL_MVD_SetIsUsed(MS_U8 u8Idx, MS_BOOL bUsed)
702 {
703 pMVDHalContext->_stMVDStream[u8Idx].bUsed = bUsed;
704 }
705
706 //Given the start address & the available size for the FW buffers,
707 //return the address of each buffers.
708 //Now only support u8Size==1, 2, 4
MVD_GetFWBuffData(MS_U8 u8Idx,FW_BUFF_TYPE eBuffType,MS_U16 u16Offset,MS_U8 u8Size)709 static MS_U32 MVD_GetFWBuffData(MS_U8 u8Idx, FW_BUFF_TYPE eBuffType, MS_U16 u16Offset, MS_U8 u8Size)
710 {
711 MS_U32 u32Val = 0;
712 MS_VIRT u32BufStart = NULL;
713 switch (eBuffType)
714 {
715 case FW_BUFF_VOLINFO: u32BufStart = GET_VOL_BUFFADD(u8Idx); break;
716 case FW_BUFF_FRMINFO: u32BufStart = GET_FRMINFO_BUFFADD(u8Idx); break;
717 case FW_BUFF_HDR: u32BufStart = GET_HDR_BUFFADD(u8Idx); break;
718 case FW_BUFF_USRDATA: u32BufStart = GET_USRDATA_BUFFADD(u8Idx); break;
719 case FW_BUFF_FWSLQTAB: u32BufStart = GET_SLQ_BUFFADD(u8Idx); break;
720 case FW_BUFF_PTSTBL: u32BufStart = GET_PTSTBL_BUFFADD(u8Idx); break;
721 case FW_BUFF_DS: u32BufStart = GET_DS_BUFFADD(u8Idx); break;
722 case FW_BUFF_XCINFO: u32BufStart = GET_XCINFO_BUFFADD(u8Idx); break;
723 case FW_BUFF_DECFRMINFO: u32BufStart = GET_DECFRMINFO_BUFFADD(u8Idx); break;
724 default:
725 break;
726 }
727 if (NULL == u32BufStart)
728 {
729 printf("%s err: u8Idx=0x%x, bufType=0x%x, offset=%d, size=%d\n",
730 __FUNCTION__, u8Idx, eBuffType, u16Offset, u8Size);
731 return 0;
732 }
733
734 if (u8Size == sizeof(MS_U8))
735 {
736 u32Val = (MS_U32)HAL_MVD_MemReadByte(u32BufStart+u16Offset);
737 }
738 else if (u8Size == sizeof(MS_U32))
739 {
740 u32Val = HAL_MVD_MemRead4Byte(u32BufStart+u16Offset);
741 }
742 else if (u8Size == sizeof(MS_U16))
743 {
744 u32Val = HAL_MVD_MemRead2Byte(u32BufStart+u16Offset);
745 }
746
747 MVD_DEBUGVERBAL(printf("%s: u32Val=%d for u8Idx=0x%x, bufType=0x%x, offset=%d, size=%d\n",
748 __FUNCTION__, u32Val, u8Idx, eBuffType, u16Offset, u8Size));
749 return u32Val;
750 }
751
752 #ifdef VDEC3
MVD_SetFWBuffData(MS_U8 u8Idx,FW_BUFF_TYPE eBuffType,MS_U16 u16Offset,MS_U8 u8Size,MS_U32 u32Value)753 static void MVD_SetFWBuffData(MS_U8 u8Idx, FW_BUFF_TYPE eBuffType, MS_U16 u16Offset, MS_U8 u8Size, MS_U32 u32Value)
754 {
755 MS_VIRT u32BufStart = NULL;
756
757 switch (eBuffType)
758 {
759 case FW_BUFF_VOLINFO: u32BufStart = GET_VOL_BUFFADD(u8Idx); break;
760 case FW_BUFF_FRMINFO: u32BufStart = GET_FRMINFO_BUFFADD(u8Idx); break;
761 case FW_BUFF_HDR: u32BufStart = GET_HDR_BUFFADD(u8Idx); break;
762 case FW_BUFF_USRDATA: u32BufStart = GET_USRDATA_BUFFADD(u8Idx); break;
763 case FW_BUFF_FWSLQTAB: u32BufStart = GET_SLQ_BUFFADD(u8Idx); break;
764 case FW_BUFF_PTSTBL: u32BufStart = GET_PTSTBL_BUFFADD(u8Idx); break;
765 case FW_BUFF_DS: u32BufStart = GET_DS_BUFFADD(u8Idx); break;
766 case FW_BUFF_XCINFO: u32BufStart = GET_XCINFO_BUFFADD(u8Idx); break;
767 case FW_BUFF_DECFRMINFO: u32BufStart = GET_DECFRMINFO_BUFFADD(u8Idx); break;
768 default:
769 break;
770 }
771
772 if (NULL == u32BufStart)
773 {
774 printf("%s err: u8Idx=0x%x, bufType=0x%x, offset=%d, size=%d, value=%d\n",
775 __FUNCTION__, (unsigned int)u8Idx,(unsigned int) eBuffType,(unsigned int) u16Offset,(unsigned int) u8Size,(unsigned int)u32Value);
776 }
777
778 if (pMVDHalContext->stMiuCfg.u8HWMiuSel == MIU_SEL_1)
779 {
780 u32BufStart += HAL_MIU1_BASE;
781 }
782 /* else if (pMVDHalContext->stMiuCfg.u8HWMiuSel == MIU_SEL_2)
783 {
784 u32BufStart += HAL_MIU2_BASE;
785 }*/
786
787 if (u8Size == sizeof(MS_U8))
788 {
789 MS_U8* temp = (MS_U8*)MsOS_PA2KSEG1(u32BufStart+u16Offset);
790 *temp = (MS_U8)u32Value;
791 }
792 else if (u8Size == sizeof(MS_U32))
793 {
794 MS_U32* temp = (MS_U32*)MsOS_PA2KSEG1(u32BufStart+u16Offset);
795 *temp = (MS_U32)u32Value;
796 }
797 else if (u8Size == sizeof(MS_U16))
798 {
799 MS_U16* temp = (MS_U16*)MsOS_PA2KSEG1(u32BufStart+u16Offset);
800 *temp = (MS_U16)u32Value;
801 }
802
803 MVD_DEBUGVERBAL(printf("%s: u8Idx=0x%x, bufType=0x%x, offset=%d, size=%d, value=%d\n",
804 __FUNCTION__, (unsigned int)u8Idx, (unsigned int)eBuffType, (unsigned int)u16Offset, (unsigned int)u8Size,(unsigned int)u32Value));
805 }
806 #endif
807
808
809 //-------------------------------------------------------------------------------------------------
810 // Global Functions
811 //-------------------------------------------------------------------------------------------------
HAL_MVD_SetDbgLevel(MS_U8 level)812 void HAL_MVD_SetDbgLevel(MS_U8 level)
813 {
814 _u8HalDbgLevel = level;
815 return;
816 }
817
818
HAL_MVD_GetCaps(void)819 MS_U8 HAL_MVD_GetCaps(void)
820 {
821 MS_U8 caps = 0;
822
823 caps |= (MVD_SUPPORT_MPEG2|MVD_SUPPORT_MPEG4|MVD_SUPPORT_VC1);
824 return caps;
825 }
826
HAL_MVD_GetMaxPixel(MS_U32 u32Id)827 MS_U64 HAL_MVD_GetMaxPixel(MS_U32 u32Id)
828 {
829 return (MS_U64)MVD_HW_MAX_PIXEL/1000;
830 }
831
HAL_MVD_GetDrvFwVer(void)832 MS_U32 HAL_MVD_GetDrvFwVer(void)
833 {
834 return MVD_FW_VERSION;
835 }
836
837 #if 0
838 MS_U32 HAL_MVD_GetMiu1BaseAdd(void)
839 {
840 return MIU1_BASEADDR;
841 }
842 #endif
843
844 //#if defined(CHIP_MUJI)
HAL_MVD_GetMiu1BaseAdd(void)845 MS_VIRT HAL_MVD_GetMiu1BaseAdd(void)
846 {
847 return MIU1_BASEADDR;
848 }
849
HAL_MVD_GetFWSelMiu1(void)850 MS_BOOL HAL_MVD_GetFWSelMiu1(void)
851 {
852 return MVDCPU_ON_MIU1;
853 }
854 //#endif
855
856
HAL_MVD_GetFWSelMiu(void)857 MS_U8 HAL_MVD_GetFWSelMiu(void)
858 {
859 return pMVDHalContext->stMiuCfg.u8FWMiuSel;
860 }
861
862
863
HAL_MVD_MemGetMap(MS_U8 u8Idx,MS_U8 u8type,MS_VIRT * pu32addr,MS_SIZE * pu32len)864 void HAL_MVD_MemGetMap(MS_U8 u8Idx, MS_U8 u8type, MS_VIRT* pu32addr, MS_SIZE* pu32len)
865 {
866 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
867 MS_VIRT u32StartOffset;
868 MS_U8 u8MiuSel;
869
870 switch (u8type)
871 {
872 case E_MVD_MMAP_ALL:
873 case E_MVD_MMAP_FW:
874 _phy_to_miu_offset(u8MiuSel, u32StartOffset, pstMemCfg->u32FWCodeAddr);
875 *pu32addr = u32StartOffset;
876 *pu32len = pstMemCfg->u32FWCodeSize;
877 break;
878 case E_MVD_MMAP_BS:
879 _phy_to_miu_offset(u8MiuSel, u32StartOffset, pstMemCfg->u32BSAddr);
880 *pu32addr = u32StartOffset;
881 *pu32len = pstMemCfg->u32BSSize;
882 break;
883 case E_MVD_MMAP_FB:
884 _phy_to_miu_offset(u8MiuSel, u32StartOffset, pstMemCfg->u32FBAddr);
885 *pu32addr = u32StartOffset;
886 *pu32len = pstMemCfg->u32FBSize;
887 break;
888 case E_MVD_MMAP_DRV:
889 _phy_to_miu_offset(u8MiuSel, u32StartOffset, pstMemCfg->u32DrvBufAddr);
890 *pu32addr = u32StartOffset;
891 *pu32len = pstMemCfg->u32DrvBufSize;
892 break;
893 default:
894 break;
895 }
896
897 MVD_DEBUGINFO(printf("HAL_MVD_MemGetMap[%d] add=0x%lx len=0x%lx\n",u8type,(unsigned long)*pu32addr,(unsigned long)*pu32len));
898 return;
899 }
900
HAL_MVD_RegSetBase(MS_VIRT u32Base)901 void HAL_MVD_RegSetBase(MS_VIRT u32Base)
902 {
903 u32RiuBaseAdd = u32Base;
904 HAL_VPU_EX_InitRegBase(u32Base);
905 }
906
HAL_MVD_RegWriteByte(MS_VIRT u32Reg,MS_U8 u8Val)907 void HAL_MVD_RegWriteByte(MS_VIRT u32Reg, MS_U8 u8Val)
908 {
909 if ( __builtin_constant_p( u32Reg ) )
910 {
911 RIU8[((u32Reg) * 2) - ((u32Reg) & 1)] = u8Val;
912 }
913 else
914 {
915 RIU8[(u32Reg << 1) - (u32Reg & 1)] = u8Val;
916 }
917 }
918
HAL_MVD_RegReadByte(MS_VIRT u32Reg)919 MS_U8 HAL_MVD_RegReadByte(MS_VIRT u32Reg)
920 {
921 return (__builtin_constant_p( u32Reg ) ?
922 (((u32Reg) & 0x01) ? RIU8[(u32Reg) * 2 - 1] : RIU8[(u32Reg) * 2]) :
923 (RIU8[(u32Reg << 1) - (u32Reg & 1)]));
924 }
925
HAL_MVD_RegWriteBit(MS_VIRT u32Reg,MS_BOOL bEnable,MS_U8 u8Mask)926 void HAL_MVD_RegWriteBit(MS_VIRT u32Reg, MS_BOOL bEnable, MS_U8 u8Mask)
927 {
928 MS_VIRT u32Reg8 = ((u32Reg) * 2) - ((u32Reg) & 1);
929 RIU8[u32Reg8] = (bEnable) ? (RIU8[u32Reg8] | (u8Mask)) :
930 (RIU8[u32Reg8] & ~(u8Mask));
931 }
932
HAL_MVD_RegWriteByteMask(MS_VIRT u32Reg,MS_U8 u8Val,MS_U8 u8Msk)933 void HAL_MVD_RegWriteByteMask(MS_VIRT u32Reg, MS_U8 u8Val, MS_U8 u8Msk)
934 {
935 MS_VIRT u32Reg8 = ((u32Reg) * 2) - ((u32Reg) & 1);
936 RIU8[u32Reg8] = (RIU8[u32Reg8] & ~(u8Msk)) | ((u8Val) & (u8Msk));
937 }
938
HAL_MVD_RegWrite4Byte(MS_VIRT u32Reg,MS_U32 u32Val)939 void HAL_MVD_RegWrite4Byte(MS_VIRT u32Reg, MS_U32 u32Val)
940 {
941 if ( __builtin_constant_p( u32Reg ) && !((u32Reg) & 0x01) )
942 {
943 RIU[u32Reg] = (MS_U16)(u32Val);
944 RIU[(u32Reg) + 2] = (MS_U16)((u32Val) >> 16);
945 }
946 else
947 {
948 if (u32Reg & 0x01)
949 {
950 RIU8[(u32Reg << 1) - 1] = u32Val;
951 RIU[u32Reg + 1] = (u32Val >> 8);
952 RIU8[((u32Reg + 3) << 1)] = (u32Val >> 24);
953 }
954 else
955 {
956 RIU[u32Reg] = u32Val;
957 RIU[u32Reg + 2] = (u32Val >> 16);
958 }
959 }
960 }
961
962
HAL_MVD_MemRead4Byte(MS_VIRT u32Address)963 MS_U32 HAL_MVD_MemRead4Byte(MS_VIRT u32Address)
964 {
965 volatile MS_U32 u32Val;
966 MS_ASSERT(!(u32Address & 0x03UL));
967
968 HAL_MVD_CPU_Sync();
969 HAL_MVD_ReadMemory();
970
971 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,u32Address,u32Address);
972
973 u32Val = *(volatile MS_U32*) HAL_MVD_PA2NonCacheSeg(u32Address);
974
975 //printf("mvd rd 0x%lx = 0x%lx\n", u32Address, u32Val);
976 return u32Val;
977 }
978
HAL_MVD_MemRead2Byte(MS_VIRT u32Address)979 MS_U16 HAL_MVD_MemRead2Byte(MS_VIRT u32Address)
980 {
981 MS_VIRT u32ReadAddr;
982 MS_U32 u32ReadValue;
983 MS_U16 u16Value;
984 MS_U8 u8Shift;
985 u32ReadAddr = (u32Address >> 2) << 2;
986 u8Shift = (MS_U8)((u32Address & 0x03) * 8);
987 u32ReadValue = HAL_MVD_MemRead4Byte(u32ReadAddr);
988
989 u16Value = (MS_U16)(u32ReadValue >> u8Shift);
990 if(u8Shift == 24)
991 {
992 u32ReadValue = HAL_MVD_MemRead4Byte(u32ReadAddr+4);
993 u16Value = u16Value << 8 || (MS_U16)(u32ReadValue & 0xFF);
994 }
995 return u16Value;
996 }
997
HAL_MVD_MemReadByte(MS_VIRT u32Address)998 MS_U8 HAL_MVD_MemReadByte(MS_VIRT u32Address)
999 {
1000 MS_VIRT u32ReadAddr;
1001 MS_U32 u32ReadValue;
1002 MS_U8 u8Value;
1003 MS_U8 u8Shift;
1004 u32ReadAddr = (u32Address >> 2) << 2;
1005 u8Shift = (MS_U8)((u32Address & 0x03) * 8);
1006 u32ReadValue = HAL_MVD_MemRead4Byte(u32ReadAddr);
1007 u8Value = (MS_U8)(u32ReadValue >> u8Shift);
1008
1009 return u8Value;
1010 }
1011
HAL_MVD_MemWrite4Byte(MS_VIRT u32Address,MS_U32 u32Value)1012 MS_BOOL HAL_MVD_MemWrite4Byte(MS_VIRT u32Address, MS_U32 u32Value)
1013 {
1014
1015 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,u32Address,u32Address);
1016
1017 *(volatile MS_U32 *) HAL_MVD_PA2NonCacheSeg(u32Address) = u32Value;
1018
1019 HAL_MVD_CPU_Sync();
1020 HAL_MVD_FlushMemory();
1021
1022 return TRUE;
1023 }
1024
HAL_MVD_MemWriteByte(MS_VIRT u32Address,MS_U8 u8Value)1025 MS_BOOL HAL_MVD_MemWriteByte(MS_VIRT u32Address, MS_U8 u8Value)
1026 {
1027 MS_VIRT u32ReadAddr;
1028 MS_U32 u32ReadValue;
1029 MS_U8 u8Shift;
1030
1031 u32ReadAddr = (u32Address >> 2) << 2;
1032 u8Shift = (MS_U8)((u32Address & 0x03UL) * 8);
1033 u32ReadValue = HAL_MVD_MemRead4Byte(u32ReadAddr);
1034 u32ReadValue &= ~(0xFFUL << u8Shift);
1035 u32ReadValue |= ((MS_U32)u8Value << u8Shift);
1036 HAL_MVD_MemWrite4Byte(u32ReadAddr, u32ReadValue);
1037 return TRUE;
1038 }
1039
HAL_MVD_MemWrite2Byte(MS_VIRT u32Address,MS_U16 u16Value)1040 MS_BOOL HAL_MVD_MemWrite2Byte(MS_VIRT u32Address, MS_U16 u16Value)
1041 {
1042 MS_VIRT u32ReadAddr;
1043 MS_U32 u32ReadValue;
1044 MS_U8 u8Shift;
1045
1046 u8Shift = (MS_U8)((u32Address & 0x03UL) * 8) ;
1047 if(u8Shift < 24)
1048 {
1049 u32ReadAddr = (u32Address >> 2) << 2;
1050 u32ReadValue = HAL_MVD_MemRead4Byte(u32ReadAddr);
1051 u32ReadValue &= ~(0xFFFF << u8Shift);
1052 u32ReadValue |= ((MS_U32)u16Value << u8Shift);
1053 HAL_MVD_MemWrite4Byte(u32ReadAddr, u32ReadValue);
1054 }
1055 else
1056 {
1057 HAL_MVD_MemWriteByte(u32Address, (MS_U8)(u16Value));
1058 HAL_MVD_MemWriteByte(u32Address+1, (MS_U8)(u16Value >> 8));
1059 }
1060 return TRUE;
1061 }
1062
1063
HAL_MVD_SetReqMask(MS_BOOL bEnMask)1064 void HAL_MVD_SetReqMask(MS_BOOL bEnMask)
1065 {
1066 HAL_VPU_EX_MIU_RW_Protect(bEnMask);
1067
1068 if (MVDHW_ON_MIU1)
1069 {
1070 HAL_MVD_RegWriteBit(MIU1_RQ2_MASK_L, bEnMask, BIT4); //MVD R/W
1071 HAL_MVD_RegWriteBit(MIU1_RQ0_MASK_H, bEnMask, BIT4); //MVD bbu R/W
1072 }
1073 else if(MVDHW_ON_MIU0)
1074 {
1075 HAL_MVD_RegWriteBit(MIU0_RQ2_MASK_L, bEnMask, BIT4); //MVD R/W
1076 HAL_MVD_RegWriteBit(MIU0_RQ0_MASK_H, bEnMask, BIT4); //MVD bbu R/W
1077 }
1078 else
1079 {
1080 HAL_MVD_RegWriteBit(MIU2_RQ2_MASK_L, bEnMask, BIT4); //MVD R/W
1081 HAL_MVD_RegWriteBit(MIU2_RQ0_MASK_H, bEnMask, BIT4); //MVD bbu R/W
1082 }
1083 HAL_MVD_Delayms(1);
1084
1085 return;
1086 }
1087
HAL_MVD_Memset4Byte(MS_VIRT u32Address,MS_U32 u32Value)1088 static MS_BOOL HAL_MVD_Memset4Byte(MS_VIRT u32Address, MS_U32 u32Value)
1089 {
1090 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,u32Address,u32Address);
1091
1092 *(volatile MS_U32 *) HAL_MVD_PA2NonCacheSeg(u32Address) = u32Value;
1093
1094 return TRUE;
1095 }
1096
1097 //------------------------------------------------------------------------------
1098 /// Initialize MVD
1099 /// @return -result of resetting MVD hardware
1100 //------------------------------------------------------------------------------
HAL_MVD_RstHW(void)1101 MS_BOOL HAL_MVD_RstHW(void)
1102 {
1103 MS_U32 u32Time = 0;
1104
1105 OSAL_MVD_LockHwMutex();
1106
1107 HAL_MVD_SetReqMask(ENABLE);
1108
1109 HAL_MVD_RegWriteBit(MVD_CTRL, 1, MVD_CTRL_DISCONNECT_MIU);//disconnect MIU
1110 HAL_MVD_RegWriteBit(MVD_CTRL, 0, MVD_CTRL_DISCONNECT_MIU);//release reset
1111
1112 HAL_MVD_RegWriteBit(MVD_CTRL, 1, MVD_CTRL_RST);//reset MVD
1113 HAL_MVD_RegWriteBit(MVD_CTRL, 0, MVD_CTRL_RST);//release reset
1114
1115 u32Time = HAL_MVD_GetTime();
1116 while ( ((HAL_MVD_RegReadByte(MVD_STATUS) & MVD_STATUS_READY) == 0)
1117 && ((HAL_MVD_GetTime() - u32Time) < 200) );
1118
1119 #if 0 //bring up
1120 printf("====================>>>>MVD Ctrl status1.5a : 0x%x\n",HAL_MVD_RegReadByte(MVD_STATUS));
1121 HAL_MVD_RegWriteBit(MVD_STATUS, 1, MVD_T8_MIU_128_0);//release reset
1122 HAL_MVD_RegWriteBit(MVD_STATUS, 1, MVD_T8_MIU_128_1);//release reset
1123 MVD_DEBUGINFO(printf("MVD Ctrl status : 0x%x\n",HAL_MVD_RegReadByte(MVD_STATUS)));
1124 printf("====================>>>>MVD Ctrl status1.5b : 0x%x\n",HAL_MVD_RegReadByte(MVD_STATUS));
1125 #endif
1126
1127 HAL_MVD_SetReqMask(DISABLE);
1128
1129 OSAL_MVD_UnlockHwMutex();
1130
1131 return TRUE;
1132 }
1133
1134
1135 //------------------------------------------------------------------------------
1136 /// Release CPU
1137 /// @return -release CPU successfully or not
1138 //------------------------------------------------------------------------------
HAL_MVD_ReleaseFW(void)1139 MS_BOOL HAL_MVD_ReleaseFW(void)
1140 {
1141 //For dual decoder, we only release VPU if it is not released yet.
1142 if (TRUE == HAL_VPU_EX_IsRsted())
1143 {
1144 MVD_DEBUGINFO(printf("%s VPU_IsRsted\n", __FUNCTION__));
1145 return TRUE;
1146 }
1147
1148 HAL_VPU_EX_SwRstRelse();
1149 return TRUE;
1150 }
1151
HAL_MVD_PA2NonCacheSeg(MS_PHY u32PhyAddr)1152 MS_VIRT HAL_MVD_PA2NonCacheSeg(MS_PHY u32PhyAddr)
1153 {
1154 return MS_PA2KSEG1(u32PhyAddr);
1155 }
1156
HAL_MVD_GetTime(void)1157 MS_U32 HAL_MVD_GetTime(void)
1158 {
1159 return MsOS_GetSystemTime();
1160 }
1161
HAL_MVD_Delayms(MS_U32 u32msecs)1162 void HAL_MVD_Delayms(MS_U32 u32msecs)
1163 {
1164 MsOS_DelayTask(u32msecs);
1165 }
1166
HAL_MVD_CPU_Sync(void)1167 void HAL_MVD_CPU_Sync(void)
1168 {
1169 MAsm_CPU_Sync();
1170 }
1171
HAL_MVD_FlushMemory(void)1172 void HAL_MVD_FlushMemory(void)
1173 {
1174 MsOS_FlushMemory();
1175 }
1176
HAL_MVD_ReadMemory(void)1177 void HAL_MVD_ReadMemory(void)
1178 {
1179 MsOS_ReadMemory();
1180 }
1181
1182 //Record the memory layout from system configuration
HAL_MVD_SetMEMCfg(MS_U8 u8Idx,MVD_MEMCfg * pMEMCfg)1183 MS_BOOL HAL_MVD_SetMEMCfg(MS_U8 u8Idx, MVD_MEMCfg* pMEMCfg)
1184 {
1185 memcpy(&(pMVDHalContext->stMemCfg[u8Idx]), pMEMCfg, sizeof(MVD_MEMCfg));
1186 //record the MIU settings
1187 pMVDHalContext->stMiuCfg.u32Miu1BaseAddr = pMEMCfg->u32Miu1BaseAddr;
1188 pMVDHalContext->stMiuCfg.u32Miu2BaseAddr = pMEMCfg->u32Miu2BaseAddr;
1189 pMVDHalContext->stMiuCfg.u32Miu3BaseAddr = pMEMCfg->u32Miu3BaseAddr;
1190 pMVDHalContext->stMiuCfg.u8FWMiuSel = pMEMCfg->u8FWMiuSel;
1191 pMVDHalContext->stMiuCfg.u8HWMiuSel = pMEMCfg->u8HWMiuSel;
1192 return TRUE;
1193 }
1194
HAL_MVD_GetMEMCfg(MS_U8 u8Idx)1195 MVD_MEMCfg* HAL_MVD_GetMEMCfg(MS_U8 u8Idx)
1196 {
1197 //printf("%s: u8Idx=0x%x\n", __FUNCTION__, u8Idx);
1198 MVD_MEMCfg* pInfo = NULL;
1199 pInfo = &(pMVDHalContext->stMemCfg[u8Idx]);
1200 return pInfo;
1201 }
1202
HAL_MVD_SetFWCfg(MS_U8 u8Idx,MVD_FWCfg * pFWCfg)1203 MS_BOOL HAL_MVD_SetFWCfg(MS_U8 u8Idx, MVD_FWCfg* pFWCfg)
1204 {
1205 //printf("%s: u8Idx=0x%x\n", __FUNCTION__, u8Idx);
1206 memcpy(&(pMVDHalContext->stFwCfg[u8Idx]), pFWCfg, sizeof(MVD_FWCfg));
1207 memcpy(&(pMVDHalContext->stFwCfg[u8Idx].stFBReduction), &pFWCfg->stFBReduction,sizeof(MVD_FB_Reduction));
1208 return TRUE;
1209 }
1210
HAL_MVD_GetFWCfg(MS_U8 u8Idx)1211 MVD_FWCfg* HAL_MVD_GetFWCfg(MS_U8 u8Idx)
1212 {
1213 MVD_FWCfg* pInfo = NULL;
1214 //printf("%s: u8Idx=0x%x\n", __FUNCTION__, u8Idx);
1215 pInfo = &(pMVDHalContext->stFwCfg[u8Idx]);
1216 return pInfo;
1217 }
1218
HAL_MVD_GetFBMode(MS_U8 u8Idx)1219 MS_U8 HAL_MVD_GetFBMode(MS_U8 u8Idx)
1220 {
1221 MS_U8 u8Mode = MVD3_SD_MODE;
1222 u8Mode = pMVDHalContext->stFwCfg[u8Idx].u8FBMode;
1223 MVD_DEBUGINFO(printf("FBMode=0x%x\n", u8Mode));
1224 return u8Mode;
1225 }
1226
HAL_MVD_GetCodecType(MS_U8 u8Idx)1227 MVD_CodecType HAL_MVD_GetCodecType(MS_U8 u8Idx)
1228 {
1229 MVD_CodecType eCodecType = E_MVD_CODEC_UNKNOWN;
1230 eCodecType = pMVDHalContext->stFwCfg[u8Idx].eCodecType;
1231 return eCodecType;
1232 }
1233
HAL_MVD_GetSrcMode(MS_U8 u8Idx)1234 MVD_SrcMode HAL_MVD_GetSrcMode(MS_U8 u8Idx)
1235 {
1236 MVD_SrcMode eSrcMode = E_MVD_SRC_UNKNOWN;
1237 eSrcMode = pMVDHalContext->stFwCfg[u8Idx].eSrcMode;
1238 return eSrcMode;
1239 }
1240
HAL_MVD_SetSrcMode(MS_U8 u8Idx,MVD_SrcMode mode)1241 MS_BOOL HAL_MVD_SetSrcMode(MS_U8 u8Idx,MVD_SrcMode mode)
1242 {
1243 if(pMVDHalContext != NULL)
1244 {
1245 pMVDHalContext->stFwCfg[u8Idx].eSrcMode = mode;
1246 return TRUE;
1247 }
1248 else
1249 {
1250 return FALSE;
1251 }
1252 }
1253
1254
HAL_MVD_GetCtrlCfg(MS_U8 u8Idx)1255 MVD_CtrlCfg* HAL_MVD_GetCtrlCfg(MS_U8 u8Idx)
1256 {
1257 MVD_CtrlCfg* pInfo = NULL;
1258 pInfo = &(pMVDHalContext->stCtrlCfg[u8Idx]);
1259 return pInfo;
1260 }
1261
HAL_MVD_GetSlqTblInfo(MS_U8 u8Idx)1262 MVD_SLQTBLInfo* HAL_MVD_GetSlqTblInfo(MS_U8 u8Idx)
1263 {
1264 MVD_SLQTBLInfo* pInfo = NULL;
1265 pInfo = &(pMVDHalContext->stSlqTblInfo[u8Idx]);
1266 return pInfo;
1267 }
1268
HAL_MVD_PowerCtrl(MS_BOOL bOn)1269 void HAL_MVD_PowerCtrl(MS_BOOL bOn)
1270 {
1271 #ifdef CONFIG_MSTAR_CLKM
1272 HAL_VPU_EX_SetClkManagement(E_VPU_EX_CLKPORT_MVD, bOn);
1273 #else
1274 HAL_MVD_RegWriteByteMask(REG_CKG_MVD, CKG_MVD_216MHZ, CKG_MVD_MASK);
1275 HAL_MVD_RegWriteBit(REG_CKG_MVD, !bOn, CKG_MVD_GATED);
1276 HAL_MVD_RegWriteBit(REG_CKG_MVD, !bOn, CKG_MVD_INVERT);
1277 #endif
1278 HAL_MVD_RegWriteBit(REG_CKG_MVD_CHROMA_A, !bOn, CKG_MVD_CHROMA_A_GATED);
1279 HAL_MVD_RegWriteBit(REG_CKG_MVD_CHROMA_A, !bOn, CKG_MVD_CHROMA_A_INVERT);
1280
1281 HAL_MVD_RegWriteBit(REG_CKG_MVD_CHROMA_B, !bOn, CKG_MVD_CHROMA_B_GATED);
1282 HAL_MVD_RegWriteBit(REG_CKG_MVD_CHROMA_B, !bOn, CKG_MVD_CHROMA_B_INVERT);
1283
1284 HAL_MVD_RegWriteBit(REG_CKG_MVD_CHROMA_C, !bOn, CKG_MVD_CHROMA_C_GATED);
1285 HAL_MVD_RegWriteBit(REG_CKG_MVD_CHROMA_C, !bOn, CKG_MVD_CHROMA_C_INVERT);
1286
1287 HAL_MVD_RegWriteBit(REG_CKG_MVD_LUMA_A, !bOn, CKG_MVD_LUMA_A_GATED);
1288 HAL_MVD_RegWriteBit(REG_CKG_MVD_LUMA_A, !bOn, CKG_MVD_LUMA_A_INVERT);
1289
1290 HAL_MVD_RegWriteBit(REG_CKG_MVD_LUMA_B, !bOn, CKG_MVD_LUMA_B_GATED);
1291 HAL_MVD_RegWriteBit(REG_CKG_MVD_LUMA_B, !bOn, CKG_MVD_LUMA_B_INVERT);
1292
1293 HAL_MVD_RegWriteBit(REG_CKG_MVD_LUMA_C, !bOn, CKG_MVD_LUMA_C_GATED);
1294 HAL_MVD_RegWriteBit(REG_CKG_MVD_LUMA_C, !bOn, CKG_MVD_LUMA_C_INVERT);
1295
1296 HAL_MVD_RegWriteBit(REG_CKG_MVD_RMEM, !bOn, CKG_MVD_RMEM_GATED);
1297 HAL_MVD_RegWriteBit(REG_CKG_MVD_RMEM, !bOn, CKG_MVD_RMEM_INVERT);
1298
1299 HAL_MVD_RegWriteBit(REG_CKG_MVD_RMEM1, !bOn, CKG_MVD_RMEM1_GATED);
1300 HAL_MVD_RegWriteBit(REG_CKG_MVD_RMEM1, !bOn, CKG_MVD_RMEM1_INVERT);
1301
1302 HAL_MVD_RegWriteBit(REG_CKG_MVD_RREFDAT, !bOn, CKG_MVD_RREFDAT_GATED);
1303 HAL_MVD_RegWriteBit(REG_CKG_MVD_RREFDAT, !bOn, CKG_MVD_RREFDAT_INVERT);
1304
1305 //Set MVD all clock sources equal to clk_miu_p 0: enable 1: disable
1306 //Per Lawrence, mark this line:
1307 // Sync mode is debug mode, so driver shouldn't write 1 to this register in normal case.
1308 //HAL_MVD_RegWriteBit(REG_CKG_MVD_SYNC, !bOn, CKG_MVD_SYNC_GATED);
1309
1310 return;
1311 }
1312
1313 #if 0
1314 void HAL_MVD_Sleep(MS_U32 u32us)
1315 {
1316 MsOS_DelayTaskUs(u32us);
1317 }
1318 #endif
HAL_MVD_ResetHandShake(MS_U8 u8Idx,MVD_HANDSHAKE_CMD cmd)1319 void HAL_MVD_ResetHandShake(MS_U8 u8Idx, MVD_HANDSHAKE_CMD cmd)
1320 {
1321 MS_U32 u32BufAddr = GET_FRMINFO_BUFFADD(u8Idx);
1322 HAL_MVD_CPU_Sync();
1323 HAL_MVD_ReadMemory();
1324 MVD_CMD_HANDSHADE_INDEX u32CmdState;
1325 u32CmdState.value= HAL_MVD_MemRead4Byte(u32BufAddr + OFFSET_CMD_HANDSHAKE_INDEX);
1326 switch (cmd)
1327 {
1328 case MVD_HANDSHAKE_PAUSE:
1329 (u32CmdState.mvdcmd_handshake_pause) = 0;
1330 break;
1331 case MVD_HANDSHAKE_SLQ_RST:
1332 (u32CmdState.mvdcmd_handshake_slq_reset) = 0;
1333 break;
1334 case MVD_HANDSHAKE_STOP:
1335 (u32CmdState.mvdcmd_handshake_stop) = 0;
1336 break;
1337 case MVD_HANDSHAKE_SKIP_DATA:
1338 (u32CmdState.mvdcmd_handshake_skip_data) = 0;
1339 break;
1340 case MVD_HANDSHAKE_SINGLE_STEP:
1341 (u32CmdState.mvdcmd_handshake_single_step) = 0;
1342 break;
1343 case MVD_HANDSHAKE_SCALER_INFO:
1344 (u32CmdState.mvdcmd_handshake_scaler_data_ready) = 0;
1345 break;
1346 case MVD_HANDSHAKE_GET_NXTDISPFRM:
1347 (u32CmdState.mvdcmd_handshake_get_nextdispfrm_ready) = 0;
1348 break;
1349 case MVD_HANDSHAKE_PARSER_RST:
1350 (u32CmdState.mvdcmd_handshake_parser_rst) = 0;
1351 break;
1352 case MVD_HANDSHAKE_RST_CC608:
1353 (u32CmdState.mvdcmd_handshake_cc608_rst) = 0;
1354 break;
1355 case MVD_HANDSHAKE_RST_CC708:
1356 (u32CmdState.mvdcmd_handshake_cc708_rst) = 0;
1357 break;
1358 case MVD_HANDSHAKE_VIRTUAL_COMMAND:
1359 (u32CmdState.mvdcmd_handshake_virtualCommand) = 0;
1360 break;
1361 case MVD_HANDSHAKE_FLUSHQUEUE_COMMAND:
1362 (u32CmdState.mvdcmd_handshake_flush) = 0;
1363 break;
1364 case MVD_HANDSHAKE_VSYNC_CONTROL:
1365 (u32CmdState.mvdcmd_handshake_vsync_control) = 0;
1366 break;
1367 default:
1368 break;
1369 }
1370 HAL_MVD_MemWrite4Byte(u32BufAddr + OFFSET_CMD_HANDSHAKE_INDEX,u32CmdState.value);
1371 MsOS_FlushMemory();
1372 }
1373
1374 //------------------------------------------------------------------------------
1375 /// Wait MVD command ready or timeout
1376 /// @return -MVD command ready or timeout
1377 //------------------------------------------------------------------------------
HAL_MVD_TimeOut(MS_U8 u8Idx)1378 MS_BOOL HAL_MVD_TimeOut(MS_U8 u8Idx)
1379 {
1380 MS_U32 i;
1381 MS_U32 u32StartTime = MsOS_GetSystemTime();
1382
1383 for ( i = 0; i < MVD_PollingTimes; i++ )
1384 {
1385 ///- wait until MVD command ready or timeout
1386 if ( ( HAL_MVD_RegReadByte(MVD_STATUS) & MVD_STATUS_READY ) == MVD_STATUS_READY )
1387 {
1388 return FALSE;
1389 }
1390
1391 if (/*(TRUE == pMVDHalContext->bStopped[u8Idx]) ||*/ ((MsOS_GetSystemTime()-u32StartTime)>1300))
1392 {
1393 MVD_DEBUGINFO(printf("%s: bStopped(%x) or timeout(%d)\n", __FUNCTION__, pMVDHalContext->bStopped[u8Idx], MsOS_GetSystemTime()-u32StartTime));
1394 return TRUE;
1395 }
1396
1397 //HAL_MVD_Sleep(5);
1398 }
1399 MVD_DEBUGERROR( printf("MVD_TimeOut=%x\n", i) );
1400 return TRUE;
1401 }
1402
1403 //------------------------------------------------------------------------------
1404 /// Set MVD firmware command
1405 /// @param -u8cmd \b IN : MVD command
1406 /// @param -pstCmdArg \b IN : pointer to command argument
1407 //------------------------------------------------------------------------------
HAL_MVD_MVDCommand(MS_U8 u8cmd,MVD_CmdArg * pstCmdArg)1408 MS_BOOL HAL_MVD_MVDCommand ( MS_U8 u8cmd, MVD_CmdArg *pstCmdArg )
1409 {
1410 MS_BOOL bRet = TRUE;
1411 #ifdef VDEC3
1412 MS_U32 u32CmdArg;
1413 MS_U32 u32Ret = FALSE;
1414 MS_U32 u32Timeout;
1415 MS_U8 u8HalIdx = pstCmdArg->Arg5;
1416 MS_U32 u32Id = MVD_GetStreamId(u8HalIdx);
1417 MS_U8 u8VPUIdx = HAL_VPU_EX_GetTaskId(u32Id);
1418 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8HalIdx);
1419 CMD_QUEUE *pShm = (CMD_QUEUE *)MsOS_PA2KSEG1(pstMemCfg->u32FWCodeAddr + VCOMMANDQ_INFO_START + u8VPUIdx*0x100000);
1420 MS_VIRT u32BufStart2 = NULL;
1421 MS_BOOL bResponse = FALSE;
1422 #endif
1423 OSAL_MVD_LockHwMutex();
1424
1425 #ifdef VDEC3
1426 if(HAL_MVD_IsDisplayCommand(u8cmd) == TRUE)
1427 {
1428 if(HAL_MVD_IsNeedResponseCommand(u8cmd) == TRUE)
1429 {
1430 // clear handshake dram
1431 u32BufStart2 = GET_VOL_BUFFADD(u8HalIdx);
1432
1433 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,u32BufStart2,u32BufStart2);
1434
1435 MS_U8* temp2 = (MS_U8*)MsOS_PA2KSEG1(u32BufStart2+OFFSET_VCHANDSHAKE);
1436
1437 *temp2 = 0;
1438
1439 MsOS_FlushMemory();
1440 }
1441
1442
1443 u32CmdArg = pstCmdArg->Arg0 | (pstCmdArg->Arg1<<8) | (pstCmdArg->Arg2 << 16) | (pstCmdArg->Arg3 << 24);
1444
1445 u32Timeout = MsOS_GetSystemTime()+VIRTUAL_CMD_TIMEOUT;
1446
1447 do
1448 {
1449 u32Ret = HAL_VPU_EX_DRAMStreamDispCMDQueueSend(u32Id,(void*)pShm,E_HVD_CMDQ_ARG,u32CmdArg);
1450
1451
1452 if(u32Ret == E_HVD_COMMAND_QUEUE_NOT_INITIALED)
1453 {
1454 bRet = FALSE;
1455 break;
1456 }
1457 else if (MsOS_GetSystemTime() > u32Timeout && u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL )
1458 {
1459 bRet = FALSE;
1460 break;
1461 }
1462 }while(u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL);
1463
1464 if(bRet == FALSE || u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL)
1465 {
1466 bRet = FALSE;
1467 goto _CMD_DONE;
1468 }
1469
1470
1471 u32Timeout = MsOS_GetSystemTime()+VIRTUAL_CMD_TIMEOUT;
1472
1473 do
1474 {
1475 u32Ret = HAL_VPU_EX_DRAMStreamDispCMDQueueSend(u32Id,(void*)pShm,E_HVD_CMDQ_CMD,u8cmd|(u8VPUIdx<<24)|(pstCmdArg->Arg4<<16));
1476
1477 if(u32Ret == E_HVD_COMMAND_QUEUE_NOT_INITIALED)
1478 {
1479 bRet = FALSE;
1480 break;
1481 }
1482 else if (MsOS_GetSystemTime() > u32Timeout && u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL)
1483 {
1484 bRet = FALSE;
1485 break;
1486 }
1487 }while(u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL);
1488
1489 if(bRet == FALSE || u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL)
1490 {
1491 bRet = FALSE;
1492 goto _CMD_DONE;
1493 }
1494
1495 if(HAL_MVD_IsNeedResponseCommand(u8cmd) == TRUE)
1496 {
1497 u32Timeout = MsOS_GetSystemTime()+VIRTUAL_CMD_TIMEOUT;
1498
1499 while(MsOS_GetSystemTime() < u32Timeout)
1500 {
1501 #if 0
1502 if (HAL_MVD_IsCmdFinished(u8HalIdx, MVD_HANDSHAKE_VIRTUAL_COMMAND))
1503 {
1504 bResponse = TRUE;
1505 break;
1506 }
1507 #else
1508 if(MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VCHANDSHAKE, sizeof(MS_U8)) == 1)
1509 {
1510 bResponse = TRUE;
1511 break;
1512 }
1513 #endif
1514 }
1515
1516 if(bResponse == FALSE) // fail case
1517 {
1518 bRet = FALSE;
1519 goto _CMD_DONE;
1520 }
1521
1522 pstCmdArg->Arg0 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG0, sizeof(MS_U8));
1523 pstCmdArg->Arg1 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG1, sizeof(MS_U8));
1524 pstCmdArg->Arg2 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG2, sizeof(MS_U8));
1525 pstCmdArg->Arg3 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG3, sizeof(MS_U8));
1526 pstCmdArg->Arg4 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG4, sizeof(MS_U8));
1527 }
1528
1529 }
1530 else if(HAL_MVD_IsNormalCommand(u8cmd) == TRUE)
1531 {
1532 if(HAL_MVD_IsNeedResponseCommand(u8cmd) == TRUE)
1533 {
1534 // clear handshake dram
1535 u32BufStart2 = GET_VOL_BUFFADD(u8HalIdx);
1536
1537 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,u32BufStart2,u32BufStart2);
1538
1539 MS_U8* temp2 = (MS_U8*)MsOS_PA2KSEG1(u32BufStart2+OFFSET_VCHANDSHAKE);
1540
1541 *temp2 = 0;
1542
1543 MsOS_ReadMemory();
1544 MsOS_FlushMemory();
1545 }
1546
1547 u32CmdArg = pstCmdArg->Arg0 | (pstCmdArg->Arg1<<8) | (pstCmdArg->Arg2 << 16) | (pstCmdArg->Arg3 << 24);
1548
1549 u32Timeout = MsOS_GetSystemTime()+VIRTUAL_CMD_TIMEOUT;
1550
1551 do
1552 {
1553 //u32Ret = HAL_VPU_EX_DRAMStreamCMDQueueSend_MVD(pstCmdArg->Arg5,E_HVD_CMDQ_ARG,u32CmdArg);
1554 u32Ret = HAL_VPU_EX_DRAMStreamCMDQueueSend(u32Id,(void*)pShm,E_HVD_CMDQ_ARG,u32CmdArg);
1555
1556 if(u32Ret == E_HVD_COMMAND_QUEUE_NOT_INITIALED)
1557 {
1558 bRet = FALSE;
1559 break;
1560 }
1561 else if (MsOS_GetSystemTime() > u32Timeout && u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL )
1562 {
1563 bRet = FALSE;
1564 break;
1565 }
1566 }while(u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL);
1567
1568
1569 if(bRet == FALSE || u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL)
1570 {
1571 bRet = FALSE;
1572 goto _CMD_DONE;
1573 }
1574
1575
1576 u32Timeout = MsOS_GetSystemTime()+VIRTUAL_CMD_TIMEOUT;
1577 do
1578 {
1579 //u32Ret = HAL_VPU_EX_DRAMStreamCMDQueueSend_MVD(pstCmdArg->Arg5,E_HVD_CMDQ_CMD,u8cmd|(pstCmdArg->Arg5<<24)|(pstCmdArg->Arg4<<16));
1580 u32Ret = HAL_VPU_EX_DRAMStreamCMDQueueSend(u32Id,(void*)pShm,E_HVD_CMDQ_CMD,u8cmd|(u8VPUIdx<<24)|(pstCmdArg->Arg4<<16));
1581
1582 if(u32Ret == E_HVD_COMMAND_QUEUE_NOT_INITIALED)
1583 {
1584 bRet = FALSE;
1585 break;
1586 }
1587 else if (MsOS_GetSystemTime() > u32Timeout && u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL)
1588 {
1589 bRet = FALSE;
1590 break;
1591 }
1592 }while(u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL);
1593
1594 if(bRet == FALSE || u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL)
1595 {
1596 bRet = FALSE;
1597 goto _CMD_DONE;
1598 }
1599
1600 if(HAL_MVD_IsNeedResponseCommand(u8cmd) == TRUE)
1601 {
1602 u32Timeout = MsOS_GetSystemTime()+VIRTUAL_CMD_TIMEOUT;
1603
1604 while(MsOS_GetSystemTime() < u32Timeout)
1605 {
1606 #if 0
1607 if (HAL_MVD_IsCmdFinished(u8HalIdx, MVD_HANDSHAKE_VIRTUAL_COMMAND))
1608 {
1609 bResponse = TRUE;
1610 break;
1611 }
1612 #else
1613 if(MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VCHANDSHAKE, sizeof(MS_U8)) == 1)
1614 {
1615 bResponse = TRUE;
1616 break;
1617 }
1618 #endif
1619 }
1620
1621 if(bResponse == FALSE) // fail case
1622 {
1623 bRet = FALSE;
1624 goto _CMD_DONE;
1625 }
1626
1627 pstCmdArg->Arg0 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG0, sizeof(MS_U8));
1628 pstCmdArg->Arg1 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG1, sizeof(MS_U8));
1629 pstCmdArg->Arg2 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG2, sizeof(MS_U8));
1630 pstCmdArg->Arg3 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG3, sizeof(MS_U8));
1631 pstCmdArg->Arg4 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG4, sizeof(MS_U8));
1632 }
1633 }
1634 else
1635 #endif
1636 {
1637 if ( HAL_MVD_TimeOut(pstCmdArg->Arg5) == TRUE )
1638 {
1639 bRet = FALSE;
1640 goto _CMD_DONE;
1641 }
1642
1643 HAL_MVD_RegWriteByte(MVD_ARG0, pstCmdArg->Arg0);
1644 HAL_MVD_RegWriteByte(MVD_ARG1, pstCmdArg->Arg1);
1645 HAL_MVD_RegWriteByte(MVD_ARG2, pstCmdArg->Arg2);
1646 HAL_MVD_RegWriteByte(MVD_ARG3, pstCmdArg->Arg3);
1647 HAL_MVD_RegWriteByte(MVD_ARG4, pstCmdArg->Arg4);
1648 HAL_MVD_RegWriteByte(MVD_ARG5, pstCmdArg->Arg5);
1649 HAL_MVD_RegWriteByte(MVD_COMMAND, u8cmd);
1650 if ((CMD_GET_AFD != u8cmd) && (CMD_SLQ_GET_TBL_RPTR != u8cmd) &&
1651 (CMD_SLQ_UPDATE_TBL_WPTR != u8cmd) && (CMD_GET_NEXTDISPFRM != u8cmd) &&
1652 (CMD_DECODE_STATUS != u8cmd) && (CMD_RD_PTS != u8cmd) &&
1653 (CMD_GET_INT_STAT != u8cmd) && (CMD_RD_IO != u8cmd))
1654 {
1655 MVD_DEBUG_FWCMD(printf("MVD_CMD: %x; %x, %x, %x, %x, %x, %x\n", u8cmd, pstCmdArg->Arg0,
1656 pstCmdArg->Arg1, pstCmdArg->Arg2, pstCmdArg->Arg3, pstCmdArg->Arg4, pstCmdArg->Arg5));
1657 }
1658
1659 if ( HAL_MVD_TimeOut(pstCmdArg->Arg5) == TRUE )
1660 {
1661 bRet = FALSE;
1662 goto _CMD_DONE;
1663 }
1664
1665 pstCmdArg->Arg0 = HAL_MVD_RegReadByte(MVD_ARG0);
1666 pstCmdArg->Arg1 = HAL_MVD_RegReadByte(MVD_ARG1);
1667 pstCmdArg->Arg2 = HAL_MVD_RegReadByte(MVD_ARG2);
1668 pstCmdArg->Arg3 = HAL_MVD_RegReadByte(MVD_ARG3);
1669 pstCmdArg->Arg4 = HAL_MVD_RegReadByte(MVD_ARG4);
1670 pstCmdArg->Arg5 = HAL_MVD_RegReadByte(MVD_ARG5);
1671 }
1672
1673 _CMD_DONE:
1674 OSAL_MVD_UnlockHwMutex();
1675
1676 if (!bRet)
1677 {
1678 MVD_DEBUG_FWCMD(printf("%s timeout dump pc\n", __FUNCTION__));
1679 MS_U32 x=0;
1680 for (x=0; x<30; x++)
1681 MVD_DEBUG_FWCMD(printf("0x%x\n", HAL_VPU_EX_GetProgCnt()));
1682 MVD_DEBUG_FWCMD(printf("###\n"));
1683 }
1684
1685 return bRet;
1686 }
1687
HAL_MVD_SetSyncClk(MS_BOOL bEnable)1688 void HAL_MVD_SetSyncClk(MS_BOOL bEnable)
1689 {
1690 MS_ASSERT(0==bEnable);//Notice: Euclid & T3 have no sync_mode; Bit4 must be 0.
1691
1692 OSAL_MVD_LockHwMutex();
1693 HAL_MVD_RegWriteBit(MVD_CTRL, bEnable, MVD_CTRL_CLK_SYNCMODE);
1694 OSAL_MVD_UnlockHwMutex();
1695
1696 return;
1697 }
1698
HAL_MVD_InitHW(VPU_EX_SourceType SourceType,VPU_EX_DecoderType eDecType)1699 MS_BOOL HAL_MVD_InitHW(VPU_EX_SourceType SourceType,VPU_EX_DecoderType eDecType)
1700 {
1701 //Set MVD Clock @ reg_CHIPTOP
1702 HAL_MVD_PowerCtrl(ENABLE);
1703 #ifdef CONFIG_MSTAR_CLKM
1704 if(eDecType == E_VPU_EX_DECODER_MVD)
1705 {
1706 HAL_VPU_EX_SetClkManagement(E_VPU_EX_CLKPORT_MVD_CORE, ENABLE);
1707 }
1708 if(SourceType == E_VPU_EX_INPUT_TSP)
1709 {
1710 HAL_VPU_EX_SetClkManagement(E_VPU_EX_CLKPORT_MVD_PAS, ENABLE);
1711 }
1712 #endif
1713
1714 #ifdef CONFIG_MSTAR_SRAMPD
1715 HAL_MVD_RegWriteBit(REG_CODEC_SRAM_SD_EN, ENABLE, SRAM_SD_EN_MVD);
1716 HAL_MVD_Delayms(1);
1717 #endif
1718
1719 //Set MVD Clock aync
1720 HAL_MVD_SetSyncClk(DISABLE);
1721
1722 //MVD reset
1723 if(!HAL_MVD_RstHW())
1724 {
1725 MVD_DEBUGERROR(printf("MDrv_MVD_MVDInit:MVD4ResetHW failed\n"));
1726 return FALSE;
1727 }
1728 else
1729 {
1730 MVD_DEBUGINFO(printf("MDrv_MVD_MVDInit:MVD4ResetHW success\n"));
1731 }
1732
1733 return TRUE;
1734 }
1735
1736
1737 //------------------------------------------------------------------------------
1738 /// Get MVD firmware version
1739 /// @return -firmware version
1740 //------------------------------------------------------------------------------
HAL_MVD_GetFWVer(MS_U32 u32VpuSid)1741 MS_U32 HAL_MVD_GetFWVer(MS_U32 u32VpuSid)
1742 {
1743 #if 0
1744 return HAL_VPU_EX_GetFWVer(u32VpuSid, E_VPU_EX_FW_VER_MVD_FW);
1745 #else
1746 //UNUSED(u32VpuSid);
1747 MVD_CmdArg mvdcmd;
1748
1749 SETUP_CMDARG(mvdcmd);
1750 mvdcmd.Arg5 = HAL_VPU_EX_GetTaskId(u32VpuSid);
1751 if (HAL_MVD_MVDCommand( CMD_GET_FW_VERSION, &mvdcmd ) == FALSE)
1752 {
1753 MVD_ERROR( printf( "Command: 0x%x fail!!\r\n", CMD_GET_FW_VERSION ) );
1754 return 0;
1755 }
1756 return COMBU32(mvdcmd.Arg3,mvdcmd.Arg2,mvdcmd.Arg1,mvdcmd.Arg0);
1757 #endif
1758 }
1759
1760 //------------------------------------------------------------------------------
1761 /// Get MVD firmware interface version
1762 /// @return -firmware interface version
1763 //------------------------------------------------------------------------------
HAL_MVD_GetFWIfVer(MS_U32 u32VpuSid)1764 MS_U32 HAL_MVD_GetFWIfVer(MS_U32 u32VpuSid)
1765 {
1766 #if 0
1767 return HAL_VPU_EX_GetFWVer(u32VpuSid, E_VPU_EX_FW_VER_MVD_IF);
1768 #else
1769 UNUSED(u32VpuSid);
1770 MVD_CmdArg mvdcmd;
1771
1772 SETUP_CMDARG(mvdcmd);
1773 if (HAL_MVD_MVDCommand( CMD_INTERFACE_VERSION, &mvdcmd ) == FALSE)
1774 {
1775 MVD_ERROR( printf( "Command: 0x%x fail!!\r\n", CMD_INTERFACE_VERSION ) );
1776 return 0;
1777 }
1778 return COMBU32(mvdcmd.Arg3,mvdcmd.Arg2,mvdcmd.Arg1,mvdcmd.Arg0);
1779 #endif
1780 }
1781
1782 //------------------------------------------------------------------------------
1783 /// Check MVD firmware status
1784 /// @return -firmware is ready or not
1785 //------------------------------------------------------------------------------
1786
1787 #ifdef VDEC3
_MVD_Check_FW_Rdy(MS_U32 u32VpuSid)1788 static MS_BOOL _MVD_Check_FW_Rdy(MS_U32 u32VpuSid)
1789 {
1790 MS_U32 u32Id = MVD_GetStreamId(u32VpuSid);
1791 MS_U8 u8VPUIdx = HAL_VPU_EX_GetTaskId(u32Id);
1792 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u32VpuSid);
1793 MS_U32 u32TimeOut = MsOS_GetSystemTime() + 500;
1794 unsigned int* pVersion = (unsigned int*)MsOS_PA2KSEG1(pstMemCfg->u32FWCodeAddr + OFFSET_BASE + u8VPUIdx*0x100000);
1795 MS_BOOL ret = FALSE;
1796
1797 while(MsOS_GetSystemTime() < u32TimeOut)
1798 {
1799 if(((*pVersion) == FW_VERSION) && ((*(pVersion+4)) == INTERFACE_VERSION))
1800 {
1801 ret = TRUE;
1802 break;
1803 }
1804 }
1805
1806 if (ret == FALSE)
1807 {
1808 MVD_ERROR(printf("MVD f/w header version is wrong,%x,%x,%x,%x\n",(*(pVersion+4)), INTERFACE_VERSION,(*pVersion), FW_VERSION));
1809 }
1810
1811 return ret;
1812 }
1813
1814 #else
_MVD_Check_FW_Rdy(MS_U32 u32VpuSid)1815 static MS_BOOL _MVD_Check_FW_Rdy(MS_U32 u32VpuSid)
1816 {
1817 MS_U32 u32TimeOut = 2000;
1818
1819 //check firmware version consistent with header file
1820 while ((INTERFACE_VERSION != HAL_MVD_GetFWIfVer(u32VpuSid)) && (--u32TimeOut));
1821 if (u32TimeOut == 0)
1822 {
1823 MVD_ERROR(printf("MVD_FW_IF_Version=%lx inconsistent with header file(%x)!\n",
1824 HAL_MVD_GetFWIfVer(u32VpuSid), INTERFACE_VERSION));
1825 return FALSE;
1826 }
1827
1828 if (FW_VERSION != HAL_MVD_GetFWVer(u32VpuSid))
1829 {
1830 MVD_DEBUGINFO(printf("Warning! FWBinVer(%lx) != FWHdrVer(%x)\n", HAL_MVD_GetFWVer(u32VpuSid), FW_VERSION));
1831 }
1832 MVD_DEBUGINFO(printf("MVD version Interface = %x, FW = %x\n", INTERFACE_VERSION, FW_VERSION));
1833
1834 return TRUE;
1835 }
1836 #endif
_DumpCtrl(MS_U8 u8Idx)1837 MS_BOOL _DumpCtrl(MS_U8 u8Idx)
1838 {
1839 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
1840
1841 //printf("u32VA=0x%lx, PA=0x%x\n", u32VA, pstMemCfg->u32FWCodeAddr);
1842 struct _ctl_info *ctl_ptr = (struct _ctl_info *)
1843 HAL_MVD_PA2NonCacheSeg(pstMemCfg->u32FWCodeAddr + CTL_INFO_ADDR);
1844 MS_U32 u32timeout = HAL_MVD_GetTime() + 1000;//u32HVDCmdTimeout;
1845
1846 HAL_MVD_ReadMemory();
1847
1848 MVD_DEBUGINFO(printf("version=0x%x, statue=0x%x, last_ctl_cmd=0x%x, last_ctl_arg=0x%x\n",
1849 ctl_ptr->verion, ctl_ptr->statue, ctl_ptr->last_ctl_cmd, ctl_ptr->last_ctl_arg));
1850
1851 while (CTL_TASK_CMDRDY != ctl_ptr->statue)
1852 {
1853 if (HAL_MVD_GetTime() > u32timeout)
1854 {
1855 MVD_DEBUGERROR(printf("CTRL timeout!!! %d\n", __LINE__));
1856 return FALSE;
1857 }
1858 }
1859
1860 MVD_DEBUGINFO(printf("Version=0x%x, statue=0x%x, last_ctl_cmd=0x%x, last_ctl_arg=0x%x\n",
1861 ctl_ptr->verion, ctl_ptr->statue, ctl_ptr->last_ctl_cmd, ctl_ptr->last_ctl_arg));
1862
1863 MS_U8 i;
1864
1865 for (i = 0; i < 4; i++)
1866 {
1867 MVD_DEBUGINFO(printf("%s: Task %d, status=%d\n", __FUNCTION__, i, ctl_ptr->task_statue[i]));
1868 }
1869 return TRUE;
1870 }
1871
1872
MVD_MapVpuSrcType(MVD_SrcMode eSrcMode)1873 static VPU_EX_SourceType MVD_MapVpuSrcType(MVD_SrcMode eSrcMode)
1874 {
1875 VPU_EX_SourceType eVpuSrcType = E_VPU_EX_INPUT_NONE;
1876 switch (eSrcMode)
1877 {
1878 case E_MVD_TS_MODE:
1879 case E_MVD_TS_FILE_MODE:
1880 eVpuSrcType = E_VPU_EX_INPUT_TSP;
1881 break;
1882
1883 case E_MVD_SLQ_TBL_MODE:
1884 case E_MVD_SLQ_MODE:
1885 case E_MVD_FILE_MODE:
1886 eVpuSrcType = E_VPU_EX_INPUT_FILE;
1887 break;
1888
1889 case E_MVD_SRC_UNKNOWN:
1890 default:
1891 break;
1892 }
1893 return eVpuSrcType;
1894 }
1895
MVD_GetTaskInfo(VPU_EX_TaskInfo * pstTaskInfo,MS_U8 u8Idx,HAL_VPU_StreamId eVpuId)1896 static void MVD_GetTaskInfo(VPU_EX_TaskInfo* pstTaskInfo, MS_U8 u8Idx, HAL_VPU_StreamId eVpuId)
1897 {
1898 pstTaskInfo->u32Id = (u8Idx << 8 | eVpuId);
1899 pstTaskInfo->eDecType = E_VPU_EX_DECODER_MVD;
1900 pstTaskInfo->eVpuId = eVpuId;
1901 pstTaskInfo->eSrcType = MVD_MapVpuSrcType(HAL_MVD_GetSrcMode(u8Idx));
1902 pstTaskInfo->u32HeapSize = MVD_DRAM_SIZE;
1903 }
1904
1905
HAL_MVD_CreateTask(MS_U8 u8Idx,HAL_VPU_StreamId eVpuId,MS_BOOL bShareBBU)1906 MS_BOOL HAL_MVD_CreateTask(MS_U8 u8Idx, HAL_VPU_StreamId eVpuId, MS_BOOL bShareBBU)
1907 {
1908 MS_BOOL bRet = FALSE;
1909 MS_BOOL bFWdecideFB = FALSE;
1910 MVD_FWCfg* pstCfg = HAL_MVD_GetFWCfg(u8Idx);
1911 HAL_VPU_EX_SetFWReload(!(pstCfg->bNotReload));
1912
1913 MVD_DEBUGINFO(printf("\n\n Create Task(%x)!!!\n", u8Idx));
1914 VPU_EX_TaskInfo stTaskInfo;
1915 MVD_GetTaskInfo(&stTaskInfo, u8Idx, eVpuId);
1916
1917 VPU_EX_FWCodeCfg stVpuFWCfg;
1918 VPU_EX_NDecInitPara stVpuInitPara;
1919 stVpuInitPara.pFWCodeCfg = &stVpuFWCfg;
1920 stVpuInitPara.pTaskInfo = &stTaskInfo;
1921 stVpuInitPara.pVLCCfg = NULL;
1922
1923 MVD_MEMCfg* pMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
1924 stVpuFWCfg.u32BinAddr = HAL_MVD_PA2NonCacheSeg(pMemCfg->u32FWBinAddr);
1925 stVpuFWCfg.u32BinSize = pMemCfg->u32FWBinSize;
1926 stVpuFWCfg.u32DstAddr = HAL_MVD_PA2NonCacheSeg(pMemCfg->u32FWCodeAddr);
1927 stVpuFWCfg.u32DstSize = pMemCfg->u32FWCodeSize;
1928 stVpuFWCfg.u8SrcType = pMemCfg->eFWSrcType;
1929
1930 #ifdef VDEC3
1931 VPU_EX_FBCfg pFBCfg;
1932 stVpuInitPara.pFBCfg = &pFBCfg;
1933
1934 if(pMVDHalContext->bCMAUsed == TRUE)
1935 {
1936 stVpuInitPara.pFBCfg->u32FrameBufAddr = (MS_VIRT)pMVDHalContext->cmaInitParam.heap_miu_start_offset;
1937 stVpuInitPara.pFBCfg->u32FrameBufSize = (MS_VIRT)pMVDHalContext->cmaInitParam.heap_length;
1938 bFWdecideFB = TRUE;
1939
1940 }
1941 stTaskInfo.u8HalId = u8Idx;
1942 pMVDHalContext->_stMVDStream[u8Idx].u32SLQId = HAL_VPU_EX_GetBBUId(stTaskInfo.u32Id, &stTaskInfo, bShareBBU);
1943 if(pMVDHalContext->_stMVDStream[u8Idx].u32SLQId == HAL_VPU_INVALID_BBU_ID)
1944 {
1945 MVD_DEBUGINFO(printf("ERROR!!!MVD GetBBU Id Fail \n"));
1946 }
1947 else
1948 {
1949 bRet = HAL_VPU_EX_TaskCreate((MS_U32)eVpuId, (void*)&stVpuInitPara, bFWdecideFB, pMVDHalContext->_stMVDStream[u8Idx].u32SLQId);
1950 }
1951
1952 if(bRet == FALSE)
1953 {
1954 if(!HAL_VPU_EX_FreeBBUId(stTaskInfo.u32Id, pMVDHalContext->_stMVDStream[u8Idx].u32SLQId, &stTaskInfo))
1955 {
1956 MVD_DEBUGERROR(printf("[%s][%d]ERROR!!! Free BBU Id Fail !!!\n",__FUNCTION__,__LINE__));
1957 }
1958 }
1959 #else
1960 bRet = HAL_VPU_EX_TaskCreate((MS_U32)eVpuId, (void*)&stVpuInitPara);
1961 #endif
1962 MVD_DEBUGINFO(printf(" Create Task!!! bRet=%x ###\n\n", bRet));
1963 _DumpCtrl(u8Idx);
1964
1965 return bRet;
1966 }
1967
HAL_MVD_DeleteTask(MS_U8 u8Idx,HAL_VPU_StreamId eVpuId)1968 MS_BOOL HAL_MVD_DeleteTask(MS_U8 u8Idx, HAL_VPU_StreamId eVpuId)
1969 {
1970 MS_BOOL bRet = FALSE;
1971 MVD_DEBUGINFO(printf("\n\n Delete Task(%x)!!!\n", u8Idx));
1972
1973 VPU_EX_TaskInfo stTaskInfo;
1974 MVD_GetTaskInfo(&stTaskInfo, u8Idx, eVpuId);
1975
1976 VPU_EX_FWCodeCfg stVpuFWCfg;
1977 VPU_EX_NDecInitPara stVpuInitPara;
1978 stVpuInitPara.pFWCodeCfg = &stVpuFWCfg;
1979 stVpuInitPara.pTaskInfo = &stTaskInfo;
1980
1981 MVD_MEMCfg* pMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
1982 stVpuFWCfg.u32BinAddr = HAL_MVD_PA2NonCacheSeg(pMemCfg->u32FWBinAddr);
1983 stVpuFWCfg.u32BinSize = pMemCfg->u32FWBinSize;
1984 stVpuFWCfg.u32DstAddr = HAL_MVD_PA2NonCacheSeg(pMemCfg->u32FWCodeAddr);
1985 stVpuFWCfg.u8SrcType = pMemCfg->eFWSrcType;
1986
1987 #ifdef VDEC3
1988 if(!HAL_VPU_EX_FreeBBUId(stTaskInfo.u32Id, pMVDHalContext->_stMVDStream[u8Idx].u32SLQId, &stTaskInfo))
1989 {
1990 MVD_DEBUGINFO(printf("ERROR!!! Free BBU Id Fail !!!\n"));
1991 }
1992 #endif
1993 bRet = HAL_VPU_EX_TaskDelete((MS_U32) eVpuId, &stVpuInitPara);
1994 MVD_DEBUGINFO(printf(" Delete Task!!! ###\n\n"));
1995 _DumpCtrl(u8Idx);
1996 return bRet;
1997 }
1998
HAL_MVD_InitFW(MS_U32 u32VpuSid)1999 MS_BOOL HAL_MVD_InitFW(MS_U32 u32VpuSid)
2000 {
2001 //to fix the timing issue of getting FWIfVer on Chakra2
2002 HAL_MVD_Delayms(1);
2003
2004 //check FW ready
2005 if ( !_MVD_Check_FW_Rdy(u32VpuSid))
2006 {
2007 MS_ASSERT(0);
2008 return FALSE;
2009 }
2010
2011 #if 0
2012 if(pMVDHalContext->_stMVDStream[0].bUsed == FALSE && pMVDHalContext->_stMVDStream[1].bUsed == FALSE) // no mvd is used
2013 {
2014 MVD_CmdArg mvdcmd;
2015 SETUP_CMDARG(mvdcmd);
2016 mvdcmd.Arg0 = 1; //reset mvd engine,if have only one mvd
2017 SET_DECNUM(mvdcmd, ((MS_U8)u32VpuSid));
2018 if (HAL_MVD_MVDCommand( CMD_SW_RESET, &mvdcmd ) == FALSE)
2019 {
2020 MVD_ERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SW_RESET ) );
2021 return FALSE;
2022 }
2023 }
2024 #endif
2025 return TRUE;
2026 }
2027
2028 #define _MVD_INIT_FAIL_RET() \
2029 do { \
2030 HAL_MVD_SetIsUsed(u8HalIdx, FALSE); \
2031 return FALSE; \
2032 } while (0)
2033
2034
HAL_MVD_Init(MS_U8 u8HalIdx,MVD_CodecType eCodecType,MS_U32 u32VpuSid,MS_BOOL bShareBBU)2035 MS_BOOL HAL_MVD_Init(MS_U8 u8HalIdx, MVD_CodecType eCodecType, MS_U32 u32VpuSid, MS_BOOL bShareBBU)
2036 {
2037 //OSAL_MVD_MutexInit();
2038 MS_BOOL no_use = FALSE;
2039 MS_BOOL ret;
2040
2041 ret = MDrv_MVD_AUTH_IPCheck(eCodecType,&no_use);
2042 if(ret == FALSE)
2043 {
2044 return FALSE;
2045 }
2046
2047 if (!HAL_MVD_CreateTask(u8HalIdx, (HAL_VPU_StreamId)u32VpuSid, bShareBBU))
2048 {
2049 _MVD_INIT_FAIL_RET();
2050 }
2051
2052 pMVDHalContext->bStopped[u8HalIdx] = FALSE;
2053
2054 if (!HAL_MVD_InitFW(u8HalIdx))
2055 {
2056 MVD_DEBUGERROR(printf("%s:HAL_MVD_InitFW(%x) failed\n", __FUNCTION__, u8HalIdx));
2057 if (!HAL_MVD_DeleteTask(u8HalIdx, (HAL_VPU_StreamId)u32VpuSid))
2058 {
2059 MVD_DEBUGERROR(printf("%s:HAL_MVD_DeleteTask failed\n", __FUNCTION__));
2060 }
2061
2062 _MVD_INIT_FAIL_RET();
2063 }
2064 else
2065 {
2066 MVD_DEBUGINFO(printf("%s:HAL_MVD_InitFW(%x) success\n", __FUNCTION__, u8HalIdx));
2067 }
2068
2069 HAL_MVD_SetIsUsed(u8HalIdx, TRUE);
2070
2071 return TRUE;
2072 }
2073
2074 #define _MVD_CMDRDY ((HAL_MVD_RegReadByte(MVD_STATUS) & MVD_STATUS_READY) == MVD_STATUS_READY)
2075 //------------------------------------------------------------------------------
2076 /// Check if MVD command is ready
2077 /// @return TRUE or FALSE
2078 /// - TRUE, Success to process the command
2079 /// - FALSE, Failed due to timeout
2080 //------------------------------------------------------------------------------
HAL_MVD_GetCmdRdy(void)2081 MS_BOOL HAL_MVD_GetCmdRdy(void)
2082 {
2083 MS_U32 timeoutTick = 2000;
2084
2085 while ((!_MVD_CMDRDY) && ((timeoutTick--)!=0));
2086
2087 if (0 == timeoutTick)
2088 return FALSE;
2089 else
2090 return TRUE;
2091 }
2092
HAL_MVD_CheckIdle(void)2093 MS_BOOL HAL_MVD_CheckIdle(void)
2094 {
2095 MS_BOOL bIsIdle = FALSE;
2096 MVD_CmdArg mvdcmd;
2097
2098 //issue CheckIdle command
2099 SETUP_CMDARG(mvdcmd);
2100 SET_CMD_RET_FALSE(CMD_MVD_IDLE, &mvdcmd);
2101
2102 bIsIdle = (mvdcmd.Arg0 == 1);
2103 if (HAL_MVD_GetCmdRdy())
2104 {
2105 return bIsIdle;
2106 }
2107 else
2108 {
2109 return FALSE;
2110 }
2111 }
2112
2113
_MVD_SoftRstHW(void)2114 static MS_BOOL _MVD_SoftRstHW(void)
2115 {
2116 return FALSE;
2117 }
2118
2119 //------------------------------------------------------------------------------
2120 /// Soft-reset MVD
2121 /// Ref AP note p.12 HK2MVD Reset Flow
2122 /// @return TRUE or FALSE
2123 /// - TRUE, Success to soft-reset MVD
2124 /// - FALSE, Failed. Need init MVD again.
2125 //------------------------------------------------------------------------------
HAL_MVD_SoftRstHW(void)2126 MS_BOOL HAL_MVD_SoftRstHW(void)
2127 {
2128 MS_U32 timetick = 2000;
2129
2130 if (HAL_MVD_GetCmdRdy())
2131 {
2132 //idle check
2133 while ((!HAL_MVD_CheckIdle()) && ((timetick--)!=0));
2134
2135 //either MVD is idle or timeout, do ENG/SLQ reset
2136 return _MVD_SoftRstHW(); //Reset HW engine
2137 }
2138 else
2139 {
2140 return FALSE; //here means "CPU hanging"
2141 }
2142 }
2143
2144 //------------------------------------------------------------------------------
2145 /// Clean the IRQ bit (in interrupt handler should call this function while the
2146 /// interrupt has been triggered.
2147 /// @param none
2148 /// @return none
2149 /// @internal
2150 //------------------------------------------------------------------------------
HAL_MVD_ClearIRQ(void)2151 void HAL_MVD_ClearIRQ(void)
2152 {
2153 OSAL_MVD_LockHwMutex();
2154 HAL_MVD_RegWriteBit(MVD_CTRL, 1, MVD_CTRL_CLR_INT);
2155 OSAL_MVD_UnlockHwMutex();
2156 return;
2157 }
2158
2159 //------------------------------------------------------------------------------
2160 /// Set display speed.
2161 ///FW use (# of B frames) / (# of decode frames) < Ratio this formula to adjustment.
2162 ///Once if the ratio is 1, that means, whenever (#Bframes / #decoded) < 1, then
2163 ///FW would drop the B frame.
2164 ///In other words, once AP need to back to normal mode, AP have to set the arg0 to 0.
2165 //------------------------------------------------------------------------------
HAL_MVD_SetSpeed(MS_U8 u8Idx,MVD_SpeedType eSpeedType,MS_U8 u8Multiple)2166 MS_BOOL HAL_MVD_SetSpeed(MS_U8 u8Idx, MVD_SpeedType eSpeedType, MS_U8 u8Multiple)
2167 {
2168 MVD_CmdArg mvdcmd;
2169
2170 SETUP_CMDARG(mvdcmd);
2171
2172 if (E_MVD_SPEED_FAST == eSpeedType)
2173 mvdcmd.Arg0 = 1; //fast forward
2174 else if (E_MVD_SPEED_SLOW == eSpeedType)
2175 mvdcmd.Arg0 = 2; //slow motion
2176 else
2177 mvdcmd.Arg0 = 0; //normal speed
2178
2179 if (u8Multiple == 1)
2180 {
2181 mvdcmd.Arg0 = 0;
2182 //The only way to be NORMAL speed.
2183 }
2184
2185 mvdcmd.Arg1 = u8Multiple;
2186
2187 if(pMVDHalContext->bTrickPlay2xAVSync[u8Idx] == TRUE && eSpeedType == E_MVD_SPEED_FAST && u8Multiple == 2)
2188 {
2189 mvdcmd.Arg2 = 1;
2190 }
2191 else
2192 {
2193 mvdcmd.Arg2 = 0;
2194 }
2195
2196 SET_DECNUM(mvdcmd, u8Idx);
2197 SET_CMD_RET_FALSE(CMD_DISP_SPEED_CTRL, &mvdcmd);
2198 return TRUE;
2199 }
2200
2201 //------------------------------------------------------------------------------
2202 /// Set frame buffer address to MVD
2203 /// @param -u32addr \b IN : start address
2204 //------------------------------------------------------------------------------
HAL_MVD_SetFrameBuffAddr(MS_U8 u8Idx,MS_VIRT u32addr,MS_U8 u8fbMode)2205 void HAL_MVD_SetFrameBuffAddr(MS_U8 u8Idx, MS_VIRT u32addr, MS_U8 u8fbMode)
2206 {
2207 MVD_CmdArg mvdcmd;
2208 if(pMVDHalContext->bCMAUsed)
2209 {
2210 u8fbMode = MVD_CMA_MODE;
2211 }
2212
2213 if ((u32addr>>3) > MAX_ADD_28BIT)// TODO: fixme, in 64bits system, address may be more than 28 bits
2214 {
2215 MVD_DEBUGERROR(printf("MDrv_MVD_SetFrameBuffAddr: only support 28bit add!\n"));
2216 return;
2217 }
2218
2219 MS_ASSERT((u32addr%8)==0);
2220 u32addr >>= 3;
2221
2222 SETUP_CMDARG(mvdcmd);
2223 mvdcmd.Arg0 = L_WORD(u32addr);
2224 mvdcmd.Arg1 = H_WORD(u32addr);
2225 mvdcmd.Arg2 = L_DWORD(u32addr);
2226
2227 //Frame Buffer Mode Setting
2228 mvdcmd.Arg3 = u8fbMode | ((u32addr>>24)&0x0f);
2229 mvdcmd.Arg4 = u8fbMode & 0xff;
2230 MVD_DEBUGINFO(printf("FramebufferAdd 0x%lx, FB Mode 0x%x, arg3=0x%x\n", (unsigned long)u32addr, u8fbMode, mvdcmd.Arg3));
2231 SET_DECNUM(mvdcmd, u8Idx);
2232 if (HAL_MVD_MVDCommand( CMD_FB_BASE, &mvdcmd ) == FALSE)
2233 {
2234 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FB_BASE ) );
2235 return;
2236 }
2237
2238 return;
2239 }
2240
2241 //------------------------------------------------------------------------------
2242 /// Set header buffer address to MVD
2243 /// @param -u32addr \b IN : start address
2244 //------------------------------------------------------------------------------
HAL_MVD_SetHeaderBufferAddr(MS_U8 u8Idx,MS_VIRT u32addr)2245 void HAL_MVD_SetHeaderBufferAddr (MS_U8 u8Idx, MS_VIRT u32addr )
2246 {
2247 MVD_CmdArg mvdcmd;
2248
2249 MS_ASSERT((u32addr%8)==0);
2250 u32addr >>= 3;
2251
2252 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2253 if (HAL_MVD_MVDCommand( CMD_HEADER_INFO_BUF, &mvdcmd ) == FALSE)
2254 {
2255 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_HEADER_INFO_BUF ) );
2256 }
2257 return;
2258 }
2259
2260 //------------------------------------------------------------------------------
2261 /// Set vol info buffer address to MVD
2262 /// @param -u32addr \b IN : start address
2263 //------------------------------------------------------------------------------
HAL_MVD_SetVolInfoBufferAddr(MS_U8 u8Idx,MS_VIRT u32addr)2264 void HAL_MVD_SetVolInfoBufferAddr (MS_U8 u8Idx, MS_VIRT u32addr )
2265 {
2266 MVD_CmdArg mvdcmd;
2267
2268 MS_ASSERT((u32addr%8)==0);
2269 u32addr >>= 3;
2270
2271 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2272 if (HAL_MVD_MVDCommand( CMD_VOL_INFO_BUF, &mvdcmd ) == FALSE)
2273 {
2274 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_VOL_INFO_BUF ) );
2275 }
2276 return;
2277 }
2278
2279 //------------------------------------------------------------------------------
2280 /// Set frame info buffer address to MVD
2281 /// @param -u32addr \b IN : start address
2282 //------------------------------------------------------------------------------
HAL_MVD_SetFrameInfoBufferAddr(MS_U8 u8Idx,MS_VIRT u32addr)2283 void HAL_MVD_SetFrameInfoBufferAddr (MS_U8 u8Idx, MS_VIRT u32addr )
2284 {
2285 MVD_CmdArg mvdcmd;
2286
2287 MS_ASSERT((u32addr%8)==0);
2288 u32addr >>= 3;
2289
2290 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2291 if (HAL_MVD_MVDCommand( CMD_FRAME_INFO_BUF, &mvdcmd ) == FALSE)
2292 {
2293 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FRAME_INFO_BUF ) );
2294 }
2295 return;
2296 }
2297
2298 //------------------------------------------------------------------------------
2299 /// Set IAP buffer address to MVD
2300 /// @param -u32addr \b IN : start address
2301 //------------------------------------------------------------------------------
HAL_MVD_SetIAPBufferAddr(MS_U8 u8Idx,MS_VIRT u32addr)2302 void HAL_MVD_SetIAPBufferAddr (MS_U8 u8Idx, MS_VIRT u32addr )
2303 {
2304 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
2305 MVD_CmdArg mvdcmd;
2306 MS_ASSERT((u32addr%8192)==0);
2307 u32addr >>= 13;
2308
2309 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2310 mvdcmd.Arg4 = pstMemCfg->u8FBMiuSel;
2311 if (HAL_MVD_MVDCommand( CMD_IAP_BUF_START, &mvdcmd ) == FALSE)
2312 {
2313 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_IAP_BUF_START ) );
2314 }
2315 return;
2316 }
2317
2318 //------------------------------------------------------------------------------
2319 /// Set Data Partition buffer address to MVD
2320 /// @param -u32addr \b IN : start address
2321 //------------------------------------------------------------------------------
HAL_MVD_SetDPBufferAddr(MS_U8 u8Idx,MS_VIRT u32addr)2322 void HAL_MVD_SetDPBufferAddr (MS_U8 u8Idx, MS_VIRT u32addr )
2323 {
2324 MVD_CmdArg mvdcmd;
2325 MS_ASSERT((u32addr%8)==0);
2326 u32addr >>= 3;
2327
2328 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2329 if (HAL_MVD_MVDCommand( CMD_DP_BUF_START, &mvdcmd ) == FALSE)
2330 {
2331 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DP_BUF_START ) );
2332 }
2333 return;
2334 }
2335
2336 //------------------------------------------------------------------------------
2337 /// Set Motion Vector buffer address to MVD
2338 /// @param -u32addr \b IN : start address
2339 //------------------------------------------------------------------------------
HAL_MVD_SetMVBufferAddr(MS_U8 u8Idx,MS_VIRT u32addr)2340 void HAL_MVD_SetMVBufferAddr (MS_U8 u8Idx, MS_VIRT u32addr )
2341 {
2342 MVD_CmdArg mvdcmd;
2343 MS_ASSERT((u32addr%2048)==0);
2344 u32addr >>= 3;
2345
2346 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2347 if (HAL_MVD_MVDCommand( CMD_MV_BUF_START, &mvdcmd ) == FALSE)
2348 {
2349 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_MV_BUF_START ) );
2350 }
2351 return;
2352 }
2353
_MVD_SetUserDataBufStart(MS_U8 u8Idx,MS_VIRT u32addr,MS_U8 u8arg3)2354 static void _MVD_SetUserDataBufStart(MS_U8 u8Idx, MS_VIRT u32addr, MS_U8 u8arg3)
2355 {
2356 MVD_CmdArg mvdcmd;
2357
2358 MS_ASSERT((u32addr%8)==0);
2359 u32addr >>= 3;
2360 MVD_DEBUGINFO(printf("%s add=0x%lx arg3=0x%x\n", __FUNCTION__, (unsigned long)u32addr, u8arg3));
2361
2362 SETUP_CMDARG(mvdcmd);
2363 mvdcmd.Arg0 = L_WORD(u32addr);
2364 mvdcmd.Arg1 = H_WORD(u32addr);
2365 mvdcmd.Arg2 = L_DWORD(u32addr);
2366 mvdcmd.Arg4 = H_DWORD(u32addr);
2367 mvdcmd.Arg3 = u8arg3;
2368 SET_DECNUM(mvdcmd, u8Idx);
2369 if (HAL_MVD_MVDCommand( CMD_USER_BUF_START, &mvdcmd ) == FALSE)
2370 {
2371 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_USER_BUF_START ) );
2372 return;
2373 }
2374 return;
2375 }
2376
_MVD_SetUserDataBufSize(MS_U8 u8Idx,MS_U32 u32size,MS_U8 u8arg3)2377 static void _MVD_SetUserDataBufSize(MS_U8 u8Idx, MS_U32 u32size, MS_U8 u8arg3)
2378 {
2379 MVD_CmdArg mvdcmd;
2380
2381 MS_ASSERT((u32size%8)==0);
2382 u32size >>= 3;
2383 MVD_DEBUGINFO(printf("%s add=0x%x arg3=0x%x\n", __FUNCTION__, u32size, u8arg3));
2384
2385 SETUP_CMDARG(mvdcmd);
2386 mvdcmd.Arg0 = L_WORD(u32size);
2387 mvdcmd.Arg1 = H_WORD(u32size);
2388 mvdcmd.Arg2 = L_DWORD(u32size);
2389 mvdcmd.Arg4 = H_DWORD(u32size);
2390 mvdcmd.Arg3 = u8arg3;
2391 if(mvdcmd.Arg3 <= 1) //mean 608 and 708 in MM RVU
2392 {
2393 mvdcmd.Arg2 = 7;//ntsc1+ntsc2+atsc
2394 mvdcmd.Arg4 = 0;
2395 }
2396 SET_DECNUM(mvdcmd, u8Idx);
2397 if (HAL_MVD_MVDCommand( CMD_USER_BUF_SIZE, &mvdcmd ) == FALSE)
2398 {
2399 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_USER_BUF_SIZE ) );
2400 return;
2401 }
2402 return;
2403 }
2404
2405 //------------------------------------------------------------------------------
2406 /// Set user data buffer address to MVD
2407 /// @param -u32addr \b IN : start address
2408 //------------------------------------------------------------------------------
HAL_MVD_SetUserDataBuf(MS_U8 u8Idx,MS_VIRT u32addr,MS_U32 u32size)2409 void HAL_MVD_SetUserDataBuf(MS_U8 u8Idx, MS_VIRT u32addr, MS_U32 u32size)
2410 {
2411 MS_U8 u8ccType = 0;
2412
2413 MS_ASSERT((u32addr%8)==0);
2414 MS_ASSERT((u32size%8)==0);
2415 #ifdef REDLION_LINUX_KERNEL_ENVI
2416 u8ccType = 2;
2417 #elif defined(MVD_SUPPORT_X4_CC)
2418 u8ccType = 4; //display order
2419 #else
2420 u8ccType = 2;// 2 for testing 0;
2421 #endif
2422
2423 #if defined(MVD_SUPPORT_X4_CC)
2424 //set decoding buffer address
2425 _MVD_SetUserDataBufStart(u8Idx, u32addr+u32size, 3);
2426 #endif
2427
2428 //set CC output buffer address
2429 _MVD_SetUserDataBufStart(u8Idx, u32addr, u8ccType);
2430
2431 #if defined(MVD_SUPPORT_X4_CC)
2432 //set decoding buffer size
2433 _MVD_SetUserDataBufSize(u8Idx, u32size, 3);
2434 #endif
2435
2436 //set CC output buffer size
2437 _MVD_SetUserDataBufSize(u8Idx, u32size, u8ccType);
2438
2439 return;
2440 }
2441
HAL_MVD_SetSLQTblBufStartEnd(MS_U8 u8Idx,MS_VIRT u32start,MS_VIRT u32end)2442 void HAL_MVD_SetSLQTblBufStartEnd(MS_U8 u8Idx, MS_VIRT u32start, MS_VIRT u32end)
2443 {
2444 MVD_CmdArg mvdcmd;
2445 MS_U32 u32val = u32end>>3;
2446 MVD_DEBUGINFO(printf("%s st=0x%lx end=0x%lx\n", __FUNCTION__, (unsigned long)u32start, (unsigned long)u32end));
2447
2448 SET_CMDARG(mvdcmd, u32val, u8Idx);
2449 if (HAL_MVD_MVDCommand( CMD_SLQ_TBL_BUF_END, &mvdcmd ) == FALSE)
2450 {
2451 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLQ_TBL_BUF_END ) );
2452 return;
2453 }
2454
2455 u32val = (u32start)>>3;
2456 SET_CMDARG(mvdcmd, u32val, u8Idx);
2457 if (HAL_MVD_MVDCommand( CMD_SLQ_TBL_BUF_START, &mvdcmd ) == FALSE)
2458 {
2459 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLQ_TBL_BUF_START ) );
2460 return;
2461 }
2462
2463 MVD_DEBUGINFO(printf("%s st=0x%lx end=0x%lx OK!!!\n", __FUNCTION__, (unsigned long)u32start, (unsigned long)u32end));
2464 return;
2465 }
2466
2467 //------------------------------------------------------------------------------
2468 /// Issue StepDisplay command.
2469 /// @return -TRUE for success; FALSE for failure.
2470 //------------------------------------------------------------------------------
HAL_MVD_StepDisp(MS_U8 u8Idx)2471 MS_BOOL HAL_MVD_StepDisp(MS_U8 u8Idx)
2472 {
2473 MVD_CmdArg mvdcmd;
2474
2475 MVD_SetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_STEP_DISP_DONE, sizeof(MS_U8), 0);
2476
2477 SETUP_CMDARG(mvdcmd);
2478 SET_DECNUM(mvdcmd, u8Idx);
2479 SET_CMD_RET_FALSE(CMD_STEP_DISP_DECODE_ONE, &mvdcmd);
2480 if (HAL_MVD_Resume(u8Idx) == FALSE)
2481 {
2482 MVD_DEBUGERROR( printf( "Command: HAL_MVD_Resume fail!!\r\n" ) );
2483 return FALSE;
2484 }
2485
2486 return TRUE;
2487 }
2488
2489 //------------------------------------------------------------------------------
2490 /// Get ES read address for TS file mode.
2491 /// @return ES read address
2492 //------------------------------------------------------------------------------
HAL_MVD_GetTsFileESReadPtr(MS_U8 u8Idx)2493 MS_VIRT HAL_MVD_GetTsFileESReadPtr(MS_U8 u8Idx)
2494 {
2495 MS_VIRT u32Add = 0;
2496 MVD_CmdArg mvdcmd;
2497
2498 SETUP_CMDARG(mvdcmd);
2499 mvdcmd.Arg0 = 2; //ES diff
2500 SET_DECNUM(mvdcmd, u8Idx);
2501 if (HAL_MVD_MVDCommand( CMD_PARSER_READ_POSITION, &mvdcmd ) == TRUE)
2502 {
2503 //in order to latch the newest parser status
2504 //u32Diff = (((MS_U32)mvdcmd.Arg3) <<24) | (((MS_U32)mvdcmd.Arg2) <<16) |
2505 // (((MS_U32)mvdcmd.Arg1) << 8) | (((MS_U32)mvdcmd.Arg0));
2506 }
2507 else
2508 {
2509 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\n", CMD_PARSER_READ_POSITION) );
2510 }
2511
2512 SETUP_CMDARG(mvdcmd);
2513 mvdcmd.Arg0 = 1;
2514 SET_DECNUM(mvdcmd, u8Idx);
2515 if (HAL_MVD_MVDCommand( CMD_PARSER_READ_POSITION, &mvdcmd ) == TRUE)
2516 {
2517 u32Add = (((MS_U32)mvdcmd.Arg3) <<24) |
2518 (((MS_U32)mvdcmd.Arg2) <<16) |
2519 (((MS_U32)mvdcmd.Arg1) << 8) |
2520 (((MS_U32)mvdcmd.Arg0));
2521 }
2522 else
2523 {
2524 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\n", CMD_PARSER_READ_POSITION) );
2525 }
2526
2527 return (u32Add*8);
2528 }
2529
2530 //------------------------------------------------------------------------------
2531 /// Get ES write address for TS file mode.
2532 /// @return ES write address
2533 //------------------------------------------------------------------------------
HAL_MVD_GetTsFileESWritePtr(MS_U8 u8Idx)2534 MS_VIRT HAL_MVD_GetTsFileESWritePtr(MS_U8 u8Idx)
2535 {
2536 MS_VIRT u32Diff = 0;
2537 MS_VIRT u32WrPtr = 0;
2538 MVD_CmdArg mvdcmd;
2539 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
2540 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
2541
2542 SETUP_CMDARG(mvdcmd);
2543 mvdcmd.Arg0 = 2; //ES diff
2544 SET_DECNUM(mvdcmd, u8Idx);
2545 if (HAL_MVD_MVDCommand( CMD_PARSER_READ_POSITION, &mvdcmd ) == TRUE)
2546 {
2547 u32Diff = (((MS_U32)mvdcmd.Arg3) <<24) | (((MS_U32)mvdcmd.Arg2) <<16) |
2548 (((MS_U32)mvdcmd.Arg1) << 8) | (((MS_U32)mvdcmd.Arg0));
2549 }
2550 else
2551 {
2552 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\n", CMD_PARSER_READ_POSITION) );
2553 }
2554
2555 u32WrPtr = u32Diff*8 + HAL_MVD_GetTsFileESReadPtr(u8Idx);
2556 if (u32WrPtr > pstSlqTblInfo->u32ESBuffEnd)
2557 {
2558 MVD_DEBUGINFO(printf("ES wrapping Wr=0x%lx ==> ", (unsigned long)u32WrPtr));
2559 u32WrPtr -= pstMemCfg->u32BSSize;
2560 MVD_DEBUGINFO(printf("0x%lx\n", (unsigned long)u32WrPtr));
2561 }
2562 return u32WrPtr;
2563 }
2564
2565 //------------------------------------------------------------------------------
2566 /// Enable/Disable firmware to show the last frame.
2567 /// @return -TRUE for success; FALSE for failure.
2568 //------------------------------------------------------------------------------
HAL_MVD_EnableLastFrameShow(MS_U8 u8Idx,MS_BOOL bEnable)2569 MS_BOOL HAL_MVD_EnableLastFrameShow(MS_U8 u8Idx, MS_BOOL bEnable)
2570 {
2571 MVD_CmdArg mvdcmd;
2572 MVD_SrcMode curSrcMode = HAL_MVD_GetSrcMode(u8Idx);
2573 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
2574 MS_VIRT* pu32FileEndPtr = &pstSlqTblInfo->u32FileEndPtr;
2575
2576 if (E_MVD_SLQ_TBL_MODE == curSrcMode)
2577 {
2578 #if SLQ_NEW_PUSH
2579 if (pstSlqTblInfo->pSlqStatus->bSlqCtrlBit)
2580 {
2581 pstSlqTblInfo->pDrvSlqTbl->u32WrPtr = pstSlqTblInfo->pSlqStatus->u32VaildWptrAddr + SLQ_ENTRY_LEN;
2582 }
2583 #endif //
2584 //save current writePtr
2585 if (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr != pstSlqTblInfo->pDrvSlqTbl->u32EndAdd)
2586 {
2587 *pu32FileEndPtr = pstSlqTblInfo->pDrvSlqTbl->u32WrPtr;
2588 }
2589 else
2590 {
2591 *pu32FileEndPtr = pstSlqTblInfo->pDrvSlqTbl->u32StAdd;
2592 }
2593 MVD_DEBUGINFO(printf("fe=%lx, rd=%lx, wr=%lx\n", (unsigned long)*pu32FileEndPtr,
2594 (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32RdPtr, (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32WrPtr));
2595 }
2596
2597 SETUP_CMDARG(mvdcmd);
2598 mvdcmd.Arg0 = bEnable;
2599 SET_DECNUM(mvdcmd, u8Idx);
2600 SET_CMD_RET_FALSE(CMD_ENABLE_LAST_FRAME_SHOW, &mvdcmd);
2601 return TRUE;
2602 }
2603
2604
HAL_MVD_SlqTblRst(MS_U8 u8Idx)2605 MS_BOOL HAL_MVD_SlqTblRst(MS_U8 u8Idx)
2606 {
2607 MVD_CmdArg mvdcmd;
2608 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
2609
2610 SETUP_CMDARG(mvdcmd);
2611 SET_DECNUM(mvdcmd, u8Idx);
2612 SET_CMD_RET_FALSE(CMD_VC1_HW_SLQ_RESET, &mvdcmd);
2613 pstSlqTblInfo->bEnSlqTblHkCtrl = FALSE;
2614 return TRUE;
2615 }
2616
HAL_MVD_SeekToPTS(MS_U8 u8Idx,MS_U32 u32Pts)2617 MS_BOOL HAL_MVD_SeekToPTS(MS_U8 u8Idx, MS_U32 u32Pts)
2618 {
2619 MVD_CmdArg mvdcmd;
2620
2621 SET_CMDARG(mvdcmd, u32Pts, u8Idx);
2622 SET_CMD_RET_FALSE(CMD_STEP_TO_PTS, &mvdcmd);
2623
2624 if (HAL_MVD_Resume(u8Idx) == FALSE)
2625 {
2626 MVD_DEBUGERROR( printf( "Command: HAL_MVD_Resume fail!!\r\n" ) );
2627 return FALSE;
2628 }
2629 return TRUE;
2630 }
2631
HAL_MVD_SkipToPTS(MS_U8 u8Idx,MS_U32 u32Pts)2632 MS_BOOL HAL_MVD_SkipToPTS(MS_U8 u8Idx, MS_U32 u32Pts)
2633 {
2634 MVD_CmdArg mvdcmd;
2635
2636 SET_CMDARG(mvdcmd, u32Pts, u8Idx);
2637 SET_CMD_RET_FALSE(CMD_SKIP_TO_PTS, &mvdcmd);
2638
2639 if (HAL_MVD_Resume(u8Idx) == FALSE)
2640 {
2641 MVD_DEBUGERROR( printf( "Command: HAL_MVD_Resume fail!!\r\n" ) );
2642 return FALSE;
2643 }
2644 return TRUE;
2645 }
2646
HAL_MVD_TrickPlay(MS_U8 u8Idx,MVD_TrickDec trickDec,MS_U8 u8DispDuration)2647 MS_BOOL HAL_MVD_TrickPlay(MS_U8 u8Idx, MVD_TrickDec trickDec, MS_U8 u8DispDuration)
2648 {
2649 MVD_CmdArg mvdcmd;
2650 MS_U8 u8DecType;
2651
2652 switch (trickDec)
2653 {
2654 case E_MVD_TRICK_DEC_ALL:
2655 u8DecType = 0;
2656 break;
2657 case E_MVD_TRICK_DEC_I:
2658 u8DecType = 1;
2659 break;
2660 case E_MVD_TRICK_DEC_IP:
2661 u8DecType = 2;
2662 break;
2663 default:
2664 return FALSE;
2665 break;
2666 }
2667
2668 SETUP_CMDARG(mvdcmd);
2669 mvdcmd.Arg0 = u8DecType;
2670 mvdcmd.Arg1 = u8DispDuration;
2671 SET_DECNUM(mvdcmd, u8Idx);
2672 SET_CMD_RET_FALSE(CMD_FAST_SLOW, &mvdcmd);
2673
2674 pMVDHalContext->stCtrlCfg[u8Idx].eTrickMode = trickDec;
2675 return TRUE;
2676 }
2677
HAL_MVD_FlushDisplayBuf(MS_U8 u8Idx)2678 MS_BOOL HAL_MVD_FlushDisplayBuf(MS_U8 u8Idx)
2679 {
2680 #define STOP_TIMEOUT 500 //ms
2681 MS_U32 u32StartTime = 0;
2682
2683 HAL_MVD_ResetHandShake(u8Idx, MVD_HANDSHAKE_FLUSHQUEUE_COMMAND);
2684 MVD_CmdArg mvdcmd;
2685 SETUP_CMDARG(mvdcmd);
2686 SET_DECNUM(mvdcmd, u8Idx);
2687 SET_CMD_RET_FALSE(CMD_FLUSH_DISP_QUEUE, &mvdcmd);
2688
2689 u32StartTime = HAL_MVD_GetTime();
2690
2691 while(!HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_FLUSHQUEUE_COMMAND))
2692 {
2693 if ((HAL_MVD_GetTime()-u32StartTime)>STOP_TIMEOUT)
2694 {
2695 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail timeout!!\r\n", CMD_FLUSH_DISP_QUEUE ) );
2696 break;
2697 }
2698 }
2699
2700 return TRUE;
2701 }
2702
2703
HAL_MVD_SetFileModeAVSync(MS_U8 u8Idx,MVD_TIMESTAMP_TYPE eSyncMode)2704 MS_BOOL HAL_MVD_SetFileModeAVSync(MS_U8 u8Idx, MVD_TIMESTAMP_TYPE eSyncMode)
2705 {
2706 MVD_CmdArg mvdcmd;
2707 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
2708
2709 pstCtrlCfg->eFileSyncMode = eSyncMode;
2710 MVD_DEBUGINFO(printf("%s eSyncMode=%d\n", __FUNCTION__, eSyncMode));
2711 SETUP_CMDARG(mvdcmd);
2712 switch (eSyncMode)
2713 {
2714 case E_MVD_TIMESTAMP_PTS:
2715 case E_MVD_TIMESTAMP_PTS_RVU:
2716 mvdcmd.Arg0 = FILE_PTS_MODE;
2717 break;
2718
2719 case E_MVD_TIMESTAMP_DTS:
2720 case E_MVD_TIMESTAMP_DTS_RVU:
2721 mvdcmd.Arg0 = FILE_DTS_MODE;
2722 break;
2723 case E_MVD_TIMESTAMP_NEW_STS:
2724 mvdcmd.Arg0 = FILE_STS_MODE;
2725 break;
2726 case E_MVD_TIMESTAMP_FREERUN:
2727 default:
2728 mvdcmd.Arg0 = NONE_FILE_MODE; //Freerun
2729 break;
2730 }
2731 SET_DECNUM(mvdcmd, u8Idx);
2732 SET_CMD_RET_FALSE(CMD_ENABLE_FILE_SYNC, &mvdcmd);
2733
2734 SETUP_CMDARG(mvdcmd);
2735 switch (eSyncMode) //for set RVU mode
2736 {
2737 case E_MVD_TIMESTAMP_PTS_RVU:
2738 mvdcmd.Arg0 = FILE_PTS_MODE;
2739 break;
2740 case E_MVD_TIMESTAMP_DTS_RVU:
2741 mvdcmd.Arg0 = FILE_DTS_MODE;
2742 break;
2743 case E_MVD_TIMESTAMP_FREERUN:
2744 default:
2745 mvdcmd.Arg0 = 0xFF;
2746 break;
2747 }
2748 SET_DECNUM(mvdcmd, u8Idx);
2749 SET_CMD_RET_FALSE(CMD_RVU_EN, &mvdcmd);
2750 return TRUE;
2751 }
2752
2753
2754
2755
2756 //------------------------------------------------------------------------------
2757 /// Set the start address of PTS table used for SLQ table link mode.
2758 /// @return -TRUE for success; FALSE for failure.
2759 //------------------------------------------------------------------------------
HAL_MVD_SetPtsTblAddr(MS_U8 u8Idx,MS_VIRT u32addr)2760 MS_BOOL HAL_MVD_SetPtsTblAddr(MS_U8 u8Idx, MS_VIRT u32addr)
2761 {
2762 MVD_CmdArg mvdcmd;
2763
2764 MS_ASSERT((u32addr%8)==0);
2765 u32addr >>= 3;
2766
2767 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2768 SET_CMD_RET_FALSE(CMD_PTS_TBL_START, &mvdcmd);
2769 return TRUE;
2770 }
2771
HAL_MVD_SkipToIFrame(MS_U8 u8Idx)2772 MS_BOOL HAL_MVD_SkipToIFrame(MS_U8 u8Idx)
2773 {
2774 MVD_CmdArg mvdcmd;
2775 SETUP_CMDARG(mvdcmd);
2776 SET_DECNUM(mvdcmd, u8Idx);
2777 SET_CMD_RET_FALSE(CMD_START_DEC_STRICT, &mvdcmd);
2778 return TRUE;
2779 }
2780
2781 //Map driver FRC (Frame rate conversion) mode to firmware's.
HAL_MVD_MapFrcMode(MVD_FrcMode eFrcMode)2782 MS_U8 HAL_MVD_MapFrcMode(MVD_FrcMode eFrcMode)
2783 {
2784 MS_U8 frcMode = 0xf;
2785 switch (eFrcMode)
2786 {
2787 case E_MVD_FRC_NORMAL:
2788 frcMode = FrcNormal;
2789 break;
2790 case E_MVD_FRC_DISP_TWICE:
2791 frcMode = FrcDisplayTwice;
2792 break;
2793 case E_MVD_FRC_3_2_PULLDOWN: //film 24 -> 50i
2794 frcMode = Frc32Pulldown;
2795 break;
2796 case E_MVD_FRC_PAL_TO_NTSC:
2797 frcMode = FrcPALtoNTSC;
2798 break;
2799 case E_MVD_FRC_NTSC_TO_PAL:
2800 frcMode = FrcNTSCtoPAL;
2801 break;
2802 case E_MVD_FRC_DISP_ONEFIELD:
2803 frcMode = FrcShowOneFiled;
2804 break;
2805 default:
2806 break;
2807 }
2808 return frcMode;
2809 }
2810
HAL_MVD_DispCtrl(MS_U8 u8Idx,MS_BOOL bDecOrder,MS_BOOL bDropErr,MS_BOOL bDropDisp,MVD_FrcMode eFrcMode)2811 MS_BOOL HAL_MVD_DispCtrl(MS_U8 u8Idx, MS_BOOL bDecOrder, MS_BOOL bDropErr, MS_BOOL bDropDisp, MVD_FrcMode eFrcMode)
2812 {
2813 MVD_CmdArg mvdcmd;
2814 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
2815 MS_BOOL* pbDropErrFrm = &pstCtrlCfg->bDropErrFrm;
2816
2817 SETUP_CMDARG(mvdcmd);
2818 mvdcmd.Arg0 = (MS_U8)bDecOrder;
2819 mvdcmd.Arg1 = (MS_U8)bDropErr;
2820 mvdcmd.Arg2 = (MS_U8)bDropDisp;
2821 mvdcmd.Arg3 = HAL_MVD_MapFrcMode(eFrcMode);
2822 SET_DECNUM(mvdcmd, u8Idx);
2823 SET_CMD_RET_FALSE(CMD_DISPLAY_CTL, &mvdcmd);
2824
2825 pstCtrlCfg->eFrcMode = eFrcMode;
2826
2827 if (*pbDropErrFrm != bDropErr)
2828 {
2829 MVD_DEBUGINFO( printf("bDropErrFrm(%d) != bDropErr(%d)\n", *pbDropErrFrm, bDropErr));
2830 *pbDropErrFrm = bDropErr;
2831 }
2832 pstCtrlCfg->bDropDispfrm = bDropDisp;
2833
2834 return TRUE;
2835 }
2836
2837
HAL_MVD_SkipData(MS_U8 u8Idx)2838 MS_BOOL HAL_MVD_SkipData(MS_U8 u8Idx)
2839 {
2840 MS_U32 u32TimeCnt = 0;
2841 MVD_CmdArg mvdcmd;
2842
2843 HAL_MVD_ResetHandShake(u8Idx, MVD_HANDSHAKE_SKIP_DATA);
2844 SETUP_CMDARG(mvdcmd);
2845 SET_DECNUM(mvdcmd, u8Idx);
2846 SET_CMD_RET_FALSE(CMD_SKIP_DATA, &mvdcmd);
2847
2848 u32TimeCnt = HAL_MVD_GetTime();
2849 while ((HAL_MVD_GetTime() - u32TimeCnt) < SKIP_DATA_TIMEOUT_MS)
2850 {
2851 if (HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_SKIP_DATA))
2852 {
2853 MVD_DEBUGINFO(printf("\nSkip data finished!\n"));
2854 break;
2855 }
2856 }
2857 MVD_DEBUGINFO(printf("====> %s (t1=%u t2=%u diff=%u)\n", __FUNCTION__,
2858 u32TimeCnt, HAL_MVD_GetTime(), (HAL_MVD_GetTime() - u32TimeCnt)));
2859 if (TRUE != HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_SKIP_DATA))
2860 {
2861 MVD_DEBUGINFO(printf("\n***** TS flush timeout *****\n\n"));
2862 return FALSE;
2863 }
2864
2865 return TRUE;
2866 }
2867
HAL_MVD_DispRepeatField(MS_U8 u8Idx,MS_BOOL bEnable)2868 MS_BOOL HAL_MVD_DispRepeatField(MS_U8 u8Idx, MS_BOOL bEnable)
2869 {
2870 MVD_CmdArg mvdcmd;
2871 SETUP_CMDARG(mvdcmd);
2872 mvdcmd.Arg0 = bEnable;
2873 SET_DECNUM(mvdcmd, u8Idx);
2874 SET_CMD_RET_FALSE(CMD_REPEAT_MODE, &mvdcmd);
2875 return TRUE;
2876 }
2877
2878 //------------------------------------------------------------------------------
2879 /// Pause display.
2880 /// @return -TRUE for success; FALSE for failure
2881 //------------------------------------------------------------------------------
HAL_MVD_PauseDisp(MS_U8 u8Idx)2882 MS_BOOL HAL_MVD_PauseDisp(MS_U8 u8Idx)
2883 {
2884 MS_BOOL bRst = TRUE;
2885 MVD_CmdArg mvdcmd;
2886
2887 SETUP_CMDARG(mvdcmd);
2888 mvdcmd.Arg0 = DISPLAY_PAUSE_ON;
2889 SET_DECNUM(mvdcmd, u8Idx);
2890 if (HAL_MVD_MVDCommand(CMD_DISPLAY_PAUSE, &mvdcmd)== FALSE)
2891 {
2892 MVD_DEBUGERROR( printf( "Command: 0x%x(ON) fail!!\r\n", CMD_DISPLAY_PAUSE) );
2893 bRst = FALSE;
2894 }
2895 return bRst;
2896 }
2897
2898 //------------------------------------------------------------------------------
2899 /// Issue Pause command.
2900 /// @return -TRUE for success; FALSE for failure
2901 //------------------------------------------------------------------------------
HAL_MVD_Resume(MS_U8 u8Idx)2902 MS_BOOL HAL_MVD_Resume(MS_U8 u8Idx)
2903 {
2904 MS_BOOL bRst = TRUE;
2905 MVD_CmdArg mvdcmd;
2906
2907 SETUP_CMDARG(mvdcmd);
2908 mvdcmd.Arg0 = DISPLAY_PAUSE_OFF;
2909 SET_DECNUM(mvdcmd, u8Idx);
2910 if (HAL_MVD_MVDCommand(CMD_DISPLAY_PAUSE, &mvdcmd)== FALSE)
2911 {
2912 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DISPLAY_PAUSE) );
2913 bRst = FALSE;
2914 }
2915 return bRst;
2916 }
2917
HAL_MVD_Play(MS_U8 u8Idx)2918 MS_BOOL HAL_MVD_Play(MS_U8 u8Idx)
2919 {
2920 MVD_CmdArg mvdcmd;
2921 SETUP_CMDARG(mvdcmd);
2922 mvdcmd.Arg0 = 1;
2923 SET_DECNUM(mvdcmd, u8Idx);
2924 SET_CMD_RET_FALSE(CMD_DIU_WIDTH_ALIGN, &mvdcmd);
2925
2926 SETUP_CMDARG(mvdcmd);
2927 SET_DECNUM(mvdcmd, u8Idx);
2928 SET_CMD_RET_FALSE(CMD_PLAY, &mvdcmd);
2929
2930 if (HAL_MVD_Resume(u8Idx) == FALSE)
2931 {
2932 MVD_DEBUGERROR( printf( "Command: HAL_MVD_Resume fail!!\r\n" ) );
2933 return FALSE;
2934 }
2935
2936 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
2937 pCtrlCfg->bDecodeIFrame = FALSE;
2938
2939 return TRUE;
2940 }
2941
2942 //------------------------------------------------------------------------------
2943 /// Set base address for ScalerInfo structure to f/w
2944 /// @param -u32addr \b IN : start address (units in byte)
2945 //------------------------------------------------------------------------------
HAL_MVD_SetScalerInfoAddr(MS_U8 u8Idx,MS_VIRT u32addr,MS_U8 u8Arg4)2946 MS_BOOL HAL_MVD_SetScalerInfoAddr(MS_U8 u8Idx, MS_VIRT u32addr,MS_U8 u8Arg4)
2947 {
2948 MVD_CmdArg mvdcmd;
2949
2950 MS_ASSERT((u32addr%8)==0);
2951 u32addr >>= 3;
2952
2953 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2954 mvdcmd.Arg4 = u8Arg4;
2955 SET_CMD_RET_FALSE(CMD_SCALER_INFO_BASE, &mvdcmd);
2956 return TRUE;
2957 }
2958
2959 //------------------------------------------------------------------------------
2960 /// Set the dynamic scale base address
2961 /// @return -TRUE for success; FALSE for failure.
2962 //------------------------------------------------------------------------------
HAL_MVD_SetDynamicScaleAddr(MS_U8 u8Idx,MS_VIRT u32addr)2963 MS_BOOL HAL_MVD_SetDynamicScaleAddr(MS_U8 u8Idx, MS_VIRT u32addr)
2964 {
2965 MVD_CmdArg mvdcmd;
2966
2967 MS_ASSERT((u32addr%8)==0);
2968 u32addr >>= 3;
2969
2970 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2971 SET_CMD_RET_FALSE(CMD_DYNAMIC_SCALE_BASE, &mvdcmd);
2972 return TRUE;
2973 }
2974
2975 //------------------------------------------------------------------------------
2976 /// Set virtual box width/height to F/W.
2977 /// F/W will use the same w/h as scaler to calculate scaling factor.
2978 /// @return -TRUE for success; FALSE for failure.
2979 //------------------------------------------------------------------------------
HAL_MVD_SetVirtualBox(MS_U8 u8Idx,MS_U16 u16Width,MS_U16 u16Height)2980 MS_BOOL HAL_MVD_SetVirtualBox(MS_U8 u8Idx, MS_U16 u16Width, MS_U16 u16Height)
2981 {
2982 MVD_CmdArg mvdcmd;
2983
2984 SETUP_CMDARG(mvdcmd);
2985 mvdcmd.Arg0 = L_WORD(u16Width);
2986 mvdcmd.Arg1 = H_WORD(u16Width);
2987 mvdcmd.Arg2 = L_WORD(u16Height);
2988 mvdcmd.Arg3 = H_WORD(u16Height);
2989 SET_DECNUM(mvdcmd, u8Idx);
2990 SET_CMD_RET_FALSE(CMD_DS_VIRTUAL_BOX, &mvdcmd);
2991 return TRUE;
2992 }
2993
2994 //------------------------------------------------------------------------------
2995 /// Enable VC1 dynamic scaling
2996 /// @return -TRUE for success; FALSE for failure.
2997 //------------------------------------------------------------------------------
HAL_MVD_EnableDynamicScale(MS_U8 u8Idx,MS_U8 u8NewDS)2998 MS_BOOL HAL_MVD_EnableDynamicScale(MS_U8 u8Idx,MS_U8 u8NewDS)
2999 {
3000 MVD_CmdArg mvdcmd;
3001
3002 SETUP_CMDARG(mvdcmd);
3003 mvdcmd.Arg0 = TRUE;
3004 mvdcmd.Arg1 = u8NewDS;
3005 SET_DECNUM(mvdcmd, u8Idx);
3006 SET_CMD_RET_FALSE(CMD_ENABLE_DYNAMIC_SCALE, &mvdcmd);
3007 return TRUE;
3008 }
3009
3010
3011 //------------------------------------------------------------------------------
3012 /// Set blue screen
3013 /// @return -TRUE for success; FALSE for failure.
3014 //------------------------------------------------------------------------------
HAL_MVD_SetBlueScreen(MS_U8 u8Idx,MS_BOOL bEn)3015 MS_BOOL HAL_MVD_SetBlueScreen(MS_U8 u8Idx, MS_BOOL bEn)
3016 {
3017 MVD_CmdArg mvdcmd;
3018
3019 SETUP_CMDARG(mvdcmd);
3020 mvdcmd.Arg0 = bEn; //1 -> show MVOP frame color. 0 -> normal case.
3021 SET_DECNUM(mvdcmd, u8Idx);
3022 SET_CMD_RET_FALSE(CMD_FORCE_BLUE_SCREEN, &mvdcmd);
3023 return TRUE;
3024 }
3025
3026
HAL_MVD_SetFreezeDisp(MS_U8 u8Idx,MS_BOOL bEn)3027 MS_BOOL HAL_MVD_SetFreezeDisp(MS_U8 u8Idx, MS_BOOL bEn)
3028 {
3029 MVD_CmdArg mvdcmd;
3030
3031 SETUP_CMDARG(mvdcmd);
3032 mvdcmd.Arg0 = bEn;
3033 SET_DECNUM(mvdcmd, u8Idx);
3034 SET_CMD_RET_FALSE(CMD_FREEZE_DISP, &mvdcmd);
3035 return TRUE;
3036 }
3037
3038
3039 //------------------------------------------------------------------------------
3040 /// Set base address for DecFrameInfo structure to f/w
3041 /// @param -u32addr \b IN : start address (units in byte)
3042 //------------------------------------------------------------------------------
HAL_MVD_SetDecFrmInfoAddr(MS_U8 u8Idx,MS_VIRT u32addr)3043 void HAL_MVD_SetDecFrmInfoAddr(MS_U8 u8Idx, MS_VIRT u32addr)
3044 {
3045 MVD_CmdArg mvdcmd;
3046
3047 MS_ASSERT((u32addr%8)==0);
3048 u32addr >>= 3;
3049
3050 SET_CMDARG(mvdcmd, u32addr, u8Idx);
3051 if (HAL_MVD_MVDCommand( CMD_DEC_FRAME_INFO_BUF, &mvdcmd ) == FALSE)
3052 {
3053 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DEC_FRAME_INFO_BUF ) );
3054 }
3055 return;
3056 }
3057
3058 //Check if the task has interrupt
HAL_MVD_GetHasInt(MS_U8 u8Idx)3059 MS_BOOL HAL_MVD_GetHasInt(MS_U8 u8Idx)
3060 {
3061 MS_BOOL bHasInt = FALSE;
3062 MS_U32 u32IntCnt = 0;
3063 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
3064
3065 u32IntCnt = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_INT_CNT, sizeof(MS_U32));
3066 if (u32IntCnt != pCtrlCfg->u32IntCnt)
3067 {
3068 MVD_DEBUGINFO(printf("%s %d--> %d\n", __FUNCTION__, pCtrlCfg->u32IntCnt, u32IntCnt));
3069 bHasInt = TRUE;
3070 pCtrlCfg->u32IntCnt = u32IntCnt;
3071 }
3072 return bHasInt;
3073 }
3074
3075 #ifdef VDEC3
HAL_MVD_GetIntState(MS_U8 u8Idx)3076 MS_U32 HAL_MVD_GetIntState(MS_U8 u8Idx)
3077 {
3078 MS_U32 u32IntStat;
3079
3080 u32IntStat = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_INT_STAT, sizeof(MS_U32));
3081
3082 MVD_SetFWBuffData(u8Idx,FW_BUFF_FRMINFO,OFFSET_INT_STAT,sizeof(MS_U32),0);
3083
3084 return u32IntStat;
3085 }
3086 #else
HAL_MVD_GetIntState(MS_U8 u8Idx)3087 MS_U32 HAL_MVD_GetIntState(MS_U8 u8Idx)
3088 {
3089 MS_U32 u32IntStat = 0;
3090 MVD_CmdArg mvdcmd;
3091
3092 SETUP_CMDARG(mvdcmd);
3093 SET_DECNUM(mvdcmd, u8Idx);
3094 if (HAL_MVD_MVDCommand( CMD_GET_INT_STAT, &mvdcmd ) == TRUE)
3095 {
3096 u32IntStat = (((MS_U32)mvdcmd.Arg4) << 16) |
3097 (((MS_U32)mvdcmd.Arg3) << 8) |
3098 (((MS_U32)mvdcmd.Arg2));
3099 }
3100 else
3101 {
3102 if (FALSE == pMVDHalContext->bStopped[u8Idx])
3103 {
3104 MVD_DEBUGERROR(printf("Ctrl: 0x%x fail!!\n", CMD_GET_INT_STAT));
3105 }
3106 else
3107 {
3108 MVD_DEBUGINFO(printf("Cmd 0x%x normal timeout.\n", CMD_GET_INT_STAT));
3109 }
3110 }
3111
3112 return u32IntStat;
3113 }
3114
3115 #endif
3116
3117 ///// functions to check interrupt status /////
MVD_IntHasUsrDataDisp(MS_U32 u32IntStat)3118 MS_BOOL MVD_IntHasUsrDataDisp(MS_U32 u32IntStat)
3119 {
3120 return (((u32IntStat&INT_USER_DATA_DISP)==INT_USER_DATA_DISP) ? TRUE : FALSE);
3121 }
3122
MVD_IntHasUsrData(MS_U32 u32IntStat)3123 MS_BOOL MVD_IntHasUsrData(MS_U32 u32IntStat)
3124 {
3125 return (((u32IntStat&INT_USER_DATA)==INT_USER_DATA) ? TRUE : FALSE);
3126 }
3127
MVD_IntIsDispRdy(MS_U32 u32IntStat)3128 MS_BOOL MVD_IntIsDispRdy(MS_U32 u32IntStat)
3129 {
3130 return (((u32IntStat&INT_DISP_RDY)==INT_DISP_RDY) ? TRUE : FALSE);
3131 }
3132
MVD_IntHasSeqHdr(MS_U32 u32IntStat)3133 MS_BOOL MVD_IntHasSeqHdr(MS_U32 u32IntStat)
3134 {
3135 return (((u32IntStat&INT_SEQ_FOUND)==INT_SEQ_FOUND) ? TRUE : FALSE);
3136 }
3137
MVD_IntHasESDataInvalid(MS_U32 u32IntStat)3138 MS_BOOL MVD_IntHasESDataInvalid(MS_U32 u32IntStat)
3139 {
3140 return (((u32IntStat&INT_VES_VALID)==INT_VES_VALID) ? TRUE : FALSE);
3141 }
3142
MVD_IntHasDecodeErr(MS_U32 u32IntStat)3143 MS_BOOL MVD_IntHasDecodeErr(MS_U32 u32IntStat)
3144 {
3145 return (((u32IntStat&INT_DEC_ERR)==INT_DEC_ERR) ? TRUE : FALSE);
3146 }
3147 //INT_FIRST_FRAME means "1st frame be push to display queue & ready for display"
3148 //So, (1) in IPB or IP stream, that's I-frame
3149 // (2) in PB only stream, that's first P-frame
MVD_IntHas1stFrame(MS_U32 u32IntStat)3150 MS_BOOL MVD_IntHas1stFrame(MS_U32 u32IntStat)
3151 {
3152 return (((u32IntStat&INT_FIRST_FRAME)==INT_FIRST_FRAME) ? TRUE : FALSE);
3153 }
3154
3155 //INT_XC_LOW_DELAY
MVD_IntHasXcLowDelay(MS_U32 u32IntStat)3156 MS_BOOL MVD_IntHasXcLowDelay(MS_U32 u32IntStat)
3157 {
3158 //printf("MVD_IntHasXcLowDelay=%x \n ", u32IntStat);
3159 return (((u32IntStat&INT_XC_LOW_DELAY)==INT_XC_LOW_DELAY) ? TRUE : FALSE);
3160 }
3161
MVD_IntHasDecodeIframe(MS_U32 u32IntStat)3162 MS_BOOL MVD_IntHasDecodeIframe(MS_U32 u32IntStat)
3163 {
3164 return (((u32IntStat&INT_DEC_I)==INT_DEC_I) ? TRUE : FALSE);
3165 }
3166
3167
MVD_IntVSyncInt(MS_U32 u32IntStat)3168 MS_BOOL MVD_IntVSyncInt(MS_U32 u32IntStat)
3169 {
3170 return (((u32IntStat&INT_DISP_VSYNC)==INT_DISP_VSYNC) ? TRUE : FALSE);
3171 }
3172
MVD_IntDecOneFrmInt(MS_U32 u32IntStat)3173 MS_BOOL MVD_IntDecOneFrmInt(MS_U32 u32IntStat)
3174 {
3175 return (((u32IntStat&INT_DEC_DONE)==INT_DEC_DONE) ? TRUE : FALSE);
3176 }
3177
3178
MVD_GetSyncStat(MS_U8 u8Idx,MS_U8 u8ArgIdx)3179 static MS_U8 MVD_GetSyncStat(MS_U8 u8Idx, MS_U8 u8ArgIdx)
3180 {
3181 MS_U8 u8Val = 0xFF;
3182 MVD_CmdArg mvdcmd;
3183 SETUP_CMDARG(mvdcmd);
3184 SET_DECNUM(mvdcmd, u8Idx);
3185 if (HAL_MVD_MVDCommand( CMD_GET_SYNC_STAT, &mvdcmd ) == FALSE)
3186 {
3187 MVD_DEBUGERROR(printf("Ctrl: 0x%x fail!!\r\n", CMD_GET_SYNC_STAT));
3188 return 0xFF;
3189 }
3190 MVD_DEBUGINFO(printf("Sync On/Off %x, Done %x, Stat %x, diff=%d\n",
3191 mvdcmd.Arg0, mvdcmd.Arg1, mvdcmd.Arg2, (int)HAL_MVD_GetPtsStcDiff(u8Idx)));
3192
3193 if (0==u8ArgIdx)
3194 {
3195 u8Val = mvdcmd.Arg0; //On/Off
3196 }
3197 else if (1==u8ArgIdx)
3198 {
3199 u8Val = mvdcmd.Arg1; //Done
3200 }
3201 else if (2==u8ArgIdx)
3202 {
3203 u8Val = mvdcmd.Arg2; //Stat
3204 }
3205 return u8Val;
3206 }
3207
3208 //------------------------------------------------------------------------------
3209 /// Report avsync status
3210 /// avsync_status=avsync_done|(avsync_skip_picture<<1)|(avsync_repeat_picture<<2),
3211 /// 0 for free run
3212 //------------------------------------------------------------------------------
HAL_MVD_GetAVSyncStatus(MS_U8 u8Idx)3213 MS_U8 HAL_MVD_GetAVSyncStatus(MS_U8 u8Idx)
3214 {
3215 return MVD_GetSyncStat(u8Idx, 2);
3216 }
3217
HAL_MVD_SlqTblLoadWrPtr(MS_U8 u8Idx,MS_VIRT u32WrPtr)3218 void HAL_MVD_SlqTblLoadWrPtr(MS_U8 u8Idx, MS_VIRT u32WrPtr)
3219 {
3220 #if 1
3221 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
3222 MVD_CmdArg mvdcmd;
3223 MS_U16 u16Val = 0;
3224
3225 if (FALSE == pstSlqTblInfo->bEnSlqTblHkCtrl)
3226 {
3227 SETUP_CMDARG(mvdcmd);
3228 mvdcmd.Arg0 = 0x10;
3229 mvdcmd.Arg1 = 0x01;
3230 SET_DECNUM(mvdcmd, u8Idx);
3231 if (HAL_MVD_MVDCommand( CMD_RD_IO, &mvdcmd ) == FALSE)
3232 {
3233 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_RD_IO ) );
3234 return;
3235 }
3236 u16Val = (((MS_U32)mvdcmd.Arg2)) | ((MS_U32)mvdcmd.Arg3 << 8);
3237
3238 SETUP_CMDARG(mvdcmd);
3239 mvdcmd.Arg0 = 0x10;
3240 mvdcmd.Arg1 = 0x01;
3241 mvdcmd.Arg2 = u16Val & 0xff;
3242 mvdcmd.Arg3 = ((u16Val>>8 ) & 0xff) | 0x80;
3243 SET_DECNUM(mvdcmd, u8Idx);
3244 if (HAL_MVD_MVDCommand(CMD_WR_IO, &mvdcmd) == FALSE)
3245 {
3246 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_WR_IO ) );
3247 return;
3248 }
3249
3250 pstSlqTblInfo->bEnSlqTblHkCtrl = TRUE;
3251 //printf("@@@ OPEN HK.SLQ.CTRL!\n");
3252 }
3253 #endif
3254 OSAL_MVD_LockHwMutex();
3255
3256 HAL_MVD_RegWriteByte(MVD_SLQ_WADR0, (u32WrPtr & 0xff));
3257 HAL_MVD_RegWriteByte(MVD_SLQ_WADR1, ((u32WrPtr>>8 ) & 0xff));
3258 HAL_MVD_RegWriteByte(MVD_SLQ_WADR2, ((u32WrPtr>>16) & 0xff));
3259 HAL_MVD_RegWriteByte(MVD_SLQ_WADR3, ((u32WrPtr>>24) & 0x01));
3260 HAL_MVD_RegWriteBit(MVD_SLQCTRL, 1, MVD_SLQCTRL_WADR_RELOAD);
3261 HAL_MVD_RegWriteBit(MVD_SLQCTRL, 0, MVD_SLQCTRL_WADR_RELOAD);
3262
3263 OSAL_MVD_UnlockHwMutex();
3264 }
3265
HAL_MVD_SlqTblProbe(MVD_HKSLQ_CMD eCmd)3266 static MS_VIRT HAL_MVD_SlqTblProbe(MVD_HKSLQ_CMD eCmd)
3267 {
3268 MS_VIRT u32Cadr = 0;
3269 OSAL_MVD_LockHwMutex();
3270
3271 switch (eCmd)
3272 {
3273 case MVD_HKSLQ_GET_READPTR:
3274 HAL_MVD_RegWriteBit(MVD_SLQCTRL, 1, MVD_SLQCTRL_RADR_PROBE);
3275 HAL_MVD_RegWriteBit(MVD_SLQCTRL, 0, MVD_SLQCTRL_RADR_PROBE);
3276 break;
3277 case MVD_HKSLQ_GET_WRITEPTR:
3278 HAL_MVD_RegWriteBit(MVD_SLQCTRL, 1, MVD_SLQCTRL_WADR_PROBE);
3279 HAL_MVD_RegWriteBit(MVD_SLQCTRL, 0, MVD_SLQCTRL_WADR_PROBE);
3280 break;
3281 default:
3282 break;
3283 }
3284 u32Cadr = HAL_MVD_RegReadByte(MVD_SLQ_CADR0) |
3285 (HAL_MVD_RegReadByte(MVD_SLQ_CADR1) << 8) |
3286 (HAL_MVD_RegReadByte(MVD_SLQ_CADR2) <<16) |
3287 ((HAL_MVD_RegReadByte(MVD_SLQ_CADR3) & 0x01) <<24);
3288
3289 OSAL_MVD_UnlockHwMutex();
3290 return u32Cadr;
3291 }
3292
HAL_MVD_SlqTblProbeWrPtr(MS_U8 u8Idx)3293 MS_VIRT HAL_MVD_SlqTblProbeWrPtr(MS_U8 u8Idx)
3294 {
3295 return HAL_MVD_SlqTblProbe(MVD_HKSLQ_GET_WRITEPTR);
3296 }
3297
HAL_MVD_SlqTblProbeRdPtr(MS_U8 u8Idx)3298 MS_VIRT HAL_MVD_SlqTblProbeRdPtr(MS_U8 u8Idx)
3299 {
3300 return HAL_MVD_SlqTblProbe(MVD_HKSLQ_GET_READPTR);
3301 }
3302
3303 //------------------------------------------------------------------------------
3304 /// Set firmware as MStreamer mode
3305 /// @return -TRUE for success; FALSE for failure.
3306 //------------------------------------------------------------------------------
HAL_MVD_SetMStreamerMode(MS_U8 u8Idx,MS_U8 u8Mode)3307 MS_BOOL HAL_MVD_SetMStreamerMode(MS_U8 u8Idx, MS_U8 u8Mode)
3308 {
3309 MVD_CmdArg mvdcmd;
3310 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
3311
3312 SETUP_CMDARG(mvdcmd);
3313 mvdcmd.Arg0 = u8Mode; //1: enable, 0:disable MStreamer mode.
3314 SET_DECNUM(mvdcmd, u8Idx);
3315 SET_CMD_RET_FALSE(CMD_SET_MST_MODE, &mvdcmd);
3316
3317 pstCtrlCfg->u8MstMode = u8Mode;
3318 return TRUE;
3319 }
3320
3321 //------------------------------------------------------------------------------
3322 /// Set firmware as MStreamer mode (IP clip mode)
3323 /// @return -TRUE for success; FALSE for failure.
3324 //------------------------------------------------------------------------------
HAL_MVD_ShowDecodeOrder(MS_U8 u8Idx,MS_U8 u8Mode)3325 MS_BOOL HAL_MVD_ShowDecodeOrder(MS_U8 u8Idx, MS_U8 u8Mode)
3326 {
3327 MVD_CmdArg mvdcmd;
3328 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
3329
3330 SETUP_CMDARG(mvdcmd);
3331 mvdcmd.Arg0 = pstCtrlCfg->u8MstMode;
3332 mvdcmd.Arg1 = u8Mode;//a u8Mode; //1: clip mode, 0:normal mode.
3333 SET_DECNUM(mvdcmd, u8Idx);
3334 SET_CMD_RET_FALSE(CMD_SET_MST_MODE, &mvdcmd);
3335 return TRUE;
3336
3337 }
3338
HAL_MVD_IsMStreamerMode(MS_U8 u8Idx)3339 MS_BOOL HAL_MVD_IsMStreamerMode(MS_U8 u8Idx)
3340 {
3341 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
3342 return (MST_MODE_TRUE == pstCtrlCfg->u8MstMode);
3343 }
3344
HAL_MVD_FrameOpt(MS_U8 u8Idx,MS_U8 u8FrmIdx,MVD_FrmOpt eOpt)3345 MS_BOOL HAL_MVD_FrameOpt(MS_U8 u8Idx, MS_U8 u8FrmIdx, MVD_FrmOpt eOpt)
3346 {
3347 MVD_CmdArg mvdcmd;
3348
3349 SETUP_CMDARG(mvdcmd);
3350 mvdcmd.Arg0 = u8FrmIdx;
3351 mvdcmd.Arg1 = eOpt; // 0 = Flip, 1 = Release.
3352 MVD_DEBUGINFO(printf("FLIP_RELEASE_FRAME: idx=0x%x, opt=0x%x\n", u8FrmIdx, eOpt));
3353 SET_DECNUM(mvdcmd, u8Idx);
3354 SET_CMD_RET_FALSE(CMD_FLIP_RELEASE_FRAME, &mvdcmd);
3355
3356 return TRUE;
3357 }
3358
3359 //------------------------------------------------------------------------------
3360 /// Set firmware dynamic allocate FrameBuffer, now support MCU mode only
3361 /// @return -TRUE for success; FALSE for failure.
3362 //------------------------------------------------------------------------------
_MVD_SetDynamicAllocateFB(MS_U8 u8Idx,MS_BOOL bEnable)3363 MS_BOOL _MVD_SetDynamicAllocateFB(MS_U8 u8Idx,MS_BOOL bEnable)
3364 {
3365 MVD_CmdArg mvdcmd;
3366
3367 SETUP_CMDARG(mvdcmd);
3368 mvdcmd.Arg0 = 1-bEnable; //Arg0 : 0(enable) , 1(disable)
3369 SET_DECNUM(mvdcmd, u8Idx);
3370 if (HAL_MVD_MVDCommand( CMD_FIXED_FRAME_BUFFER, &mvdcmd ) == FALSE)
3371 {
3372 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FIXED_FRAME_BUFFER ) );
3373 return FALSE;
3374 }
3375
3376 return TRUE;
3377 }
3378
3379 //------------------------------------------------------------------------------
3380 /// Set firmware as MCU mode
3381 /// @return -TRUE for success; FALSE for failure.
3382 //------------------------------------------------------------------------------
HAL_MVD_SetMcuMode(MS_U8 u8Idx,MS_U8 u8Mode)3383 MS_BOOL HAL_MVD_SetMcuMode(MS_U8 u8Idx, MS_U8 u8Mode)
3384 {
3385 MVD_CmdArg mvdcmd;
3386 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
3387
3388 SETUP_CMDARG(mvdcmd);
3389 mvdcmd.Arg0 = u8Mode; //1: enable, 0:disable MCU
3390 SET_DECNUM(mvdcmd, u8Idx);
3391 SET_CMD_RET_FALSE(CMD_SET_MCU_MODE, &mvdcmd);
3392
3393 pstCtrlCfg->u8McuMode = u8Mode;
3394
3395 return TRUE;
3396 }
3397
HAL_MVD_IsMcuMode(MS_U8 u8Idx)3398 MS_BOOL HAL_MVD_IsMcuMode(MS_U8 u8Idx)
3399 {
3400 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
3401 return (TRUE == pstCtrlCfg->u8McuMode);
3402 }
3403
3404 //------------------------------------------------------------------------------
3405 /// Set firmware as ForceInterlace mode
3406 /// @return -TRUE for success; FALSE for failure.
3407 //------------------------------------------------------------------------------
HAL_MVD_ForceInterlaceMode(MS_U8 u8Idx,MS_U8 u8Mode)3408 MS_BOOL HAL_MVD_ForceInterlaceMode(MS_U8 u8Idx, MS_U8 u8Mode)
3409 {
3410 MVD_CmdArg mvdcmd;
3411
3412 SETUP_CMDARG(mvdcmd);
3413 mvdcmd.Arg0 = u8Mode; //1: enable, 0:disable
3414 mvdcmd.Arg1 = 0;
3415 SET_DECNUM(mvdcmd, u8Idx);
3416 SET_CMD_RET_FALSE(CMD_VC1_FORCE_INTLACE_DISP, &mvdcmd);
3417
3418 return TRUE;
3419 }
3420
3421 //------------------------------------------------------------------------------
3422 /// Set firmware as Progressive mode
3423 /// @return -TRUE for success; FALSE for failure.
3424 //------------------------------------------------------------------------------
HAL_MVD_ForceProgressiveMode(MS_U8 u8Idx,MS_U8 u8Mode)3425 MS_BOOL HAL_MVD_ForceProgressiveMode(MS_U8 u8Idx, MS_U8 u8Mode)
3426 {
3427 MVD_CmdArg mvdcmd;
3428
3429 SETUP_CMDARG(mvdcmd);
3430 mvdcmd.Arg0 = 0;
3431 mvdcmd.Arg1 = u8Mode; //1: enable, 0:disable
3432 SET_DECNUM(mvdcmd, u8Idx);
3433 SET_CMD_RET_FALSE(CMD_VC1_FORCE_INTLACE_DISP, &mvdcmd);
3434
3435 return TRUE;
3436 }
3437
3438 //------------------------------------------------------------------------------
3439 /// Inform firwmare that PTS is updated.
3440 /// @return -TRUE for success; FALSE for failure.
3441 //------------------------------------------------------------------------------
HAL_MVD_UpdatePts(MS_U8 u8Idx)3442 MS_BOOL HAL_MVD_UpdatePts(MS_U8 u8Idx)
3443 {
3444 MVD_CmdArg mvdcmd;
3445
3446 SETUP_CMDARG(mvdcmd);
3447 SET_DECNUM(mvdcmd, u8Idx);
3448 SET_CMD_RET_FALSE(CMD_SEND_UNI_PTS, &mvdcmd);
3449
3450 return TRUE;
3451 }
3452
3453
HAL_MVD_FrameCapture(MS_U8 u8Idx,MS_U8 u8FrmIdx,MS_BOOL bEnable)3454 MS_BOOL HAL_MVD_FrameCapture(MS_U8 u8Idx, MS_U8 u8FrmIdx, MS_BOOL bEnable)
3455 {
3456 MVD_CmdArg mvdcmd;
3457
3458 SETUP_CMDARG(mvdcmd);
3459 mvdcmd.Arg0 = bEnable; //0 or 1 to enable/disable the freeze function
3460 mvdcmd.Arg2 = u8FrmIdx; //specify the freezed frame index
3461 MVD_DEBUGINFO(printf("CAPTURE_FRAME: idx=0x%x, enable=0x%x\n", u8FrmIdx, bEnable));
3462 SET_DECNUM(mvdcmd, u8Idx);
3463 SET_CMD_RET_FALSE(CMD_ENABLE_FREEZE_PIC, &mvdcmd);
3464
3465 return TRUE;
3466 }
3467
3468 //------------------------------------------------------------------------------
3469 /// Set HW buffers' start address to MVD FW
3470 /// Return (the end address - 1)
3471 /// @param -u32Addr \b IN : start address (MIU offset)
3472 //------------------------------------------------------------------------------
HAL_MVD_SetHWBuffer(MS_U8 u8Idx,MS_VIRT u32Add)3473 MS_VIRT HAL_MVD_SetHWBuffer(MS_U8 u8Idx, MS_VIRT u32Add)
3474 {
3475 MS_VIRT tmpAdr;
3476
3477 MVD_DEBUGINFO(printf("====> %s u32Add = 0x%lx\n", __FUNCTION__, (unsigned long)u32Add));
3478 tmpAdr = (MemAlign(u32Add, MVD_FW_IAP_BUF_ALIGN));
3479 MVD_DEBUGINFO(printf("set MVD3_FW_IAP_BUF_ADR =%lx\n",(unsigned long)tmpAdr));
3480 HAL_MVD_SetIAPBufferAddr(u8Idx, tmpAdr);
3481 tmpAdr += MVD_FW_IAP_BUF_LEN;
3482
3483 tmpAdr = (MemAlign(tmpAdr, MVD_FW_DP_BUF_ALIGN));
3484 MVD_DEBUGINFO(printf("set MVD3_FW_DP_BUF_ADR=%lx\n",(unsigned long)tmpAdr));
3485 HAL_MVD_SetDPBufferAddr(u8Idx, tmpAdr);
3486 tmpAdr += MVD_FW_DP_BUF_LEN;
3487
3488 tmpAdr = (MemAlign(tmpAdr, MVD_FW_MV_BUF_ALIGN));
3489 MVD_DEBUGINFO(printf("set MVD3_FW_MV_BUF_ADR=%lx\n",(unsigned long)tmpAdr));
3490 HAL_MVD_SetMVBufferAddr(u8Idx, tmpAdr);
3491 tmpAdr += MVD_FW_MV_BUF_LEN;
3492 MVD_DEBUGINFO(printf("====> %s End of HW buffers = 0x%lx\n", __FUNCTION__, (unsigned long)tmpAdr));
3493
3494 return tmpAdr;
3495 }
3496
3497 //------------------------------------------------------------------------------
3498 /// Set the number of framebuffer
3499 /// @param -u8FrmNum \b IN : the number of framebuffer
3500 //------------------------------------------------------------------------------
HAL_MVD_SetFrameBuffNum(MS_U8 u8Idx,MS_U8 u8FrmNum,MS_U32 u32FBUsedSize)3501 void HAL_MVD_SetFrameBuffNum(MS_U8 u8Idx, MS_U8 u8FrmNum,MS_U32 u32FBUsedSize)
3502 {
3503 #define MVD_FBNUM_DEFAULT 4
3504 #define MVD_FBNUM_MIN MVD_FBNUM_DEFAULT
3505
3506 MVD_CmdArg mvdcmd;
3507
3508 MVD_DEBUGINFO(printf("%s u8FrmNum = %d\n", __FUNCTION__, u8FrmNum));
3509 if (u8FrmNum < MVD_FBNUM_MIN)
3510 {
3511 MVD_DEBUGINFO(printf("%s set u8FrmNum as %d instead of %d!\n",
3512 __FUNCTION__, MVD_FBNUM_MIN, u8FrmNum));
3513 u8FrmNum = MVD_FBNUM_MIN;
3514 }
3515 SETUP_CMDARG(mvdcmd);
3516 mvdcmd.Arg0 = u8FrmNum;
3517 mvdcmd.Arg1 = u32FBUsedSize&0xff;
3518 mvdcmd.Arg2 = (u32FBUsedSize>>8)&0xff;
3519 mvdcmd.Arg3 = (u32FBUsedSize>>16)&0xff;
3520 mvdcmd.Arg4 = (u32FBUsedSize>>24)&0xff;
3521 SET_DECNUM(mvdcmd, u8Idx);
3522 if (HAL_MVD_MVDCommand( CMD_FB_NUM, &mvdcmd ) == FALSE)
3523 {
3524 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FB_NUM ) );
3525 return;
3526 }
3527 return;
3528 }
3529
MVD_WriteFWBuffData(MS_U8 u8Idx,FW_BUFF_TYPE eBuffType,MS_U16 u16Offset,MS_U8 u8Size,MS_U32 u32Val)3530 static MS_BOOL MVD_WriteFWBuffData(MS_U8 u8Idx, FW_BUFF_TYPE eBuffType, MS_U16 u16Offset, MS_U8 u8Size, MS_U32 u32Val)
3531 {
3532 MS_BOOL bRet = FALSE;
3533 MS_VIRT u32BufStart = NULL;
3534 switch (eBuffType)
3535 {
3536 case FW_BUFF_VOLINFO: u32BufStart = GET_VOL_BUFFADD(u8Idx); break;
3537 case FW_BUFF_FRMINFO: u32BufStart = GET_FRMINFO_BUFFADD(u8Idx); break;
3538 case FW_BUFF_HDR: u32BufStart = GET_HDR_BUFFADD(u8Idx); break;
3539 case FW_BUFF_USRDATA: u32BufStart = GET_USRDATA_BUFFADD(u8Idx); break;
3540 case FW_BUFF_FWSLQTAB: u32BufStart = GET_SLQ_BUFFADD(u8Idx); break;
3541 case FW_BUFF_PTSTBL: u32BufStart = GET_PTSTBL_BUFFADD(u8Idx); break;
3542 case FW_BUFF_DS: u32BufStart = GET_DS_BUFFADD(u8Idx); break;
3543 case FW_BUFF_XCINFO: u32BufStart = GET_XCINFO_BUFFADD(u8Idx); break;
3544 case FW_BUFF_DECFRMINFO: u32BufStart = GET_DECFRMINFO_BUFFADD(u8Idx); break;
3545 default:
3546 break;
3547 }
3548 if (NULL == u32BufStart)
3549 {
3550 printf("%s err: u8Idx=0x%x, bufType=0x%x, offset=%d, size=%d\n",
3551 __FUNCTION__, u8Idx, eBuffType, u16Offset, u8Size);
3552 return bRet;
3553 }
3554
3555 if (u8Size == sizeof(MS_U8))
3556 {
3557 bRet = HAL_MVD_MemWriteByte(u32BufStart+u16Offset, (MS_U8)u32Val);
3558 }
3559 else if (u8Size == sizeof(MS_U32))
3560 {
3561 bRet = HAL_MVD_MemWrite4Byte(u32BufStart+u16Offset, u32Val);
3562 }
3563
3564 MVD_DEBUGINFO(printf("%s: u32Val=%d for u8Idx=0x%x, bufType=0x%x, offset=%d, size=%d\n",
3565 __FUNCTION__, u32Val, u8Idx, eBuffType, u16Offset, u8Size));
3566 return bRet;
3567 }
3568
3569 //================== Vol Info ==================//
HAL_MVD_GetBitsRate(MS_U8 u8Idx)3570 MS_U32 HAL_MVD_GetBitsRate(MS_U8 u8Idx)
3571 {
3572 //Ref 13818-2, this flag is unit of 400 bits/sec
3573 return MVD_GetFWBuffData(u8Idx, FW_BUFF_VOLINFO, OFFSET_BIT_RATE, sizeof(MS_U32))*400;
3574 }
3575
HAL_MVD_GetVideoRange(MS_U8 u8Idx)3576 MS_U8 HAL_MVD_GetVideoRange(MS_U8 u8Idx)
3577 {
3578 return (MS_U8)MVD_GetFWBuffData(u8Idx, FW_BUFF_VOLINFO, OFFSET_VIDEO_RANGE, sizeof(MS_U8));
3579 }
3580
HAL_MVD_GetLowDelayFlag(MS_U8 u8Idx)3581 MS_BOOL HAL_MVD_GetLowDelayFlag(MS_U8 u8Idx)
3582 {
3583 return (MS_BOOL)MVD_GetFWBuffData(u8Idx, FW_BUFF_VOLINFO, OFFSET_LOW_DELAY, sizeof(MS_U8));
3584 }
3585
HAL_MVD_GetIs32PullDown(MS_U8 u8Idx)3586 MS_BOOL HAL_MVD_GetIs32PullDown(MS_U8 u8Idx)
3587 {
3588 return (MS_BOOL)MVD_GetFWBuffData(u8Idx, FW_BUFF_VOLINFO, OFFSET_MPEG_FRC_MODE, sizeof(MS_U8));
3589 }
3590
HAL_MVD_GetIsDynScalingEnabled(MS_U8 u8Idx)3591 MS_BOOL HAL_MVD_GetIsDynScalingEnabled(MS_U8 u8Idx)
3592 {
3593 return (MS_BOOL)MVD_GetFWBuffData(u8Idx, FW_BUFF_VOLINFO, OFFSET_DS_ENABLE, sizeof(MS_U8));
3594 }
3595
HAL_MVD_Is1stFrmRdy(MS_U8 u8Idx)3596 MS_BOOL HAL_MVD_Is1stFrmRdy(MS_U8 u8Idx)
3597 {
3598 return (MS_BOOL)MVD_GetFWBuffData(u8Idx, FW_BUFF_VOLINFO, OFFSET_FIRST_DISPLAY, sizeof(MS_U8));
3599 }
3600
3601
3602 //================== FrameInfo ==================//
HAL_MVD_GetPicCounter(MS_U8 u8Idx)3603 MS_U32 HAL_MVD_GetPicCounter(MS_U8 u8Idx)
3604 {
3605 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_FRAME_COUNT, sizeof(MS_U32));
3606 }
3607
HAL_MVD_GetSkipPicCounter(MS_U8 u8Idx)3608 MS_U32 HAL_MVD_GetSkipPicCounter(MS_U8 u8Idx)
3609 {
3610 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SKIP_FRAME_COUNT, sizeof(MS_U32));
3611 }
3612
HAL_MVD_GetPicType(MS_U8 u8Idx)3613 MVD_PicType HAL_MVD_GetPicType(MS_U8 u8Idx)
3614 {
3615 MS_U32 picType = 0xff;
3616 MVD_PicType ret = E_MVD_PIC_UNKNOWN;
3617
3618 if (GET_FRMINFO_BUFFADD(u8Idx)==0)
3619 {
3620 MVD_DEBUGERROR(printf("%s error: pu8MVDGetFrameInfoBufStart=NULL\n", __FUNCTION__));
3621 return E_MVD_PIC_UNKNOWN;
3622 }
3623 picType = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PICTURE_TYPE, sizeof(MS_U32));
3624 switch (picType)
3625 {
3626 case 0:
3627 ret = E_MVD_PIC_I;
3628 break;
3629 case 1:
3630 ret = E_MVD_PIC_P;
3631 break;
3632 case 2:
3633 ret = E_MVD_PIC_B;
3634 break;
3635 default:
3636 break;
3637 }
3638 return ret;
3639 }
3640
HAL_MVD_GetPtsStcDiff(MS_U8 u8Idx)3641 MS_S32 HAL_MVD_GetPtsStcDiff(MS_U8 u8Idx)
3642 {
3643 return (MS_S32)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PTS_STC, sizeof(MS_S32));
3644 }
3645
HAL_MVD_GetDecodedFrameIdx(MS_U8 u8Idx)3646 MS_U8 HAL_MVD_GetDecodedFrameIdx(MS_U8 u8Idx)
3647 {
3648 return (MS_U8)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_FB_INDEX, sizeof(MS_U8));
3649 }
3650
HAL_MVD_GetVldErrCount(MS_U8 u8Idx)3651 MS_U32 HAL_MVD_GetVldErrCount(MS_U8 u8Idx)
3652 {
3653 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_VLD_ERR_COUNT, sizeof(MS_U32));
3654 }
3655
HAL_MVD_GetValidStreamFlag(MS_U8 u8Idx)3656 MS_BOOL HAL_MVD_GetValidStreamFlag(MS_U8 u8Idx)
3657 {
3658 return !(MS_BOOL)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_INVALIDSTREAM, sizeof(MS_U8));
3659 }
3660
HAL_MVD_GetIsIPicFound(MS_U8 u8Idx)3661 MS_U8 HAL_MVD_GetIsIPicFound(MS_U8 u8Idx)
3662 {
3663 return (MS_U8)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_FIRST_I_FOUND, sizeof(MS_U8));
3664 }
3665
3666 //------------------------------------------------------------------------------
3667 /// Set PTS base to MVD F/W
3668 /// @param -u32pts \b IN : pts unit in 90k counter
3669 //------------------------------------------------------------------------------
HAL_MVD_SetPTSBase(MS_U8 u8Idx,MS_U32 u32pts)3670 void HAL_MVD_SetPTSBase(MS_U8 u8Idx, MS_U32 u32pts)
3671 {
3672 MVD_CmdArg mvdcmd;
3673
3674 SET_CMDARG(mvdcmd, u32pts, u8Idx);
3675 if (HAL_MVD_MVDCommand( CMD_PTS_BASE, &mvdcmd ) == FALSE)
3676 {
3677 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PTS_BASE ) );
3678 }
3679 return;
3680 }
3681
HAL_MVD_GetPTS(MS_U8 u8Idx)3682 MS_U32 HAL_MVD_GetPTS(MS_U8 u8Idx)
3683 {
3684 MS_U32 u32PTS = 0;
3685
3686 u32PTS = (MS_U32)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DISP_PTS, sizeof(MS_U32));
3687 u32PTS = _90K_TO_MS(u32PTS);
3688 return u32PTS;
3689 }
3690
HAL_MVD_GetU64PTS(MS_U8 u8Idx,MVD_PtsType eType)3691 MS_U64 HAL_MVD_GetU64PTS(MS_U8 u8Idx,MVD_PtsType eType)
3692 {
3693 MS_U64 u64PTS = 0;
3694 MS_U64 u32_high32_PTS = 0;
3695 MS_U64 u32_low32_PTS = 0;
3696
3697 if(eType==E_MVD_PTS_DISP)
3698 {
3699 u32_low32_PTS = (MS_U64)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DISP_PTS, sizeof(MS_U32));
3700 u32_high32_PTS = (MS_U64)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DISP_PTS_MSB, sizeof(MS_U32));
3701 }
3702 else if(eType==E_MVD_PTS_PRE_PAS)
3703 {
3704 u32_low32_PTS = (MS_U64)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_WRPTR_PTS_LOW, sizeof(MS_U32));
3705 u32_high32_PTS = (MS_U64)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_WRPTR_PTS_HIGH, sizeof(MS_U32));
3706 }
3707
3708 u64PTS = (u32_high32_PTS<<32)|u32_low32_PTS;
3709 _90K_TO_MS_U64(u64PTS);
3710 return u64PTS;
3711 }
3712
HAL_MVD_GetNextPTS(MS_U8 u8Idx)3713 MS_U32 HAL_MVD_GetNextPTS(MS_U8 u8Idx)
3714 {
3715 return (MS_U32)_90K_TO_MS(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_NEXT_PTS, sizeof(MS_U32)));
3716 }
3717
HAL_MVD_GetChromaFormat(MS_U8 u8Idx)3718 MS_U32 HAL_MVD_GetChromaFormat(MS_U8 u8Idx)
3719 {
3720 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CHROMA_FORMAT, sizeof(MS_U8));
3721 }
3722
HAL_MVD_GetGOPCount(MS_U8 u8Idx)3723 MS_U32 HAL_MVD_GetGOPCount(MS_U8 u8Idx)
3724 {
3725 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_GOP_I_FCNT, sizeof(MS_U32))
3726 + MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_GOP_P_FCNT, sizeof(MS_U32))
3727 + MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_GOP_B_FCNT, sizeof(MS_U32));
3728 }
3729
HAL_MVD_GetColorFormat(MS_U8 u8Idx)3730 MS_U8 HAL_MVD_GetColorFormat(MS_U8 u8Idx)
3731 {
3732 if (GET_FRMINFO_BUFFADD(u8Idx)==0)
3733 {
3734 MVD_DEBUGERROR(printf("%s error: pu8MVDGetFrameInfoBufStart=NULL\n", __FUNCTION__));
3735 return 0xff;
3736 }
3737
3738 return (MS_U8)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_VIDEO_FORMAT, sizeof(MS_U8));
3739 }
3740
HAL_MVD_GetMatrixCoef(MS_U8 u8Idx)3741 MS_U8 HAL_MVD_GetMatrixCoef(MS_U8 u8Idx)
3742 {
3743 if (GET_FRMINFO_BUFFADD(u8Idx)==0)
3744 {
3745 MVD_DEBUGERROR(printf("%s error: pu8MVDGetFrameInfoBufStart=NULL\n", __FUNCTION__));
3746 return 0xff;
3747 }
3748
3749 return (MS_U8)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_MATRIX_COEF, sizeof(MS_U8));
3750 }
3751
HAL_MVD_StepDecode(MS_U8 u8Idx)3752 MS_BOOL HAL_MVD_StepDecode(MS_U8 u8Idx)
3753 {
3754 MVD_CmdArg mvdcmd;
3755 SETUP_CMDARG(mvdcmd);
3756 SET_DECNUM(mvdcmd, u8Idx);
3757 SET_CMD_RET_FALSE(CMD_SINGLE_STEP, &mvdcmd);
3758
3759 if (HAL_MVD_Resume(u8Idx) == FALSE)
3760 {
3761 MVD_DEBUGERROR(printf("Command: HAL_MVD_Resume fail!!\r\n"));
3762 return FALSE;
3763 }
3764
3765 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
3766 if (pCtrlCfg)
3767 {
3768 pCtrlCfg->bStepDecode = TRUE;
3769 }
3770
3771 return TRUE;
3772 }
3773
HAL_MVD_IsStepDispDone(MS_U8 u8Idx)3774 MS_BOOL HAL_MVD_IsStepDispDone(MS_U8 u8Idx)
3775 {
3776 return (MS_BOOL)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_STEP_DISP_DONE, sizeof(MS_U8));
3777 }
3778
HAL_MVD_IsStep2PtsDone(MS_U8 u8Idx)3779 MS_BOOL HAL_MVD_IsStep2PtsDone(MS_U8 u8Idx)
3780 {
3781 return (MS_BOOL)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_STEP_TO_PTS_DONE, sizeof(MS_U8));
3782 }
3783
3784 //Only for RCV.
HAL_MVD_GetPayloadLen(MS_U8 u8Idx)3785 MS_U32 HAL_MVD_GetPayloadLen(MS_U8 u8Idx)
3786 {
3787 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_RCV_PAYLOAD_LENGTH, sizeof(MS_U32));
3788 }
3789
3790 //Only for RCV.
HAL_MVD_GotFileEndPattern(MS_U8 u8Idx)3791 MS_BOOL HAL_MVD_GotFileEndPattern(MS_U8 u8Idx)
3792 {
3793 return (MS_BOOL)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_MEET_FILE_END_SC, sizeof(MS_U8));
3794 }
3795
HAL_MVD_IsCmdFinished(MS_U8 u8Idx,MVD_HANDSHAKE_CMD eCmd)3796 MS_BOOL HAL_MVD_IsCmdFinished(MS_U8 u8Idx, MVD_HANDSHAKE_CMD eCmd)
3797 {
3798 MVD_CMD_HANDSHADE_INDEX u32CmdState;
3799 MS_BOOL bCmdRdy = FALSE;
3800
3801 HAL_MVD_InvalidBuffRetFalse(GET_FRMINFO_BUFFADD(u8Idx));
3802
3803 u32CmdState.value = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CMD_HANDSHAKE_INDEX, sizeof(MS_U32));
3804 MVD_DEBUGINFO(printf("u32CmdState.value = 0x%x\n", u32CmdState.value));
3805 switch (eCmd)
3806 {
3807 case MVD_HANDSHAKE_PAUSE:
3808 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_pause);
3809 break;
3810 case MVD_HANDSHAKE_SLQ_RST:
3811 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_slq_reset);
3812 break;
3813 case MVD_HANDSHAKE_STOP:
3814 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_stop);
3815 break;
3816 case MVD_HANDSHAKE_SKIP_DATA:
3817 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_skip_data);
3818 break;
3819 case MVD_HANDSHAKE_SINGLE_STEP:
3820 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_single_step);
3821 break;
3822 case MVD_HANDSHAKE_SCALER_INFO:
3823 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_scaler_data_ready);
3824 break;
3825 case MVD_HANDSHAKE_GET_NXTDISPFRM:
3826 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_get_nextdispfrm_ready);
3827 break;
3828 case MVD_HANDSHAKE_PARSER_RST:
3829 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_parser_rst);
3830 break;
3831 case MVD_HANDSHAKE_RST_CC608:
3832 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_cc608_rst);
3833 break;
3834 case MVD_HANDSHAKE_RST_CC708:
3835 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_cc708_rst);
3836 break;
3837 case MVD_HANDSHAKE_VIRTUAL_COMMAND:
3838 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_virtualCommand);
3839 break;
3840 case MVD_HANDSHAKE_FLUSHQUEUE_COMMAND:
3841 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_flush);
3842 break;
3843 case MVD_HANDSHAKE_VSYNC_CONTROL:
3844 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_vsync_control);
3845 break;
3846 default:
3847 bCmdRdy = FALSE;
3848 break;
3849 }
3850 return bCmdRdy;
3851 }
3852
HAL_MVD_ClearCmdFinished(MS_U8 u8Idx,MVD_HANDSHAKE_CMD eCmd)3853 MS_BOOL HAL_MVD_ClearCmdFinished(MS_U8 u8Idx, MVD_HANDSHAKE_CMD eCmd)
3854 {
3855 MVD_CMD_HANDSHADE_INDEX u32CmdState;
3856
3857 HAL_MVD_InvalidBuffRetFalse(GET_FRMINFO_BUFFADD(u8Idx));
3858
3859 u32CmdState.value = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CMD_HANDSHAKE_INDEX, sizeof(MS_U32));
3860 MVD_DEBUGINFO(printf("before CLR u32CmdState.value = 0x%x\n", u32CmdState.value));
3861 switch (eCmd)
3862 {
3863 case MVD_HANDSHAKE_SCALER_INFO:
3864 u32CmdState.mvdcmd_handshake_scaler_data_ready = 0;
3865 break;
3866 default:
3867 break;
3868 }
3869
3870 //write the value back: may it overwrite the value that f/w is supposed to write?
3871 MVD_WriteFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CMD_HANDSHAKE_INDEX, sizeof(MS_U32), u32CmdState.value);
3872 MVD_DEBUGINFO(printf("after CLR u32CmdState.value = 0x%x\n",
3873 MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CMD_HANDSHAKE_INDEX, sizeof(MS_U32))));
3874 return TRUE;
3875 }
3876
3877
HAL_MVD_GetTimeCode(MS_U8 u8Idx,MVD_FrmInfoType eType,MVD_TimeCode * pInfo)3878 MS_BOOL HAL_MVD_GetTimeCode(MS_U8 u8Idx, MVD_FrmInfoType eType, MVD_TimeCode* pInfo)
3879 {
3880 MS_BOOL bRet = FALSE;
3881 MS_VIRT pu8MVDGetFrameInfoBufStart = GET_FRMINFO_BUFFADD(u8Idx);
3882 if (NULL == pInfo)
3883 {
3884 return FALSE;
3885 }
3886
3887 HAL_MVD_InvalidBuffRetFalse(pu8MVDGetFrameInfoBufStart);
3888
3889 if (E_MVD_FRMINFO_DECODE == eType)
3890 {
3891 pInfo->u8TimeCodeHr = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_HOURS);
3892 pInfo->u8TimeCodeMin = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_MINUTES);
3893 pInfo->u8TimeCodeSec = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_SECONDS);
3894 pInfo->u8TimeCodePic = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_PICTURES);
3895 pInfo->u8DropFrmFlag = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_DROP_FRAME_FLAG);
3896 }
3897 else if (E_MVD_FRMINFO_DISPLAY == eType)
3898 {
3899 pInfo->u8TimeCodeHr = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_HOURS_DISP);
3900 pInfo->u8TimeCodeMin = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_MINUTES_DISP);
3901 pInfo->u8TimeCodeSec = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_SECONDS_DISP);
3902 pInfo->u8TimeCodePic = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_PICTURES_DISP);
3903 pInfo->u8DropFrmFlag = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_DROP_FRAME_FLAG_DISP);
3904 }
3905 else
3906 {
3907 bRet = FALSE;
3908 }
3909
3910 return bRet;
3911 }
3912
HAL_MVD_GetDispCnt(MS_U8 u8Idx)3913 MS_U32 HAL_MVD_GetDispCnt(MS_U8 u8Idx)
3914 {
3915 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DISPLAYED_CNT, sizeof(MS_U32));
3916 }
3917
HAL_MVD_GetMinTspDataSize(MS_U8 u8HalIdx)3918 MS_U32 HAL_MVD_GetMinTspDataSize(MS_U8 u8HalIdx)
3919 {
3920 #ifdef OFFSET_CUR_MIN_TSP_DATA_SIZE
3921 return MVD_GetFWBuffData(u8HalIdx, FW_BUFF_FRMINFO, OFFSET_CUR_MIN_TSP_DATA_SIZE, sizeof(MS_U32));
3922 #else
3923 return 0x400;
3924 #endif
3925 }
3926
HAL_MVD_GetDropCnt(MS_U8 u8Idx)3927 MS_U32 HAL_MVD_GetDropCnt(MS_U8 u8Idx)
3928 {
3929 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DROP_FRAME_COUNT, sizeof(MS_U32));
3930 }
HAL_MVD_GetXcLowDelayIntState(MS_U8 u8Idx)3931 MS_U32 HAL_MVD_GetXcLowDelayIntState(MS_U8 u8Idx)
3932 {
3933 MS_VIRT pu8MVDGetFrameInfoBufStart = GET_FRMINFO_BUFFADD(u8Idx);
3934
3935 if(pu8MVDGetFrameInfoBufStart==0)
3936 {
3937 MVD_DEBUGERROR(printf("MDrv_MVD_GetXcLowDelayIntState error: pu8MVDGetFrameInfoBufStart=NULL\n"));
3938 return 0;
3939 }
3940
3941 MVD_DEBUGINFO(printf("MDrv_MVD_GetXcLowDelayIntState()=%x,%x,%x,%x,%x\n",
3942 (HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_XC_LOW_DELAY_CNT)),
3943 (HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_XC_LOW_DELAY_INT_STATE)),
3944 (HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_XC_DIFF_FIELD_NO)),
3945 (HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_XC_LOW_DELAY_CNT_LATCH)),
3946 (HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_FRAME_COUNT))));
3947
3948 return HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_XC_LOW_DELAY_INT_STATE);
3949 }
3950
3951 //Get ErrStatus when ErrCode==ErrShape
MVD_GetErrShapeStat(MS_U32 u32errStat)3952 static MVD_ErrStatus MVD_GetErrShapeStat(MS_U32 u32errStat)
3953 {
3954 MVD_ErrStatus st = E_MVD_ERR_STATUS_UNKOWN;
3955 switch (u32errStat)
3956 {
3957 case 0:
3958 st = E_MVD_ERR_SHAPE_RECTANGULAR;
3959 break;
3960 case 1:
3961 st = E_MVD_ERR_SHAPE_BINARY;
3962 break;
3963 case 2:
3964 st = E_MVD_ERR_SHAPE_BINARY_ONLY;
3965 break;
3966 case 3:
3967 st = E_MVD_ERR_SHAPE_GRAYSCALE;
3968 break;
3969 default:
3970 break;
3971 }
3972 return st;
3973 }
3974
3975 //Get ErrStatus when ErrCode==ErrSprite
MVD_GetErrSpriteStat(MS_U32 u32errStat)3976 static MVD_ErrStatus MVD_GetErrSpriteStat(MS_U32 u32errStat)
3977 {
3978 MVD_ErrStatus st = E_MVD_ERR_STATUS_UNKOWN;
3979 switch (u32errStat)
3980 {
3981 case 0:
3982 st = E_MVD_ERR_USED_SPRITE_UNUSED;
3983 break;
3984 case 1:
3985 st = E_MVD_ERR_USED_SPRITE_STATIC;
3986 break;
3987 case 2:
3988 st = E_MVD_ERR_USED_SPRITE_GMC;
3989 break;
3990 case 3:
3991 st = E_MVD_ERR_USED_SPRITE_RESERVED;
3992 break;
3993 default:
3994 break;
3995 }
3996 return st;
3997 }
3998
HAL_MVD_GetErrInfo(MS_U8 u8Idx,MVD_ErrCode * errCode,MVD_ErrStatus * errStatus)3999 void HAL_MVD_GetErrInfo(MS_U8 u8Idx, MVD_ErrCode *errCode, MVD_ErrStatus *errStatus)
4000 {
4001 MS_U32 errorCode = E_MVD_ERR_UNKNOWN;
4002 MS_U32 errorStatus = E_MVD_ERR_STATUS_UNKOWN;
4003 MS_VIRT pu8MVDGetFrameInfoBufStart = GET_FRMINFO_BUFFADD(u8Idx);
4004
4005 if(pu8MVDGetFrameInfoBufStart==0)
4006 {
4007 MVD_DEBUGERROR(printf("MDrv_MVD_GetErrInfo error!\n"));
4008 return;
4009 }
4010
4011 errorCode = HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart + OFFSET_ERROR_CODE);
4012 errorStatus = HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart + OFFSET_ERROR_STATUS);
4013
4014 switch (errorCode)
4015 {
4016 case VOL_SHAPE:
4017 *errCode = E_MVD_ERR_SHAPE;
4018 *errStatus = MVD_GetErrShapeStat(errorStatus);
4019 break;
4020 case VOL_USED_SPRITE:
4021 *errCode = E_MVD_ERR_USED_SPRITE;
4022 *errStatus = MVD_GetErrSpriteStat(errorStatus);
4023 break;
4024 case VOL_NOT_8_BIT:
4025 *errCode = E_MVD_ERR_NOT_8_BIT;
4026 *errStatus = E_MVD_ERR_STATUS_NONE;
4027 break;
4028 case VOL_NERPRED_ENABLE:
4029 *errCode = E_MVD_ERR_NERPRED_ENABLE;
4030 *errStatus = E_MVD_ERR_STATUS_NONE;
4031 break;
4032 case VOL_REDUCED_RES_ENABLE:
4033 *errCode = E_MVD_ERR_REDUCED_RES_ENABLE;
4034 *errStatus = E_MVD_ERR_STATUS_NONE;
4035 break;
4036 case VOL_SCALABILITY:
4037 *errCode = E_MVD_ERR_SCALABILITY;
4038 *errStatus = E_MVD_ERR_STATUS_NONE;
4039 break;
4040 case VOL_H263_ERROR:
4041 *errCode = E_MVD_ERR_H263_ERROR;
4042 *errStatus = E_MVD_ERR_STATUS_NONE;
4043 break;
4044 case VOL_RES_NOT_SUPPORT:
4045 *errCode = E_MVD_ERR_RES_NOT_SUPPORT;
4046 *errStatus = E_MVD_ERR_STATUS_NONE;
4047 break;
4048 case VOL_MPEG4_NOT_SUPPORT:
4049 *errCode = E_MVD_ERR_MPEG4_NOT_SUPPORT;
4050 *errStatus = E_MVD_ERR_STATUS_NONE;
4051 break;
4052 case VOL_PROFILE_NOT_SUPPORT:
4053 *errCode = E_MVD_ERR_PROFILE_NOT_SUPPORT;
4054 *errStatus = E_MVD_ERR_STATUS_NONE;
4055 break;
4056 case VOL_RCV_ERROR_OCCUR:
4057 *errCode = E_MVD_ERR_RCV_ERROR_OCCUR;
4058 *errStatus = E_MVD_ERR_STATUS_NONE;
4059 break;
4060 case VOL_OTHER:
4061 *errCode = E_MVD_ERR_OTHER;
4062 *errStatus = E_MVD_ERR_STATUS_NONE;
4063 break;
4064 default:
4065 *errCode = E_MVD_ERR_UNKNOWN;
4066 *errStatus = E_MVD_ERR_STATUS_UNKOWN;
4067 break;
4068 }
4069
4070 return;
4071 }
4072
4073 //take care MIU1 address
HAL_MVD_GetMemOffset(MS_PHY u32PhyAdd)4074 MS_PHY HAL_MVD_GetMemOffset(MS_PHY u32PhyAdd)
4075 {
4076 if (u32PhyAdd >= pMVDHalContext->stMiuCfg.u32Miu2BaseAddr)
4077 {
4078 return (u32PhyAdd - pMVDHalContext->stMiuCfg.u32Miu2BaseAddr);
4079 }
4080 else if(u32PhyAdd >= pMVDHalContext->stMiuCfg.u32Miu1BaseAddr)
4081 {
4082 return (u32PhyAdd - pMVDHalContext->stMiuCfg.u32Miu1BaseAddr);
4083 }
4084 else
4085 {
4086 return u32PhyAdd;
4087 }
4088 }
4089
4090
HAL_MVD_SLQTblSendPacket(MS_U8 u8Idx,MVD_PacketInfo * pstVideoPKT)4091 MS_BOOL HAL_MVD_SLQTblSendPacket(MS_U8 u8Idx, MVD_PacketInfo *pstVideoPKT)
4092 {
4093 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
4094 MS_VIRT u32EsLast;
4095 MS_VIRT* u32LastEntry = &pstSlqTblInfo->pDrvSlqTbl->u32WrPtr;
4096 MS_VIRT* pu32EsNew = &pstSlqTblInfo->pDrvEsTbl->u32WrPtr;
4097 MS_U32 u32EntryWord = 0;
4098 MS_U32 u32Index = 0;
4099 MS_U32 u32Pts;
4100 MS_VIRT u32MVDFWPtsTblAddr = NULL;
4101 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
4102
4103 MS_U32 u32ESStart=0;
4104 MS_U32 u32ESEnd=0;
4105 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
4106
4107
4108 #if _SLQTBL_DUMP_PKT
4109 // static MS_U32 u32SendTimes[MAX_DEC_NUM]= {0, 0};
4110
4111 printf("Pkt[%x] st=0x%x len=0x%x pts=0x%x id_l=0x%x id_h=0x%x\n", u32SendTimes[u8Idx]++,
4112 pstVideoPKT->u32StAddr, pstVideoPKT->u32Length, pstVideoPKT->u32TimeStamp,
4113 pstVideoPKT->u32ID_L, pstVideoPKT->u32ID_H);
4114 #endif
4115
4116 #ifdef VDEC3
4117 if(pstCtrlCfg->u8McuMode == FALSE)
4118 #endif
4119 {
4120 u32MVDFWPtsTblAddr = GET_PTSTBL_BUFFADD(u8Idx);
4121 MS_ASSERT(u32MVDFWPtsTblAddr != NULL);
4122 if (u32MVDFWPtsTblAddr)
4123 {
4124 MS_VIRT u32PtsTblEntryAddr = 0;
4125 //so far, this is the only place that driver will write f/w 1M area after init.
4126 u32Index = (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr - pstSlqTblInfo->pDrvSlqTbl->u32StAdd)/8;
4127 if(HAL_MVD_IsMcuMode(u8Idx) == FALSE)
4128 {
4129 if (pstVideoPKT->u32TimeStamp != MVD_NULLPKT_PTS)
4130 {
4131 u32Pts = _MS_TO_90K(pstVideoPKT->u32TimeStamp);
4132 }
4133 else
4134 {
4135 u32Pts = MVD_NULLPKT_PTS;
4136 }
4137 }
4138 else
4139 {
4140 u32Pts = pstVideoPKT->u32TimeStamp;
4141 }
4142 u32PtsTblEntryAddr = u32MVDFWPtsTblAddr+u32Index*MVD_FW_SLQTBL_PTS_LEN;
4143 HAL_MVD_MemWrite4Byte(u32PtsTblEntryAddr+4, pstSlqTblInfo->u32DummyPktCnt); //dummyPktCnt
4144 HAL_MVD_MemWrite4Byte(u32PtsTblEntryAddr+8, pstVideoPKT->u32ID_L); //idLow
4145 HAL_MVD_MemWrite4Byte(u32PtsTblEntryAddr+12, pstVideoPKT->u32ID_H); //idHigh
4146 HAL_MVD_MemWrite4Byte(u32PtsTblEntryAddr+16, u32Pts); //PTS
4147 HAL_MVD_MemWrite4Byte(u32PtsTblEntryAddr, (pstSlqTblInfo->u32SlqByteCnt)&0xffffff); //byteCnt
4148 //printf("PTS=0x%x(%x), idx=0x%x add=0x%x\n", pstVideoPKT->u32TimeStamp,
4149 // HAL_MVD_MemRead4Byte(u32PtsTblEntryAddr+16),
4150 // u32Index, u32PtsTblEntryAddr+16);
4151
4152 if ((HAL_MVD_IsMStreamerMode(u8Idx) || HAL_MVD_IsMcuMode(u8Idx))
4153 && (pstCtrlCfg->eFileSyncMode == E_MVD_TIMESTAMP_STS))
4154 {
4155 if(pMVDHalContext->bDropOnePTS[u8Idx] == FALSE)
4156 {
4157 HAL_MVD_MemWrite4Byte(u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_LEN+12, pstVideoPKT->u32ID_H); //idHigh
4158 HAL_MVD_MemWrite4Byte(u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_LEN+16, pstVideoPKT->u32TimeStamp); //PTS
4159
4160 MVD_DBG_STS(printf(">>> drvMVD pts,idH = %lu, %lu\n", HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_LEN+16),
4161 HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_LEN+12)));
4162 if (((MVD_NULLPKT_PTS == pstVideoPKT->u32ID_H) && (MVD_NULLPKT_PTS == pstVideoPKT->u32TimeStamp)) == FALSE)
4163 { //Only update PTS to firmware when pts field is valid.
4164 //Plz refer to MDrv_MVD_PushQueue if (u8MstMode == MST_MODE_TRUE) {}
4165 HAL_MVD_UpdatePts(u8Idx); //for uniplayer or MCU mode
4166 }
4167 }
4168
4169 pMVDHalContext->bDropOnePTS[u8Idx] = FALSE;
4170 }
4171 }
4172 #if _SLQTBL_DUMP_PTS
4173 if (u32Index == 0x177)
4174 {
4175 _SLQTbl_DumpPtsTbl(u8Idx, 0, 0x179);
4176 }
4177 #endif
4178 }
4179 pstSlqTblInfo->u32SlqByteCnt += pstVideoPKT->u32Length;
4180
4181 //update SLQ tbl entry
4182 //u32EsLast = (pstVideoPKT->u32StAddr)+pstSlqTblInfo->pDrvSlqTbl->u32StAdd;
4183 u32EsLast = (pstVideoPKT->u32StAddr)+HAL_MVD_GetMemOffset(pstMemCfg->u32BSAddr);
4184 HAL_MVD_MemWrite4Byte(*pu32EsNew, u32EsLast-HAL_MVD_GetMemOffset(pstMemCfg->u32BSAddr));
4185 u32ESStart = (u32EsLast) & SLQ_TBL_ENTRY_LEN;
4186
4187 u32EsLast += pstVideoPKT->u32Length; //update ES write pointer
4188 //Notice: This is for MVD HW, so no need to minus one.
4189 HAL_MVD_MemWrite4Byte((*pu32EsNew)+4, u32EsLast-HAL_MVD_GetMemOffset(pstMemCfg->u32BSAddr));
4190 u32ESEnd = (u32EsLast) & SLQ_TBL_ENTRY_LEN;
4191
4192 *pu32EsNew += 8;
4193 if (*pu32EsNew >= pstSlqTblInfo->pDrvEsTbl->u32EndAdd)
4194 { //wrap to the beginning of the table
4195 MVD_DEBUGINFO(printf("...ES wrapping to the beginning!\n"));
4196 *pu32EsNew = pstSlqTblInfo->pDrvEsTbl->u32StAdd;
4197 }
4198
4199 //printf("===>[%x] u32ESStart=0x%x u32ESEnd=0x%x u32EsLast=0x%x\n",
4200 // pMVDHalContext->u32SendTimes[u8Idx]++, u32ESStart, u32ESEnd, u32EsLast);
4201
4202 u32EntryWord = u32ESEnd;
4203 HAL_MVD_MemWrite4Byte(*u32LastEntry, u32EntryWord);
4204 //printf("===> u32EntryWord1 addr=0x%x\n", (*u32LastEntry));
4205 //printf("===> u32EntryWord0=0x%x\n", u32EntryWord);
4206
4207 u32EntryWord = u32ESStart;
4208 HAL_MVD_MemWrite4Byte((*u32LastEntry)+4, u32EntryWord);
4209 //printf("===> u32EntryWord1 addr=0x%x\n", (*u32LastEntry)+4);
4210 //printf("===> u32EntryWord1=0x%x\n", u32EntryWord);
4211
4212 *u32LastEntry += 8;
4213 if (*u32LastEntry >= pstSlqTblInfo->pDrvSlqTbl->u32EndAdd)
4214 { //wrap to the beginning of the table
4215 MVD_DEBUGINFO(printf("...wrapping to the beginning!\n"));
4216 *u32LastEntry = pstSlqTblInfo->pDrvSlqTbl->u32StAdd;
4217 //also wrap DivX311 pattern table
4218 pstSlqTblInfo->pDrvDivxTbl->u32WrPtr = pstSlqTblInfo->pDrvDivxTbl->u32StAdd;
4219 }
4220
4221 if (pstSlqTblInfo->pDrvSlqTbl->u32Empty)
4222 {
4223 pstSlqTblInfo->pDrvSlqTbl->u32Empty -= SLQ_ENTRY_LEN;
4224 }
4225
4226 return TRUE;
4227 }
4228
4229 //Table of frame rate code for MPEG-2
4230 #if 0
4231 #define FRM_RATE_CODE_NUM 9
4232 static const MS_U16 stFrameRateCode[FRM_RATE_CODE_NUM]=
4233 {
4234 NULL,23976,24000,25000,29976,30000,50000,59947,60000
4235 };
4236 #endif
MVD_GCD(MS_U32 u32A,MS_U32 u32B)4237 static MS_U32 MVD_GCD(MS_U32 u32A, MS_U32 u32B)
4238 {
4239 MS_S32 i;
4240 MS_U32 x[4]; /* need x[0], x[1], x[i-1] */
4241
4242 if (u32A > u32B)
4243 {
4244 x[0] = u32A; x[1] = u32B;
4245 }
4246 else
4247 {
4248 x[0] = u32B; x[1] = u32A;
4249 }
4250
4251 i = 1;
4252
4253 #define w(x) (((x)<4)?(x):(2+((x)&1)))
4254
4255 while( x[w(i)] != 0 )
4256 {
4257 x[w(i+1)] = x[w(i-1)] % x[w(i)];
4258 i++;
4259 }
4260
4261 return x[w(i-1)];
4262
4263 #undef w
4264 }
HAL_MVD_GetFrameInfo(MS_U8 u8Idx,MVD_FrameInfo * pinfo)4265 void HAL_MVD_GetFrameInfo(MS_U8 u8Idx, MVD_FrameInfo *pinfo)
4266 {
4267 FW_VOL_INFO gvolInfo;
4268 FW_DIVX_INFO* pDivxInfo = &(pMVDHalContext->gdivxInfo[u8Idx]);
4269 MS_VIRT temp = 0;
4270 MS_U32 u32DAR_Width=0,u32DAR_Height=0,u32PAR_Width=0,u32PAR_Height=0,u32GCD=0;
4271 MS_U32 u32Vertical_Size=0, u32Horizontal_Size=0;
4272 //13818-2 page 38 Table 6-3
4273 MS_U8 u8DARTable[5][2] = { {1,1}, {1,1}, {4,3}, {16,9}, {221,100} };
4274 MS_U32 pu8MVDGetVolBufStart = NULL;
4275 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
4276
4277 pu8MVDGetVolBufStart = GET_VOL_BUFFADD(u8Idx);
4278 if (pu8MVDGetVolBufStart == NULL)
4279 {
4280 MVD_DEBUGERROR(printf("MDrv_MVD_GetFrameInfo error: pu8MVDGetVolBufStart=NULL\n"));
4281 return;
4282 }
4283
4284 HAL_MVD_CPU_Sync();
4285 HAL_MVD_ReadMemory();
4286
4287 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,GET_VOL_BUFFADD(u8Idx),temp);
4288
4289 gvolInfo = (*(volatile FW_VOL_INFO*)(HAL_MVD_PA2NonCacheSeg(temp)));
4290
4291 pinfo->u16HorSize = (MS_U16) gvolInfo.width;
4292 pinfo->u16VerSize = (MS_U16) gvolInfo.height;
4293 pinfo->u16par_width = (MS_U16) gvolInfo.par_width;
4294 pinfo->u16par_height = (MS_U16) gvolInfo.par_height;
4295 pinfo->u8AspectRate = gvolInfo.aspect_ratio;
4296
4297 pinfo->u16CropBottom = gvolInfo.CropBottom;
4298 pinfo->u16CropTop = 0;
4299 pinfo->u16CropLeft = 0;
4300
4301 if (pinfo->u16HorSize & MVD_WIDTH_ALIGN_MASK)
4302 {
4303 //Notice: Firmware and driver have to be consistent for this part,
4304 // otherwise the pitch will not match and video is noisy.
4305 pinfo->u16CropRight = MVD_WIDTH_ALIGN_BYTE - (pinfo->u16HorSize & MVD_WIDTH_ALIGN_MASK);
4306 pinfo->u16HorSize = ((pinfo->u16HorSize >> MVD_WIDTH_ALIGN_BITS) + 1) << MVD_WIDTH_ALIGN_BITS;
4307 }
4308 else
4309 {
4310 pinfo->u16CropRight = 0;
4311 }
4312
4313 MVD_CodecType curCodecType = HAL_MVD_GetCodecType(u8Idx);
4314 if ((curCodecType == E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER) ||
4315 (curCodecType == E_MVD_CODEC_DIVX311) || (curCodecType == E_MVD_CODEC_FLV))
4316 {
4317 pinfo->u8Interlace= FALSE; //divx311/flv/svh just has progressive mode
4318 MS_ASSERT(gvolInfo.progressive_sequence == 1); //FW will init it as 1
4319 }
4320 else
4321 {
4322 if (gvolInfo.progressive_sequence == 0)
4323 {
4324 pinfo->u8Interlace=1;
4325 }
4326 else
4327 {
4328 pinfo->u8Interlace=0;
4329 }
4330 }
4331
4332 ///Calculate PAR info
4333 if (pinfo->u16par_width == 0 || pinfo->u16par_height == 0)
4334 {
4335 if ((pinfo->u8AspectRate > 0) && (pinfo->u8AspectRate < 5 ))
4336 {
4337 if (pinfo->u8AspectRate == 1)
4338 { //SAR=1.0 square sample
4339 u32DAR_Width = (MS_U32)pinfo->u16HorSize;
4340 u32DAR_Height = (MS_U32)pinfo->u16VerSize;
4341 pinfo->u16par_width = 1;
4342 pinfo->u16par_height = 1;
4343 }
4344 else
4345 {
4346 u32DAR_Width = (MS_U32)u8DARTable[pinfo->u8AspectRate][0];
4347 u32DAR_Height = (MS_U32)u8DARTable[pinfo->u8AspectRate][1];
4348 u32Vertical_Size = (MS_U32)pinfo->u16VerSize;
4349 u32Horizontal_Size = (MS_U32)(pinfo->u16HorSize - pinfo->u16CropRight);
4350 u32PAR_Width = u32DAR_Width * u32Vertical_Size;
4351 u32PAR_Height = u32DAR_Height * u32Horizontal_Size;
4352 u32GCD = MVD_GCD(u32PAR_Width, u32PAR_Height);
4353 if (0 == u32GCD)
4354 {
4355 pinfo->u16HorSize = 0xFFFF;
4356 pinfo->u16VerSize = 0xFFFF;
4357
4358 return;
4359 }
4360 else
4361 {
4362 pinfo->u16par_width = (MS_U16) (u32PAR_Width / u32GCD);
4363 pinfo->u16par_height = (MS_U16) (u32PAR_Height / u32GCD);
4364 MVD_DEBUGVERBAL(printf("u32PAR_Width:%d,u32PAR_Height:%d,GCD:%d\n",u32PAR_Width,u32PAR_Height,u32GCD));
4365 }
4366 }
4367 }
4368 else
4369 {
4370 //set to 0 to indicate it's abnormal
4371 u32DAR_Width = 0;
4372 u32DAR_Height = 0;
4373 pinfo->u16par_width = 0;
4374 pinfo->u16par_height = 0;
4375 }
4376 MVD_DEBUGVERBAL(printf("u32DAR_Width:%d,u32DAR_Height%d\n",u32DAR_Width,u32DAR_Height));
4377 }
4378 MVD_DEBUGVERBAL(printf("pinfo->u16par_width:%d, pinfo->u16par_height:%d\n",pinfo->u16par_width, pinfo->u16par_height));
4379
4380 if (curCodecType == E_MVD_CODEC_MPEG2)
4381 {
4382 if (gvolInfo.frame_rate < FRM_RATE_CODE_NUM)
4383 {
4384 pinfo->u32FrameRate = stFrameRateCode[gvolInfo.frame_rate];
4385 }
4386 else
4387 {
4388 pinfo->u32FrameRate = 0;
4389 }
4390 }
4391 else if ((curCodecType == E_MVD_CODEC_VC1_ADV) || (curCodecType == E_MVD_CODEC_VC1_MAIN))
4392 {
4393 if ((gvolInfo.vc1_frame_rate != 0) && (gvolInfo.vc1_frame_rate != MVD_U32_MAX))
4394 {
4395 pinfo->u32FrameRate = gvolInfo.vc1_frame_rate;
4396 }
4397 else if(pMVDHalContext->u32DmxFrameRate[u8Idx] != 0 && pMVDHalContext->u32DmxFrameRateBase[u8Idx] != 0)
4398 {
4399 pinfo->u32FrameRate = (pMVDHalContext->u32DmxFrameRate[u8Idx] * 1000) / pMVDHalContext->u32DmxFrameRateBase[u8Idx];
4400 }
4401 else
4402 {
4403 pinfo->u32FrameRate = pDivxInfo->frame_rate; //report framerate specified in MDrv_MVD_SetFrameInfo()
4404 }
4405
4406 MVD_DEBUGVERBAL(printf("MVD: vc1_frameRate=%d\n", pinfo->u32FrameRate));
4407 }
4408 else if (curCodecType == E_MVD_CODEC_MPEG4)
4409 {
4410 if (pDivxInfo->frame_rate != 0)
4411 {
4412 pinfo->u32FrameRate = pDivxInfo->frame_rate;
4413 //report framerate specified in MDrv_MVD_SetFrameInfo(), which is usually obtained from container
4414 }
4415 else if (gvolInfo.frame_rate != 0)
4416 {
4417 pinfo->u32FrameRate = gvolInfo.frame_rate; //report framerate from f/w
4418 }
4419 else if ((gvolInfo.fixed_vop_time_incr != 0) && (gvolInfo.vol_time_incr_res != 0))
4420 {
4421 pinfo->u32FrameRate = (gvolInfo.vol_time_incr_res * 1000) / gvolInfo.fixed_vop_time_incr;
4422 //calculate framerate according to vol header
4423 }
4424 else if(pMVDHalContext->u32DmxFrameRate[u8Idx] != 0 && pMVDHalContext->u32DmxFrameRateBase[u8Idx] != 0)
4425 {
4426 pinfo->u32FrameRate = (pMVDHalContext->u32DmxFrameRate[u8Idx] * 1000) / pMVDHalContext->u32DmxFrameRateBase[u8Idx];
4427 }
4428 else
4429 {
4430 pinfo->u32FrameRate = 60000; //set default frame rate according to chip capability
4431 }
4432 MVD_DEBUGVERBAL(printf("MVD: vol_time_incr_res=%d, fixed_vop_time_incr=%d\n", gvolInfo.vol_time_incr_res, gvolInfo.fixed_vop_time_incr));
4433 }
4434 else
4435 {
4436 if (gvolInfo.frame_rate != 0)
4437 {
4438 pinfo->u32FrameRate = gvolInfo.frame_rate;
4439 }
4440 else
4441 {
4442 pinfo->u32FrameRate = pDivxInfo->frame_rate; //report framerate specified in MDrv_MVD_SetFrameInfo()
4443 }
4444 }
4445 MVD_DEBUGVERBAL(printf("===> MVD: frameRate=%d curCodecType=0x%x\n", pinfo->u32FrameRate, curCodecType));
4446
4447 //for MM
4448 pinfo->u8MPEG1=gvolInfo.mpeg1;
4449 pinfo->u16PTSInterval=gvolInfo.pts_incr;
4450 pinfo->u8PlayMode=gvolInfo.play_mode;
4451 pinfo->u8FrcMode=gvolInfo.mpeg_frc_mode;
4452
4453 //for dynamic scaling
4454 pinfo->bEnableMIUSel = (MS_BOOL)pMVDHalContext->stMiuCfg.u8FWMiuSel;
4455
4456 if(pMVDHalContext->stMiuCfg.u8FWMiuSel >= E_CHIP_MIU_2)
4457 {
4458 MVD_DEBUGERROR(printf("u8MiuSel is %d !!, but return type is only Boolean. Please use MDrv_HVD_EX_GetDSBufMiuSelect() to get right miu select of DS buffer!\n",pMVDHalContext->stMiuCfg.u8FWMiuSel));
4459 }
4460
4461 if (pstMemCfg->bEnableDynScale)
4462 {
4463 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,GET_DS_BUFFADD(u8Idx),pinfo->u32DynScalingAddr);
4464
4465 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
4466 pinfo->u8DynScalingDepth= pCtrlCfg->u8DynScalingDepth;
4467 pinfo->u32DynScalingBufSize= gvolInfo.DSbufsize;
4468 }
4469 else
4470 {
4471 pinfo->u32DynScalingAddr= NULL;
4472 pinfo->u8DynScalingDepth= 0;
4473 pinfo->u32DynScalingBufSize= 0;
4474 }
4475
4476 return;
4477 }
4478
MVD_RstFrmInfo(MS_U8 u8Idx,MVD_FrmInfoType eType)4479 E_MVD_Result MVD_RstFrmInfo(MS_U8 u8Idx, MVD_FrmInfoType eType)
4480 {
4481 E_MVD_Result eRet = E_MVD_RET_OK;
4482 MS_VIRT u32DecFrmInfoAdd = GET_DECFRMINFO_BUFFADD(u8Idx);
4483 if (NULL == u32DecFrmInfoAdd)
4484 {
4485 return E_MVD_RET_FAIL;
4486 }
4487
4488 //printf("%s u32DecFrmInfoAdd = 0x%x\n", __FUNCTION__, u32DecFrmInfoAdd);
4489 if (E_MVD_FRMINFO_DECODE == eType)
4490 {
4491 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_LUMAADDR), _INIT_ADDR);
4492 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_CHROMAADDR), _INIT_ADDR);
4493 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_TIMESTAMP), _INIT_TIMESTAMP);
4494 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_ID_L), _INIT_ID);
4495 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_ID_H), _INIT_ID);
4496 HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_PITCH), _INIT_LEN);
4497 HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_WIDTH), _INIT_LEN);
4498 HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_HEIGHT), _INIT_LEN);
4499 HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_FRAMETYPE), 0xff);
4500 }
4501 else if (E_MVD_FRMINFO_DISPLAY == eType)
4502 {
4503 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_LUMAADDR), _INIT_ADDR);
4504 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_CHROMAADDR), _INIT_ADDR);
4505 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_TIMESTAMP), _INIT_TIMESTAMP);
4506 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_ID_L), _INIT_ID);
4507 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_ID_H), _INIT_ID);
4508 HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_PITCH), _INIT_LEN);
4509 HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_WIDTH), _INIT_LEN);
4510 HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_HEIGHT), _INIT_LEN);
4511 HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_FRAMETYPE), 0xff);
4512 }
4513 else
4514 {
4515 eRet = E_MVD_RET_INVALID_PARAM;
4516 }
4517
4518 return eRet;
4519 }
4520
4521 //Given the start address & the available size for the FW buffers,
4522 //Calculate the start address of each buffers.
MVD_GetFWBuffAdd(MS_VIRT u32Start,MS_U32 u32AvailLen,MVD_FWBuff * pBuff)4523 static MS_BOOL MVD_GetFWBuffAdd(MS_VIRT u32Start, MS_U32 u32AvailLen, MVD_FWBuff* pBuff)
4524 {
4525 MS_VIRT tmpAdr = u32Start;
4526
4527 if(pBuff == NULL)
4528 {
4529 MVD_DEBUGERROR(printf("%s err: NULL pBuff\n", __FUNCTION__));
4530 return FALSE;
4531 }
4532 tmpAdr += MVD_FW_CODE_LEN;
4533 GET_FW_BUFFADD_ALIGN(tmpAdr, FW_BUFF_ALIGN, MVD3_FW_VOL_INFO_BUF_LEN, pBuff->pu8MVDGetVolBufStart);
4534 GET_FW_BUFFADD_ALIGN(tmpAdr, FW_BUFF_ALIGN, MVD3_FW_FRAME_INFO_BUF_LEN, pBuff->pu8MVDGetFrameInfoBufStart);
4535 GET_FW_BUFFADD_ALIGN(tmpAdr, FW_BUFF_ALIGN, MVD3_FW_DIVX_INFO_BUF_LEN, pBuff->pu8MVDSetHeaderBufStart);
4536 GET_FW_BUFFADD_ALIGN(tmpAdr, FW_BUFF_ALIGN,
4537 (MVD3_FW_USER_DATA_BUF_LEN+MVD3_FW_USER_DATA_BUF_BACKUP_LEN), pBuff->u32UserDataBuf);
4538 //MVD3_FW_USER_DATA_BUF_BACKUP_LEN is used as CC decoding buffer for MVD_SUPPORT_X4_CC
4539
4540 GET_FW_BUFFADD_ALIGN(tmpAdr, FW_BUFF_ALIGN, MVD3_FW_SLQ_TAB_TMPBUF_LEN, pBuff->u32MVDFWSLQTABTmpbufAdr);
4541 GET_FW_BUFFADD(tmpAdr, MVD_FW_SLQTBL_PTS_BUF_LEN, pBuff->u32MVDFWPtsTblAddr);
4542 GET_FW_BUFFADD(tmpAdr, MVD_FW_DYN_SCALE_BUF_LEN, pBuff->u32DynScalingAdd);
4543 GET_FW_BUFFADD(tmpAdr, MVD_FW_SCALER_INFO_BUF_LEN, pBuff->u32ScalerInfoAdd);
4544 GET_FW_BUFFADD(tmpAdr, MVD_FW_DECFRM_INFO_BUF_LEN, pBuff->u32DecFrmInfoAdd);
4545 GET_FW_BUFFADD(tmpAdr, MVD_FW_VBBU_TABLE_LEN, pBuff->u32VBBUTableAdd);
4546
4547
4548 MVD_DEBUGINFO(printf("set pu8MVDGetVolBufStart=%lx\n", (unsigned long)pBuff->pu8MVDGetVolBufStart));
4549 MVD_DEBUGINFO(printf("set pu8MVDGetFrameInfoBufStart=%lx\n", (unsigned long)pBuff->pu8MVDGetFrameInfoBufStart));
4550 MVD_DEBUGINFO(printf("set pu8MVDSetHeaderBufStart=%lx\n", (unsigned long)pBuff->pu8MVDSetHeaderBufStart));
4551 MVD_DEBUGINFO(printf("u32UserDataBuf start=%lx\n", (unsigned long)pBuff->u32UserDataBuf));
4552 MVD_DEBUGINFO(printf("u32MVDFWSLQTABTmpbufAdr start=%lx\n", (unsigned long)pBuff->u32MVDFWSLQTABTmpbufAdr));
4553 MVD_DEBUGINFO(printf("PtsTblAddr start=%lx\n", (unsigned long)pBuff->u32MVDFWPtsTblAddr));
4554 MVD_DEBUGINFO(printf("u32DynScalingAdd start=%lx\n", (unsigned long)pBuff->u32DynScalingAdd));
4555 MVD_DEBUGINFO(printf("ScalerInfo start=%lx end=%lx\n",
4556 (unsigned long)pBuff->u32ScalerInfoAdd, (pBuff->u32ScalerInfoAdd+MVD_FW_SCALER_INFO_BUF_LEN)));
4557 MVD_DEBUGINFO(printf("DecFrmInfo start=%lx end=%lx\n",
4558 (unsigned long)pBuff->u32DecFrmInfoAdd, (pBuff->u32DecFrmInfoAdd+MVD_FW_DECFRM_INFO_BUF_LEN)));
4559
4560 MS_U32 u32ShMemBoundary = (MVD_FW_CODE_LEN==MVD_FW_CODE_LEN_V00) ? MVD_FW_MPOOL_START_OFFSET : MVD_FW_TASK_OFFSET;
4561 #if v3_temp
4562
4563 if ((pBuff->u32VBBUTableAdd+MVD_FW_VBBU_TABLE_LEN-u32Start) > u32ShMemBoundary)
4564 {
4565 //shared memory should not overlap with FW memory pool.
4566 MVD_DEBUGERROR(printf("%s err: 0x%lx out of memory boundary!\n", __FUNCTION__,
4567 (pBuff->u32VBBUTableAdd+MVD_FW_VBBU_TABLE_LEN-u32Start)));
4568 return FALSE;
4569 }
4570 #else
4571 if ((pBuff->u32DecFrmInfoAdd+MVD_FW_DECFRM_INFO_BUF_LEN-u32Start) > u32ShMemBoundary)
4572 {
4573 //shared memory should not overlap with FW memory pool.
4574 MVD_DEBUGERROR(printf("%s err: 0x%x out of memory boundary!\n", __FUNCTION__,
4575 (pBuff->u32DecFrmInfoAdd+MVD_FW_DECFRM_INFO_BUF_LEN-u32Start)));
4576 return FALSE;
4577 }
4578 #endif
4579
4580 return TRUE;
4581 }
4582
4583 //Set buffer address to f/w
4584 //Init the memory erea if necessary
MVD_SetFWBuffAdd(MS_U8 u8Idx,MVD_FWBuff * pBuff)4585 static MS_BOOL MVD_SetFWBuffAdd(MS_U8 u8Idx, MVD_FWBuff* pBuff)
4586 {
4587 MS_U32 i;
4588 MVD_SrcMode curSrcMode = E_MVD_SRC_UNKNOWN;
4589 MVD_MEMCfg* pstMemCfg = NULL;
4590 MVD_CtrlCfg* pCtrlCfg = NULL;
4591
4592 if(pBuff == NULL)
4593 {
4594 MVD_DEBUGERROR(printf("%s err: NULL pBuff\n", __FUNCTION__));
4595 return FALSE;
4596 }
4597
4598 pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
4599
4600 MVD_DEBUGINFO(printf("\nMIU is (shm,hw,fw)=(%x,%x,%x)\n",u8SHMMiuSel,pstMemCfg->u8HWMiuSel,pstMemCfg->u8FWMiuSel));
4601
4602 curSrcMode = HAL_MVD_GetSrcMode(u8Idx);
4603
4604 HAL_MVD_SetVolInfoBufferAddr(u8Idx, pBuff->pu8MVDGetVolBufStart);
4605 _MVD_Memset(pBuff->pu8MVDGetVolBufStart, 0, MVD3_FW_VOL_INFO_BUF_LEN);
4606
4607 pBuff->u32VolAdd = pBuff->pu8MVDGetVolBufStart;
4608
4609 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,pBuff->u32VolAdd,pBuff->u32VolAdd);
4610
4611 pBuff->u32VolAdd = HAL_MVD_PA2NonCacheSeg(pBuff->u32VolAdd);
4612 MVD_DEBUGINFO(printf("gvolInfo = 0x%lx, volBuf=0x%lx\n", (unsigned long)pBuff->u32VolAdd, (unsigned long)pBuff->pu8MVDGetVolBufStart));
4613
4614 HAL_MVD_SetFrameInfoBufferAddr(u8Idx, pBuff->pu8MVDGetFrameInfoBufStart);
4615 _MVD_Memset(pBuff->pu8MVDGetFrameInfoBufStart, 0, MVD3_FW_FRAME_INFO_BUF_LEN);
4616
4617 HAL_MVD_SetHeaderBufferAddr(u8Idx, pBuff->pu8MVDSetHeaderBufStart);
4618 HAL_MVD_SetUserDataBuf(u8Idx, pBuff->u32UserDataBuf, MVD3_FW_USER_DATA_BUF_LEN);
4619 pCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
4620 pCtrlCfg->u32UsrDataRd = pBuff->u32UserDataBuf;
4621
4622
4623 if((curSrcMode != E_MVD_TS_FILE_MODE)
4624 && (curSrcMode != E_MVD_TS_MODE))
4625 {
4626 _MVD_Memset(pBuff->u32MVDFWSLQTABTmpbufAdr, 0, MVD3_FW_SLQ_TAB_TMPBUF_LEN);
4627 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWSLQTABTmpbufAdr, 0xBE010000UL);
4628 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWSLQTABTmpbufAdr+4, 0x000000FAUL);
4629
4630 HAL_MVD_SetPtsTblAddr(u8Idx, pBuff->u32MVDFWPtsTblAddr);
4631 for (i=0; i<MVD_FW_SLQTBL_PTS_BUF_LEN; i+=MVD_FW_SLQTBL_PTS_LEN)
4632 {
4633 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWPtsTblAddr+i, 0); //byteCnt
4634 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWPtsTblAddr+i+4, 0); //dummyPktCnt
4635 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWPtsTblAddr+i+8, 0); //idLow
4636 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWPtsTblAddr+i+12, 0); //idHigh
4637
4638 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWPtsTblAddr+i+16, MVD_NULLPKT_PTS); //PTS
4639 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWPtsTblAddr+i+20, 0); //reserved0
4640 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWPtsTblAddr+i+24, 0); //reserved1
4641 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWPtsTblAddr+i+28, 0); //reserved2
4642 }
4643 //MS_ASSERT((u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_BUF_LEN)<=(u32start+u32len));
4644 MVD_DEBUGINFO(printf("PTS tbl start=%lx end=%lx\n",
4645 (unsigned long)pBuff->u32MVDFWPtsTblAddr, (unsigned long)(pBuff->u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_BUF_LEN)));
4646
4647 pBuff->u32VBBUTableAdd = VBBU_TABLE_START+u8Idx*0x100000;
4648 }
4649
4650 if (pstMemCfg->bEnableDynScale)
4651 {
4652 HAL_MVD_SetDynamicScaleAddr(u8Idx, pBuff->u32DynScalingAdd);
4653 HAL_MVD_EnableDynamicScale(u8Idx,0); //default old DS style
4654 pCtrlCfg->u8DynScalingDepth = 32; //HAL_MVD_GetDynamicScaleDepth
4655 MVD_DEBUGINFO(printf("u8EnableMIUSel = 0x%x\n", pMVDHalContext->stMiuCfg.u8FWMiuSel));
4656 MVD_DEBUGINFO(printf("u32DynScalingAddr= 0x%lx\n", (unsigned long)pBuff->u32DynScalingAdd));
4657 MVD_DEBUGINFO(printf("u8DynScalingDepth= 0x%x\n", pCtrlCfg->u8DynScalingDepth));
4658 }
4659 MVD_DEBUGINFO(printf("DynScaling start=%lx end=%lx\n",
4660 (unsigned long)pBuff->u32DynScalingAdd, (unsigned long)(pBuff->u32DynScalingAdd+MVD_FW_DYN_SCALE_BUF_LEN)));
4661
4662 HAL_MVD_SetDecFrmInfoAddr(u8Idx, pBuff->u32DecFrmInfoAdd);
4663
4664 MVD_RstFrmInfo(u8Idx, E_MVD_FRMINFO_DECODE);
4665 MVD_RstFrmInfo(u8Idx, E_MVD_FRMINFO_DISPLAY);
4666 MVD_DEBUGINFO(printf("DecFrmInfo start=%lx\n", (unsigned long)pBuff->u32DecFrmInfoAdd));
4667
4668 if (curSrcMode == E_MVD_SLQ_TBL_MODE)
4669 {
4670 HAL_MVD_SLQTblInit(u8Idx);
4671 }
4672
4673 return TRUE;
4674 }
4675
4676 #ifdef VDEC3
4677 #else
MVD_IsNextDispFrmRdy(MS_U8 u8Idx)4678 static MS_BOOL MVD_IsNextDispFrmRdy(MS_U8 u8Idx)
4679 {
4680 #define NXT_DISP_TIMEOUT 20000//0x20
4681 MS_U32 u32TimeOut = 0;
4682 MVD_CmdArg mvdcmd;
4683
4684 HAL_MVD_ResetHandShake(u8Idx, MVD_HANDSHAKE_GET_NXTDISPFRM);
4685 SETUP_CMDARG(mvdcmd);
4686 SET_DECNUM(mvdcmd, u8Idx);
4687 SET_CMD_RET_FALSE(CMD_GET_NEXTDISPFRM, &mvdcmd);
4688
4689 while(!HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_GET_NXTDISPFRM) && (u32TimeOut < NXT_DISP_TIMEOUT))
4690 {
4691 u32TimeOut++;
4692 }
4693 if(u32TimeOut >= NXT_DISP_TIMEOUT)
4694 {
4695 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_GET_NEXTDISPFRM ) );
4696 return FALSE;
4697 }
4698 return TRUE;
4699 }
4700 #endif
4701
HAL_MVD_GetExtDispInfo(MS_U8 u8Idx,MVD_ExtDispInfo * pInfo)4702 void HAL_MVD_GetExtDispInfo(MS_U8 u8Idx, MVD_ExtDispInfo* pInfo)
4703 {
4704 pInfo->u16VSize = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DISP_V_SIZE, sizeof(MS_U16));
4705 pInfo->u16HSize = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DISP_H_SIZE, sizeof(MS_U16));
4706 pInfo->u16VOffset = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CENTRE_V_OFFSET, sizeof(MS_U16));
4707 pInfo->u16HOffset = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CENTRE_H_OFFSET, sizeof(MS_U16));
4708 }
4709
HAL_MVD_GetFrmInfo(MS_U8 u8Idx,MVD_FrmInfoType eType,MVD_FrmInfo * pInfo)4710 E_MVD_Result HAL_MVD_GetFrmInfo(MS_U8 u8Idx, MVD_FrmInfoType eType, MVD_FrmInfo* pInfo)
4711 {
4712 MS_U32 u32Id = MVD_GetStreamId(u8Idx);
4713 MS_U8 u8VPUIdx = HAL_VPU_EX_GetTaskId(u32Id);
4714 E_MVD_Result eRet = E_MVD_RET_OK;
4715 MS_VIRT u32DecFrmInfoAdd = GET_DECFRMINFO_BUFFADD(u8Idx);
4716 #if v3_temp
4717 MVD_MEMCfg* pstMemCfg = NULL;
4718 pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
4719 #endif
4720 if (NULL == pInfo)
4721 {
4722 MVD_DEBUGERROR(printf("GetFrmInfo NULL pInfo!\n"));
4723 return E_MVD_RET_INVALID_PARAM;
4724 }
4725 if (NULL == u32DecFrmInfoAdd)
4726 {
4727 MVD_DEBUGERROR(printf("GetFrmInfo NULL u32DecFrmInfoAdd!\n"));
4728 return E_MVD_RET_FAIL;
4729 }
4730 //printf("%s u32DecFrmInfoAdd = 0x%x\n", __FUNCTION__, u32DecFrmInfoAdd);
4731
4732 if (E_MVD_FRMINFO_DECODE == eType)
4733 {
4734 pInfo->u32LumaAddr = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_LUMAADDR);
4735 pInfo->u32ChromaAddr= HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_CHROMAADDR);
4736 pInfo->u32TimeStamp = _90K_TO_MS(HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_TIMESTAMP));
4737 pInfo->u32ID_L = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_ID_L);
4738 pInfo->u32ID_H = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_ID_H);
4739 pInfo->u16Pitch = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_PITCH);
4740 pInfo->u16Width = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_WIDTH);
4741 pInfo->u16Height= HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_HEIGHT);
4742 pInfo->eFrmType = (MVD_PicType)HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_FRAMETYPE);
4743 }
4744 else if (E_MVD_FRMINFO_DISPLAY == eType)
4745 {
4746 pInfo->u32LumaAddr = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_LUMAADDR);
4747 pInfo->u32ChromaAddr= HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_CHROMAADDR);
4748 pInfo->u32TimeStamp = _90K_TO_MS(HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_TIMESTAMP));
4749 pInfo->u32ID_L = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_ID_L);
4750 pInfo->u32ID_H = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_ID_H);
4751 pInfo->u16Pitch = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_PITCH);
4752 pInfo->u16Width = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_WIDTH);
4753 pInfo->u16Height= HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_HEIGHT);
4754 pInfo->eFrmType = (MVD_PicType)HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_FRAMETYPE);
4755 }
4756
4757 else if (E_MVD_FRMINFO_NEXT_DISPLAY == eType)
4758 {
4759 #if v3_temp
4760 DISPQ_IN_DRAM* pTemp = (DISPQ_IN_DRAM*)(MS_PA2KSEG1(pstMemCfg->u32FWCodeAddr+DISP_QUEUE_START+ u8VPUIdx*0x100000));
4761 if (pTemp->dispQ_rd == pTemp->dispQ_wr)
4762 {
4763 MVD_DEBUGINFO(printf("NextDispFrm not ready!\n"));
4764 return E_MVD_RET_FAIL;
4765 }
4766 pInfo->u16FrmIdx = pTemp->disp_info[pTemp->dispQ_rd].u16NextDispFrameIdx;
4767
4768 pInfo->u32LumaAddr = pTemp->disp_info[pTemp->dispQ_rd].u32NextDispLumaAddr;
4769
4770 pInfo->u32ChromaAddr= pTemp->disp_info[pTemp->dispQ_rd].u32NextDispChromaAddr;
4771 // 64BIT_PTS = (TimeStamp | (ID_H<<32)) , unit: 90K
4772 pInfo->u32TimeStamp = pTemp->disp_info[pTemp->dispQ_rd].u32NextDispTimeStamp;
4773
4774 pInfo->u32ID_H = pTemp->disp_info[pTemp->dispQ_rd].u32NextDispID_H;
4775
4776 pInfo->u16Width = pTemp->disp_info[pTemp->dispQ_rd].u16NextDispWidth;
4777
4778 if(HAL_MVD_IsMcuMode(u8Idx))
4779 {
4780 //bit[19-20] Picture format,
4781 //bit[18-17] Disp times, 1~3
4782 //bit[16] Top field first , 0-> bottom first, 1-> top first
4783 //bit[15:8] Range reduction of luma data
4784 //bit[7:0] Range reduction of chroma data
4785 pInfo->u32ID_L = (MS_U32)pTemp->disp_info[pTemp->dispQ_rd].u8NextDispRangeRed_UV
4786 | (MS_U32)(pTemp->disp_info[pTemp->dispQ_rd].u8NextDispRangeRed_Y << 8)
4787 | (MS_U32)(pTemp->disp_info[pTemp->dispQ_rd].u16ExtData << 16)
4788 | (MS_U32)(pTemp->disp_info[pTemp->dispQ_rd].u8Progressive << 19);
4789
4790 if (pInfo->u16Width & MVD_WIDTH_ALIGN_MASK)
4791 {
4792 pInfo->u16Width = ((pInfo->u16Width >> MVD_WIDTH_ALIGN_BITS) + 1) << MVD_WIDTH_ALIGN_BITS;
4793 }
4794 }
4795 else
4796 {
4797 pInfo->u32ID_L = pTemp->disp_info[pTemp->dispQ_rd].u32DispID_L;
4798 }
4799 pInfo->u16Pitch = pTemp->disp_info[pTemp->dispQ_rd].u16NextDispPitch;
4800 pInfo->u16Height= pTemp->disp_info[pTemp->dispQ_rd].u16NextDispHeight;
4801 pInfo->eFrmType = pTemp->disp_info[pTemp->dispQ_rd].u16NextDispeFrameType;
4802
4803 pTemp->bUsedByOutside[pInfo->u16FrmIdx]++;
4804
4805 pTemp->dispQ_rd = (pTemp->dispQ_rd+1)%DISPQ_SIZE;
4806 MsOS_FlushMemory();
4807 #else
4808 if (!MVD_IsNextDispFrmRdy(u8Idx))
4809 {
4810 MVD_DEBUGINFO(printf("NextDispFrm not ready!\n"));
4811 return E_MVD_RET_FAIL;
4812 }
4813 pInfo->u16FrmIdx= HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_FRAMEIDX);
4814 if (pInfo->u16FrmIdx == 0xFFFF)
4815 {
4816 MVD_DEBUGINFO(printf("GetFrmInfo no available frame!\n"));
4817 return E_MVD_RET_FAIL;
4818 }
4819 pInfo->u32LumaAddr = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_LUMAADDR);
4820 pInfo->u32ChromaAddr= HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_CHROMAADDR);
4821 // 64BIT_PTS = (TimeStamp | (ID_H<<32)) , unit: 90K
4822 pInfo->u32TimeStamp = (HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_TIMESTAMP));
4823 pInfo->u32ID_H = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_ID_H);
4824 pInfo->u16Width = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_WIDTH);
4825 if(HAL_MVD_IsMcuMode(u8Idx))
4826 {
4827 //bit[18-17] Disp times, 1~3
4828 //bit[16] Top field first , 0-> bottom first, 1-> top first
4829 //bit[15:8] Range reduction of luma data
4830 //bit[7:0] Range reduction of chroma data
4831 pInfo->u32ID_L = (MS_U32)HAL_MVD_MemReadByte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_RANGERED_UV)
4832 | (MS_U32)(HAL_MVD_MemReadByte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_RANGERED_Y) << 8)
4833 | (MS_U32)(HAL_MVD_MemReadByte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_EXT_DATA) << 16);
4834 if (pInfo->u16Width & MVD_WIDTH_ALIGN_MASK)
4835 {
4836 pInfo->u16Width = ((pInfo->u16Width >> MVD_WIDTH_ALIGN_BITS) + 1) << MVD_WIDTH_ALIGN_BITS;
4837 }
4838 }
4839 else
4840 {
4841 pInfo->u32ID_L = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_ID_L);
4842 }
4843 pInfo->u16Pitch = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_PITCH);
4844 pInfo->u16Height= HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_HEIGHT);
4845 pInfo->eFrmType = (MVD_PicType)HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_FRAMETYPE);
4846 #endif
4847 #if 0
4848 printf("NxtFrm:: Idx=0x%x, ", pInfo->u16FrmIdx);
4849 printf("Type=0x%x, ", pInfo->eFrmType );
4850 printf("Luma=0x%x, ", pInfo->u32LumaAddr );
4851 printf("Chroma=0x%x, ", pInfo->u32ChromaAddr);
4852 printf("Pts=%lu, ", pInfo->u32TimeStamp );
4853 printf("ID_H=%lu, ", pInfo->u32ID_H );
4854 printf("ID_L=0x%x\n", pInfo->u32ID_L );
4855 #endif
4856 MVD_DBG_STS(printf("<<< drvMVD pts,idH = %lu, %lu\n", pInfo->u32TimeStamp, pInfo->u32ID_H));
4857 }
4858 else
4859 {
4860 eRet = E_MVD_RET_INVALID_PARAM;
4861 }
4862
4863 if ((pInfo->u32LumaAddr == _INIT_ADDR) || (pInfo->u32ChromaAddr== _INIT_ADDR) ||
4864 (pInfo->u16Pitch == _INIT_LEN) || (pInfo->u16Width == _INIT_LEN) ||
4865 (pInfo->u16Height== _INIT_LEN))
4866 {
4867 MVD_DEBUGINFO(printf("GetFrmInfo not ready!\n"));
4868 return E_MVD_RET_FAIL;
4869 }
4870
4871 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,(pInfo->u32LumaAddr * 8),pInfo->u32LumaAddr);
4872 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,(pInfo->u32ChromaAddr * 8),pInfo->u32ChromaAddr);
4873
4874 //printf("===> Luma=0x%x, Chroma=0x%x\n", pInfo->u32LumaAddr, pInfo->u32ChromaAddr);
4875 return eRet;
4876 }
4877
4878
4879
HAL_MVD_SetDynScalingParam(MS_U8 u8Idx,MS_PHY u32StAddr,MS_SIZE u32Size)4880 E_MVD_Result HAL_MVD_SetDynScalingParam(MS_U8 u8Idx, MS_PHY u32StAddr, MS_SIZE u32Size)
4881 {
4882 #define SCALER_INFO_TIMEOUT 0x1000
4883 MS_U32 u32TimeOut = 0;
4884 MS_VIRT u32SrcAdd = NULL;
4885 MS_U32 i;
4886 MS_VIRT u32ScalerInfoAdd = GET_XCINFO_BUFFADD(u8Idx);
4887 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
4888
4889 if ((u32StAddr==NULL) || (u32Size==0) || (u32Size>MVD_FW_SCALER_INFO_BUF_LEN))
4890 {
4891 MVD_DEBUGERROR(printf("%s invalid para u32StAddr=0x%lx, u32Size=0x%lx\n",
4892 __FUNCTION__, (unsigned long)u32StAddr, (unsigned long)u32Size));
4893 return E_MVD_RET_INVALID_PARAM;
4894 }
4895 if (TRUE != pstMemCfg->bEnableDynScale)
4896 {
4897 MVD_DEBUGERROR(printf("%s !bEnableDynScale\n", __FUNCTION__));
4898 return E_MVD_RET_FAIL;
4899 }
4900
4901 //copy data
4902 u32SrcAdd = HAL_MVD_PA2NonCacheSeg(u32StAddr);
4903 u32Size = ((u32Size+3)>>2)<<2;
4904 MVD_DEBUGINFO(printf("u32Size= 0x%lx, u32SrcAdd= 0x%lx\n", (unsigned long)u32Size, (unsigned long)u32SrcAdd));
4905 for (i=0; i<u32Size; i=i+4)
4906 {
4907 HAL_MVD_MemWrite4Byte(u32ScalerInfoAdd+i, *(volatile MS_U32*)(u32SrcAdd+i));
4908 MVD_DEBUGINFO(printf("0x%lx = 0x%x\n", (unsigned long)(u32ScalerInfoAdd+i), HAL_MVD_MemRead4Byte(u32ScalerInfoAdd+i)));
4909 }
4910
4911 //notify f/w
4912 HAL_MVD_ResetHandShake(u8Idx, MVD_HANDSHAKE_SCALER_INFO);
4913 if (TRUE!=HAL_MVD_SetScalerInfoAddr(u8Idx, u32ScalerInfoAdd,((MS_U8*)u32SrcAdd)[0])) //Set the buffer address (MIU offset) to f/w
4914 {
4915 MVD_DEBUGERROR(printf("%s fail to set ScalerInfoAdd\n", __FUNCTION__));
4916 return E_MVD_RET_FAIL;
4917 }
4918
4919 //check f/w already handle the data
4920 while((TRUE!=HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_SCALER_INFO)) && (u32TimeOut < SCALER_INFO_TIMEOUT))
4921 {
4922 u32TimeOut++;
4923 }
4924 if(u32TimeOut >= SCALER_INFO_TIMEOUT)
4925 {
4926 MVD_DEBUGERROR(printf("%s timeout!!!\n", __FUNCTION__));
4927 return E_MVD_RET_FAIL;
4928 }
4929
4930 //clear ack bit
4931 HAL_MVD_ClearCmdFinished(u8Idx, MVD_HANDSHAKE_SCALER_INFO);
4932
4933 MVD_DEBUGINFO(printf("=====> %s u32TimeOut = 0x%x\n", __FUNCTION__, u32TimeOut));
4934 return E_MVD_RET_OK;
4935 }
4936
4937 //Map driver CodecType to firmware CodecType
MVD_MapCodecType(MVD_CodecType type)4938 static MS_U8 MVD_MapCodecType(MVD_CodecType type)
4939 {
4940 MS_U8 u8type = 0xff;
4941 switch (type)
4942 {
4943 case E_MVD_CODEC_MPEG2:
4944 u8type = CODEC_MPEG2;
4945 break;
4946 case E_MVD_CODEC_MPEG4:
4947 u8type = CODEC_MPEG4;
4948 break;
4949 case E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER:
4950 u8type = CODEC_MPEG4_SHORT_VIDEO_HEADER;
4951 break;
4952 case E_MVD_CODEC_DIVX311:
4953 u8type = CODEC_DIVX311;
4954 break;
4955
4956 case E_MVD_CODEC_FLV:
4957 u8type = 0x03;
4958 break;
4959
4960 case E_MVD_CODEC_VC1_MAIN: //RCV
4961 u8type = 0x05;
4962 break;
4963
4964 case E_MVD_CODEC_VC1_ADV: //VC1
4965 u8type = 0x04;
4966 break;
4967
4968 default:
4969 break;
4970 }
4971
4972 return u8type;
4973 }
4974
4975 //Map driver SrcType to firmware SrcType
MVD_MapSrcMode(MVD_SrcMode mode)4976 static MS_U8 MVD_MapSrcMode(MVD_SrcMode mode)
4977 {
4978 MS_U8 u8mode = 0xff;
4979 switch (mode)
4980 {
4981 case E_MVD_TS_MODE:
4982 u8mode = STREAM_MODE;
4983 break;
4984 case E_MVD_FILE_MODE:
4985 u8mode = FILE_MODE;
4986 break;
4987 case E_MVD_SLQ_MODE:
4988 u8mode = SLQ_MODE;
4989 break;
4990 case E_MVD_SLQ_TBL_MODE:
4991 u8mode = SLQ_TBL_MODE;
4992 break;
4993 case E_MVD_TS_FILE_MODE:
4994 u8mode = TS_FILE_MODE;
4995 break;
4996
4997 default:
4998 break;
4999 }
5000
5001 return u8mode;
5002 }
5003
5004
MVD_CheckFrmBuffSizeMin(MVD_FWCfg * fwCfg,MVD_MEMCfg * memCfg)5005 static MS_BOOL MVD_CheckFrmBuffSizeMin(MVD_FWCfg* fwCfg, MVD_MEMCfg* memCfg)
5006 {
5007 MS_BOOL ret = TRUE;
5008
5009 if (_IS_VC1(fwCfg->eCodecType))
5010 {
5011 MVD_DEBUGERROR(printf("Framebuffer size(0x%lx) < (0x%x+0x%lx)!\n",
5012 (unsigned long)memCfg->u32FBSize, (MVD_HD_FBSIZE*MVD_FBNUM_MIN), MVD_HW_BUF_TOTAL_LEN));
5013 ret = FALSE;
5014 }
5015 else if (memCfg->u32FBSize < (MVD4_MPEG_FBSIZE_SDMIN+MVD_HW_BUF_TOTAL_LEN))
5016 {
5017 MVD_DEBUGERROR(printf("Framebuffer size(0x%lx) < (0x%x+0x%lx)\n",
5018 (unsigned long)memCfg->u32FBSize, MVD4_MPEG_FBSIZE_SDMIN, MVD_HW_BUF_TOTAL_LEN));
5019 ret = FALSE;
5020 }
5021 return ret;
5022 }
5023
MVD_GetUsedFrmBuffSize(MS_U8 u8FBMode,MS_U8 u8FBNum)5024 MS_U32 MVD_GetUsedFrmBuffSize(MS_U8 u8FBMode, MS_U8 u8FBNum)
5025 {
5026 MS_U32 u32Size = 0;
5027 if (MVD3_DHD_MODE == u8FBMode)
5028 {
5029 u32Size = MVD_DHD_FBSIZE;
5030 if (MVD_FBNUM_MAX == u8FBNum)
5031 {
5032 u32Size *= MVD_FBNUM_MAX;
5033 }
5034 else if (MVD_FBNUM_MIN == u8FBNum)
5035 {
5036 u32Size *= MVD_FBNUM_MIN;
5037 }
5038 }
5039 else if (MVD3_HD_MODE == u8FBMode)
5040 {
5041 u32Size = MVD_HD_FBSIZE;
5042 if (MVD_FBNUM_MAX == u8FBNum)
5043 {
5044 u32Size *= MVD_FBNUM_MAX;
5045 }
5046 else if (MVD_FBNUM_MIN == u8FBNum)
5047 {
5048 u32Size *= MVD_FBNUM_MIN;
5049 }
5050 }
5051 else if (MVD3_SD_MODE == u8FBMode)
5052 {
5053 u32Size = MVD4_MPEG_FBSIZE_SDMIN;
5054 }
5055 return u32Size;
5056 }
5057
5058 //------------------------------------------------------------------------------
5059 /// Determine u8FBMode & u8FBNum according to the assigned FBSize
5060 //------------------------------------------------------------------------------
HAL_MVD_CheckFrmBuffSize(MS_U8 u8Idx,MVD_FWCfg * fwCfg,MVD_MEMCfg * memCfg)5061 MS_BOOL HAL_MVD_CheckFrmBuffSize(MS_U8 u8Idx, MVD_FWCfg* fwCfg, MVD_MEMCfg* memCfg)
5062 {
5063 MS_BOOL ret = TRUE;
5064 MS_U8* pu8FBMode = &(fwCfg->u8FBMode);
5065 MS_U8* pu8FBNum = &(fwCfg->u8FBNum);
5066 MS_U32 u32AvailFrmBuffSize = memCfg->u32FBSize - MVD_HW_BUF_TOTAL_LEN;
5067
5068 ret = MDrv_MVD_AUTH_IPCheck(fwCfg->eCodecType,&(memCfg->bSupportSDModeOnly));
5069 if(ret == FALSE)
5070 {
5071 return FALSE;
5072 }
5073
5074 *pu8FBMode = 0xff;
5075
5076 #if defined(MVD_SUPPORT_SD_ONLY)
5077 *pu8FBMode = MVD3_SD_MODE;
5078 #else
5079 if(memCfg->bSupportSDModeOnly)
5080 {
5081 *pu8FBMode = MVD3_SD_MODE;
5082 }
5083 #endif //MVD_SUPPORT_SD_ONLY
5084
5085 //For SD only cases: defined(MVD_SUPPORT_SD_ONLY) and bSupportSDModeOnly
5086 if (MVD3_SD_MODE == *pu8FBMode)
5087 {
5088 ret = MVD_CheckFrmBuffSizeMin(fwCfg, memCfg);
5089
5090 //set frmBuffNum as 4
5091 *pu8FBNum = MVD_FBNUM_MIN;
5092 MVD_DEBUGINFO(printf("[MVD_SD_MODE] u8FBNum=%d, FBSize=0x%lx\n", *pu8FBNum, (unsigned long)memCfg->u32FBSize));
5093 goto _GET_USED_SIZE;
5094 }
5095
5096 if (u32AvailFrmBuffSize >= (MVD_DHD_FBSIZE*MVD_FBNUM_MAX))
5097 {
5098 MVD_DEBUGINFO(printf("%s(%d) DHD*5\n", __FUNCTION__, __LINE__));
5099 //Dual HD: (1920*2)*1088 or 1920*(1088*2)
5100 if (!_IS_VC1(fwCfg->eCodecType)) //mpeg2/4
5101 {
5102 *pu8FBMode = MVD3_DHD_MODE;
5103 }
5104 else
5105 {
5106 *pu8FBMode = MVD3_DHD_MODE_MIN;
5107 }
5108 *pu8FBNum = MVD_FBNUM_MAX;
5109 }
5110 else if (u32AvailFrmBuffSize >= (MVD_DHD_FBSIZE*MVD_FBNUM_MIN))
5111 {
5112 MVD_DEBUGINFO(printf("%s(%d) DHD*4\n", __FUNCTION__, __LINE__));
5113 //Dual HD: (1920*2)*1088 or 1920*(1088*2)
5114 if (!_IS_VC1(fwCfg->eCodecType)) //mpeg2/4
5115 {
5116 *pu8FBMode = MVD3_DHD_MODE;
5117 }
5118 else
5119 {
5120 *pu8FBMode = MVD3_DHD_MODE_MIN;
5121 }
5122 *pu8FBNum = MVD_FBNUM_MIN;
5123 }
5124 else if (u32AvailFrmBuffSize >= (MVD_HD_FBSIZE*MVD_FBNUM_MAX))
5125 {
5126 MVD_DEBUGINFO(printf("%s(%d) HD*5\n", __FUNCTION__, __LINE__));
5127 *pu8FBMode = MVD3_HD_MODE;
5128 *pu8FBNum = MVD_FBNUM_MAX;
5129 }
5130 else if (u32AvailFrmBuffSize >= (MVD_HD_FBSIZE*MVD_FBNUM_MIN))
5131 {
5132 MVD_DEBUGINFO(printf("%s(%d) HD*4\n", __FUNCTION__, __LINE__));
5133 *pu8FBMode = MVD3_HD_MODE;
5134 *pu8FBNum = MVD_FBNUM_MIN;
5135 }
5136 else
5137 {
5138 MVD_DEBUGINFO(printf("%s(%d) SD\n", __FUNCTION__, __LINE__));
5139 ret = MVD_CheckFrmBuffSizeMin(fwCfg, memCfg);
5140 if (TRUE == ret)
5141 {
5142 *pu8FBMode = MVD3_SD_MODE;
5143 *pu8FBNum = MVD_FBNUM_MIN;
5144 MVD_DEBUGINFO(printf("Framebuffer [SD] mode\n"));
5145 }
5146 }
5147
5148
5149 //Keep FBNum=4 for mpeg2/4, not-mstreamer/uniplayer/mcu mode.
5150 if (!_IS_VC1(fwCfg->eCodecType)) //mpeg2/4
5151 {
5152 if (*pu8FBNum != MVD_FBNUM_DEFAULT)
5153 {
5154 *pu8FBNum = MVD_FBNUM_DEFAULT;
5155 }
5156 }
5157
5158 _GET_USED_SIZE:
5159 fwCfg->u32FBUsedSize = u32AvailFrmBuffSize;
5160
5161 MVD_DEBUGINFO(printf("%s u8FBMode=0x%x, u8FBNum=%d, FBSize=0x%lx, used=0x%lx\n",
5162 __FUNCTION__, fwCfg->u8FBMode, fwCfg->u8FBNum, (unsigned long)memCfg->u32FBSize, (unsigned long)fwCfg->u32FBUsedSize));
5163 return ret;
5164 }
5165
HAL_MVD_SetCodecInfo(MS_U8 u8Idx,MVD_CodecType eCodecType,MVD_SrcMode eSrcMode,MS_U8 bDisablePESParsing)5166 MS_BOOL HAL_MVD_SetCodecInfo(MS_U8 u8Idx, MVD_CodecType eCodecType, MVD_SrcMode eSrcMode, MS_U8 bDisablePESParsing)
5167 {
5168 MVD_CmdArg stCmdArg;
5169 //printf("u8CodecType=0x%x\n", u8CodecType);
5170 //printf("eSrcMode=0x%x\n", eSrcMode);
5171 SETUP_CMDARG(stCmdArg);
5172 stCmdArg.Arg0 = MVD_MapCodecType(eCodecType);
5173 stCmdArg.Arg1 = MVD_MapSrcMode(eSrcMode);
5174 stCmdArg.Arg2 = bDisablePESParsing;
5175 //arg2 is only valid for STREAM_MODE and TS_FILE_MODE
5176 //set as 0 to enable MVD parser and parser interrupt
5177 stCmdArg.Arg3 = 0;
5178 MVD_DEBUGINFO(printf("MDrv_MVD_SetCodecInfo: Cmd: %x, Arg0: %x, Arg1: %x. Arg2: %x\n",
5179 CMD_CODEC_INFO, stCmdArg.Arg0, stCmdArg.Arg1, stCmdArg.Arg2));
5180 SET_DECNUM(stCmdArg, u8Idx);
5181 SET_CMD_RET_FALSE(CMD_CODEC_INFO, &stCmdArg);
5182
5183 HAL_MVD_SetSrcMode(u8Idx,eSrcMode);
5184
5185 //set code offset to MVD
5186 MS_VIRT u32Addr, u32Len;
5187 HAL_MVD_MemGetMap(u8Idx, E_MVD_MMAP_FW, &u32Addr, &u32Len);
5188
5189 if (u32Len==0) printf("%s err: u32Len=0!\n", __FUNCTION__);
5190 MS_U32 i=0;
5191 i = u32Addr >> 3;
5192 SET_CMDARG(stCmdArg, i, u8Idx);
5193 SET_CMD_RET_FALSE(CMD_CODE_OFFSET, &stCmdArg);
5194
5195 #define _mvdAssert(x) if(!x) printf("%s(%d) inconsistent cfg!\n", __FUNCTION__, __LINE__);
5196 MVD_FWCfg* pCurFwCfg = HAL_MVD_GetFWCfg(u8Idx);
5197 _mvdAssert(pCurFwCfg->eCodecType == eCodecType);
5198 _mvdAssert(pCurFwCfg->eSrcMode == eSrcMode);
5199 _mvdAssert(pCurFwCfg->bDisablePESParsing == bDisablePESParsing);
5200
5201 //Refer to msAPI_VDPlayer_DecodeMPEG4.c (core\kernel\api\videoplayer)
5202 if (eSrcMode == E_MVD_SLQ_TBL_MODE)
5203 {
5204 if ((eCodecType == E_MVD_CODEC_MPEG4) ||
5205 (eCodecType == E_MVD_CODEC_DIVX311) ||
5206 (eCodecType == E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER))
5207 {
5208 // Enable PackMode
5209 SETUP_CMDARG(stCmdArg);
5210 stCmdArg.Arg0 = 3;
5211 SET_DECNUM(stCmdArg, u8Idx);
5212 if (HAL_MVD_MVDCommand( CMD_PARSE_M4V_PACKMD, &stCmdArg ) == FALSE)
5213 {
5214 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PARSE_M4V_PACKMD ) );
5215 return FALSE;
5216 }
5217
5218 // Set DIU width of rounding mode (align to 8byte)
5219 SETUP_CMDARG(stCmdArg);
5220 stCmdArg.Arg0 = 1;
5221 SET_DECNUM(stCmdArg, u8Idx);
5222 if (HAL_MVD_MVDCommand(CMD_DIU_WIDTH_ALIGN, &stCmdArg) == FALSE)
5223 {
5224 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DIU_WIDTH_ALIGN ) );
5225 return FALSE;
5226 }
5227 }
5228 }
5229
5230 //set internal buffers after setting codecinfo for V3
5231 if (!HAL_MVD_SetInternalBuffAddr(u8Idx, u32Addr, u32Len))
5232 {
5233 MVD_DEBUGERROR(printf("MDrv_MVD_Init:_MVD_MVDSetInternalBuffAddr failed\n"));
5234 return FALSE;
5235 }
5236 else
5237 {
5238 MVD_DEBUGINFO(printf("MDrv_MVD_Init:_MVD_MVDSetInternalBuffAddr success\n"));
5239 }
5240
5241 return TRUE;
5242 }
5243
MVD_GetBDMAType(void)5244 BDMA_CpyType MVD_GetBDMAType(void)
5245 {
5246 BDMA_CpyType bdmaCpyType = E_BDMA_CPYTYPE_MAX;
5247
5248 if (pMVDHalContext->stMiuCfg.u8HWMiuSel == MIU_SEL_0)
5249 {
5250 if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_0)
5251 {
5252 bdmaCpyType = E_BDMA_SDRAM2SDRAM;
5253 }
5254 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_1)
5255 {
5256 bdmaCpyType = E_BDMA_SDRAM2SDRAM1;
5257 }
5258 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_2)
5259 {
5260 bdmaCpyType = E_BDMA_SDRAM2SDRAM2;
5261 }
5262 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_3)
5263 {
5264 bdmaCpyType = E_BDMA_SDRAM2SDRAM3;
5265 }
5266 else
5267 {
5268 MS_ASSERT(0);
5269 }
5270 }
5271 else if (pMVDHalContext->stMiuCfg.u8HWMiuSel == MIU_SEL_1)
5272 {
5273 if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_0)
5274 {
5275 bdmaCpyType = E_BDMA_SDRAM12SDRAM;
5276 }
5277 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_1)
5278 {
5279 bdmaCpyType = E_BDMA_SDRAM12SDRAM1;
5280 }
5281 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_2)
5282 {
5283 bdmaCpyType = E_BDMA_SDRAM12SDRAM2;
5284 }
5285 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_3)
5286 {
5287 bdmaCpyType = E_BDMA_SDRAM12SDRAM3;
5288 }
5289 else
5290 {
5291 MS_ASSERT(0);
5292 }
5293 }
5294 else if (pMVDHalContext->stMiuCfg.u8HWMiuSel == MIU_SEL_2)
5295 {
5296 if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_0)
5297 {
5298 bdmaCpyType = E_BDMA_SDRAM22SDRAM;
5299 }
5300 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_1)
5301 {
5302 bdmaCpyType = E_BDMA_SDRAM22SDRAM1;
5303 }
5304 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_2)
5305 {
5306 bdmaCpyType = E_BDMA_SDRAM22SDRAM2;
5307 }
5308 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_3)
5309 {
5310 bdmaCpyType = E_BDMA_SDRAM22SDRAM3;
5311 }
5312 else
5313 {
5314 MS_ASSERT(0);
5315 }
5316 }
5317 else if (pMVDHalContext->stMiuCfg.u8HWMiuSel == MIU_SEL_3)
5318 {
5319 if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_0)
5320 {
5321 bdmaCpyType = E_BDMA_SDRAM32SDRAM;
5322 }
5323 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_1)
5324 {
5325 bdmaCpyType = E_BDMA_SDRAM32SDRAM1;
5326 }
5327 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_2)
5328 {
5329 bdmaCpyType = E_BDMA_SDRAM32SDRAM2;
5330 }
5331 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_3)
5332 {
5333 bdmaCpyType = E_BDMA_SDRAM32SDRAM3;
5334 }
5335 else
5336 {
5337 MS_ASSERT(0);
5338 }
5339 }
5340 else
5341 {
5342 MS_ASSERT(0);
5343 }
5344
5345 return bdmaCpyType;
5346 }
5347
5348 //Init static variables.
5349 //Exception: stMemCfg & stMiuCfg since they are set before calling this function.
HAL_MVD_InitVar(MS_U8 u8Idx)5350 void HAL_MVD_InitVar(MS_U8 u8Idx)
5351 {
5352 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
5353 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
5354
5355 memset(pstCtrlCfg, 0, sizeof(MVD_CtrlCfg));
5356 pstCtrlCfg->eTrickMode = E_MVD_TRICK_DEC_ALL;
5357 pstCtrlCfg->eFrcMode = E_MVD_FRC_NORMAL;
5358 pstCtrlCfg->ePreSpeedType = E_MVD_SPEED_DEFAULT;
5359 pstCtrlCfg->eFileSyncMode = E_MVD_TIMESTAMP_FREERUN;
5360
5361 //determine if we need to BDMA SLQ table from DrvProcBuff to BitstreamBuff
5362 #ifndef MSOS_TYPE_LINUX_KERNEL//BDMA
5363 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
5364 pstCtrlCfg->bSlqTblSync = ((pstMemCfg->u32DrvBufAddr < pstMemCfg->u32BSAddr) ||
5365 ((pstMemCfg->u32DrvBufAddr+pstMemCfg->u32DrvBufSize) > (pstMemCfg->u32BSAddr+pstMemCfg->u32BSSize)));
5366 MVD_DEBUGINFO(printf("bSlqTblSync = %x\n", pstCtrlCfg->bSlqTblSync));
5367 if (pstCtrlCfg->bSlqTblSync)
5368 {
5369 const BDMA_Info* pBDMA;
5370 pBDMA = MDrv_BDMA_GetInfo();
5371 if ((pBDMA == NULL) || (pBDMA->bInit != TRUE))
5372 {
5373 if (E_BDMA_OK != MDrv_BDMA_Init(pstMemCfg->u32Miu1BaseAddr))
5374 {
5375 printf("%s fail at MDrv_BDMA_Init!!!\n", __FUNCTION__);
5376 }
5377 }
5378 pstSlqTblInfo->bdmaCpyType = MVD_GetBDMAType();
5379 }
5380 #else
5381 pstCtrlCfg->bSlqTblSync = 0;
5382 #endif
5383 memset(pstSlqTblInfo, 0, sizeof(MVD_SLQTBLInfo));
5384 pstSlqTblInfo->u32LastPts = MVD_NULLPKT_PTS;
5385 pstSlqTblInfo->u32PreEsRd = MVD_U32_MAX;
5386 pstSlqTblInfo->u32PreEsWr = 0;
5387 pstSlqTblInfo->pSlqStatus = &(pMVDHalContext->_SlqStatus[u8Idx]);
5388 pstSlqTblInfo->pDrvSlqTbl = &(pMVDHalContext->_drvSlqTbl[u8Idx]);
5389 pstSlqTblInfo->pDrvEsTbl = &(pMVDHalContext->_drvEsTbl[u8Idx]);
5390 pstSlqTblInfo->pDrvDivxTbl = &(pMVDHalContext->_drvDivxTbl[u8Idx]);
5391 #if SLQ_NEW_PUSH
5392 pstSlqTblInfo->pSlqStatus->u32SlqPatternAddr = 0;
5393 pstSlqTblInfo->pSlqStatus->u32SlqPushLength = 0;
5394 pstSlqTblInfo->pSlqStatus->bSlqPicStart = FALSE;
5395 pstSlqTblInfo->pSlqStatus->bSlqPicCollect = FALSE;
5396 pstSlqTblInfo->pSlqStatus->bSlqPicWaitNextStart = FALSE;
5397 pstSlqTblInfo->pSlqStatus->bSlqEnLastFrameShow =FALSE;
5398 pstSlqTblInfo->pSlqStatus->bSlqFireRdy = FALSE;
5399 pstSlqTblInfo->pSlqStatus->bSlqCtrlBit =FALSE;
5400 #endif
5401 }
5402
5403 //------------------------------------------------------------------------------
5404 /// Issue Stop command.
5405 //------------------------------------------------------------------------------
HAL_MVD_Stop(MS_U8 u8Idx)5406 MS_BOOL HAL_MVD_Stop(MS_U8 u8Idx)
5407 {
5408 MVD_CmdArg mvdcmd;
5409 MS_BOOL bRet = TRUE;
5410
5411 #define STOP_TIMEOUT 500 //ms
5412 MS_U32 u32StartTime = 0;
5413 u32StartTime = HAL_MVD_GetTime();
5414
5415 SETUP_CMDARG(mvdcmd);
5416 SET_DECNUM(mvdcmd, u8Idx);
5417 HAL_MVD_ResetHandShake(u8Idx, MVD_HANDSHAKE_STOP);
5418
5419 if (HAL_MVD_MVDCommand(CMD_STOP, &mvdcmd) == FALSE)
5420 {
5421 MVD_DEBUGERROR(printf("Command: 0x%x fail!!\r\n", CMD_STOP));
5422 HAL_MVD_Delayms(1);
5423 if ( HAL_MVD_TimeOut(u8Idx) == TRUE )
5424 {
5425 MVD_DEBUGERROR(printf("*** MVD ERR: STOP TIMEOUT!!! ***\n"));
5426 }
5427 }
5428
5429 while(!HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_STOP))
5430 {
5431 if ((HAL_MVD_GetTime()-u32StartTime)>STOP_TIMEOUT)
5432 {
5433 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail timeout!!\r\n", CMD_STOP ) );
5434 break;
5435 }
5436 }
5437
5438 pMVDHalContext->bStopped[u8Idx] = TRUE;
5439 return bRet;
5440 }
5441
HAL_MVD_DeinitHW(VPU_EX_SourceType SourceType,VPU_EX_DecoderType eDecType)5442 MS_BOOL HAL_MVD_DeinitHW(VPU_EX_SourceType SourceType, VPU_EX_DecoderType eDecType)
5443 {
5444 //MVD HW reset
5445 if (!HAL_MVD_RstHW())
5446 {
5447 MVD_DEBUGERROR(printf("MDrv_MVD_Exit:MVD4ResetHW failed\n"));
5448 }
5449 else
5450 {
5451 MVD_DEBUGINFO(printf("MDrv_MVD_Exit:MVD4ResetHW success\n"));
5452 }
5453 HAL_MVD_PowerCtrl(DISABLE);
5454 #ifdef CONFIG_MSTAR_CLKM
5455 if(eDecType == E_VPU_EX_DECODER_MVD)
5456 {
5457 HAL_VPU_EX_SetClkManagement(E_VPU_EX_CLKPORT_MVD_CORE, DISABLE);
5458 }
5459 if(SourceType == E_VPU_EX_INPUT_TSP)
5460 {
5461 HAL_VPU_EX_SetClkManagement(E_VPU_EX_CLKPORT_MVD_PAS, DISABLE);
5462 }
5463 #endif
5464
5465 #ifdef CONFIG_MSTAR_SRAMPD
5466 HAL_MVD_RegWriteBit(REG_CODEC_SRAM_SD_EN, DISABLE, SRAM_SD_EN_MVD);
5467 HAL_MVD_Delayms(1);
5468 #endif
5469 return TRUE;
5470 }
5471
HAL_MVD_Exit(MS_U8 u8Idx)5472 MS_BOOL HAL_MVD_Exit(MS_U8 u8Idx)
5473 {
5474 MVD_DEBUGINFO(printf("MDrv_MVD_Exit:start\n"));
5475
5476 HAL_MVD_SetIsUsed(u8Idx, FALSE);
5477 pMVDHalContext->bAutoInsertDummyPattern[u8Idx] = FALSE;
5478 pMVDHalContext->bDropOnePTS[u8Idx] = FALSE;
5479 pMVDHalContext->u32DmxFrameRate[u8Idx] = 0;
5480 pMVDHalContext->u32DmxFrameRateBase[u8Idx] = 0;
5481 pMVDHalContext->bTrickPlay2xAVSync[u8Idx] = FALSE;
5482
5483 return TRUE;
5484 }
5485
5486
5487 //------------------------------------------------------------------------------
5488 /// Set DivX311 stream info.
5489 /// @param divxInfo \b IN : DivX311 stream info.
5490 //------------------------------------------------------------------------------
MVD_WriteDivx311Data(MS_U8 u8Idx,FW_DIVX_INFO * divxInfo)5491 static void MVD_WriteDivx311Data(MS_U8 u8Idx, FW_DIVX_INFO *divxInfo)
5492 {
5493 MS_VIRT pu8MVDSetHeaderBufStart = GET_HDR_BUFFADD(u8Idx);
5494 HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_VOL_HANDLE_DONE,divxInfo->vol_handle_done);
5495 HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_WIDTH,divxInfo->width);
5496 HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_HEIGHT,divxInfo->height);
5497 HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_FRAME_COUNT,divxInfo->frame_count);
5498 HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_FRAME_TIME,divxInfo->frame_time);
5499 HAL_MVD_MemWrite2Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_PTS_INCR,divxInfo->pts_incr);
5500 HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_FRAME_RATE,divxInfo->frame_rate);
5501 HAL_MVD_MemWriteByte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_ASPECT_RATIO,divxInfo->aspect_ratio);
5502 HAL_MVD_MemWriteByte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_PROGRESSIVE_SEQUENCE,divxInfo->progressive_sequence);
5503 HAL_MVD_MemWriteByte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_MPEG1,divxInfo->mpeg1);
5504 HAL_MVD_MemWriteByte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_PLAY_MODE,divxInfo->play_mode);
5505 HAL_MVD_MemWriteByte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_MPEG_FRC_MODE,divxInfo->mpeg_frc_mode);
5506 return;
5507 }
5508
HAL_MVD_SetFrameInfo(MS_U8 u8Idx,MVD_FrameInfo * pinfo)5509 void HAL_MVD_SetFrameInfo(MS_U8 u8Idx, MVD_FrameInfo *pinfo )
5510 {
5511 if (GET_HDR_BUFFADD(u8Idx)==0)
5512 {
5513 MVD_DEBUGERROR(printf("MDrv_MVD_SetFrameInfo error: pu8MVDSetHeaderBufStart=NULL\n"));
5514 return;
5515 }
5516
5517 FW_DIVX_INFO* pDivxInfo = &(pMVDHalContext->gdivxInfo[u8Idx]);
5518 pDivxInfo->width=pinfo->u16HorSize;
5519 pDivxInfo->height=pinfo->u16VerSize;
5520 pDivxInfo->aspect_ratio=pinfo->u8AspectRate;
5521 pDivxInfo->frame_rate = pinfo->u32FrameRate;
5522
5523 //for MM
5524 pDivxInfo->mpeg1=pinfo->u8MPEG1;
5525 pDivxInfo->pts_incr=pinfo->u16PTSInterval;
5526 pDivxInfo->play_mode=pinfo->u8PlayMode;
5527 pDivxInfo->mpeg_frc_mode=pinfo->u8FrcMode;
5528
5529 if(pinfo->u8Interlace==0)
5530 pDivxInfo->progressive_sequence=1;
5531 else
5532 pDivxInfo->progressive_sequence=0;
5533
5534 pDivxInfo->frame_count=0;
5535 pDivxInfo->frame_time=0;
5536 pDivxInfo->vol_handle_done=0;
5537 // pDivxInfo->invalidstream=0;
5538 MVD_DEBUGINFO(printf("set vol info,pts_incr=%d,\n",pDivxInfo->pts_incr));
5539 MVD_DEBUGINFO(printf("set vol info,width=%x,height=%x,frame_rate=%d,aspect_ratio=%x,\n",
5540 (unsigned int)pDivxInfo->width,(unsigned int)pDivxInfo->height,pDivxInfo->frame_rate,pDivxInfo->aspect_ratio));
5541 MVD_DEBUGINFO(printf("set vol info,progressive_sequence=%x,mpeg1=%x,play_mode=%x,\n",
5542 pDivxInfo->progressive_sequence,pDivxInfo->mpeg1,pDivxInfo->play_mode));
5543
5544 MVD_WriteDivx311Data(u8Idx, pDivxInfo);
5545 return;
5546 }
5547
5548
5549
5550 ///////////////////////////////////////////////////////////////////////////////
5551 /// Get Hardware Pointer of MVD CC Ring Buffer
5552 /// Return value:: The HW Pointer Address of MVD CC Ring Buffer
5553 /// @param u8CC608 \b IN
5554 /// - # TRUE for CC608 parser
5555 /// - # FALSE for CC708 parser
5556 ///////////////////////////////////////////////////////////////////////////////
HAL_CC_CM_GetMVDRB_HWAddr(MS_U8 u8CC608)5557 MS_VIRT HAL_CC_CM_GetMVDRB_HWAddr(MS_U8 u8CC608)
5558 {
5559 #if 1
5560 MVD_CmdArg mvdcmd;
5561 MS_VIRT u32CCWrPtr = 0;
5562
5563 SETUP_CMDARG(mvdcmd);
5564 mvdcmd.Arg3 = u8CC608;
5565 if (HAL_MVD_MVDCommand( CMD_RD_USER_WP, &mvdcmd ) == FALSE)
5566 {
5567 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_RD_USER_WP ) );
5568 return MVD_U32_MAX;
5569 }
5570 u32CCWrPtr = COMBU32(mvdcmd.Arg3, mvdcmd.Arg2, mvdcmd.Arg1, mvdcmd.Arg0);
5571 return u32CCWrPtr;
5572 #else
5573 MS_U32 u32MVDCC_Temp1 = 0;
5574 if (HAL_MVD_TimeOut(pstCmdArg->Arg5) == FALSE)
5575 {
5576 //HAL_MVD_ARGINIT();
5577 HAL_MVD_RegWriteByte(MVD_ARG5, 0);
5578 HAL_MVD_RegWriteByte(MVD_ARG4, 0);
5579 HAL_MVD_RegWriteByte(MVD_ARG3, (MS_U8)u8CC608);
5580 HAL_MVD_RegWriteByte(MVD_COMMAND, (MS_U8)(CMD_RD_USER_WP));//CMD_GET_CCBUF_HWADDR
5581
5582 if (HAL_MVD_TimeOut(pstCmdArg->Arg5) == FALSE)
5583 {
5584 u32MVDCC_Temp1 = 0;
5585 u32MVDCC_Temp1 = (((MS_U32)HAL_MVD_RegReadByte(MVD_ARG0)) & 0x000000FF);
5586 u32MVDCC_Temp1 += ((((MS_U32)HAL_MVD_RegReadByte(MVD_ARG1)) & 0x000000FF) << 8);
5587 u32MVDCC_Temp1 += ((((MS_U32)HAL_MVD_RegReadByte(MVD_ARG2)) & 0x000000FF) << 16);
5588 u32MVDCC_Temp1 = (u32MVDCC_Temp1 << 3);
5589 return (u32MVDCC_Temp1);
5590 }
5591 else
5592 {
5593 MVD_DEBUGINFO(printf("\nF:GHAV"));
5594 }
5595 }
5596 else
5597 {
5598 MVD_DEBUGINFO(printf("\nF:GHA"));
5599 }
5600
5601 return 0xffffffff;
5602 #endif
5603 }
5604
HAL_MVD_GetUsrDataIsAvailable(MS_U8 u8Idx)5605 MS_BOOL HAL_MVD_GetUsrDataIsAvailable(MS_U8 u8Idx)
5606 {
5607 volatile MVD_CtrlCfg* pCtrlCfg = (volatile MVD_CtrlCfg*)HAL_MVD_GetCtrlCfg(u8Idx);
5608 MS_VIRT u32UsrDataWr = 0;
5609 MS_BOOL bIsAvail = FALSE;
5610
5611 #if defined(MVD_SUPPORT_X4_CC)
5612 u32UsrDataWr = HAL_CC_CM_GetMVDRB_HWAddr(4);
5613 #else
5614 u32UsrDataWr = HAL_CC_CM_GetMVDRB_HWAddr(2);
5615 #endif
5616 bIsAvail = !(pCtrlCfg->u32UsrDataRd == u32UsrDataWr);
5617 MVD_DEBUGINFO(printf("IsAvail:%x rd=%lx wr=%lx\n", bIsAvail,
5618 (unsigned long)pCtrlCfg->u32UsrDataRd, (unsigned long)u32UsrDataWr));
5619 return bIsAvail;
5620 }
5621
5622 //------------------------------------------------------------------------------
5623 /// Get info of user data
5624 //------------------------------------------------------------------------------
HAL_MVD_GetUsrDataInfo(MS_U8 u8Idx,MVD_UsrDataInfo * pUsrInfo)5625 MS_BOOL HAL_MVD_GetUsrDataInfo(MS_U8 u8Idx, MVD_UsrDataInfo* pUsrInfo)
5626 {
5627 MS_VIRT u32UsrData = NULL;
5628 MS_VIRT u32UsrDataWr = 0;
5629 #if defined(MVD_SUPPORT_X4_CC)
5630 FW_USER_DATA_BUF_EXT stUsrDataExt;
5631 #else
5632 FW_USER_DATA_BUF stUsrDataInfo;
5633 #endif
5634 volatile MVD_CtrlCfg* pCtrlCfg = (volatile MVD_CtrlCfg*)HAL_MVD_GetCtrlCfg(u8Idx);
5635
5636 if ((!pUsrInfo) || (GET_FRMINFO_BUFFADD(u8Idx)==0))
5637 {
5638 MVD_DEBUGERROR(printf("%s: NULL ptr.\n", __FUNCTION__));
5639 return FALSE;
5640 }
5641
5642 //get write pointer
5643 #if defined(MVD_SUPPORT_X4_CC)
5644 u32UsrDataWr = HAL_CC_CM_GetMVDRB_HWAddr(4);
5645 #else
5646 u32UsrDataWr = HAL_CC_CM_GetMVDRB_HWAddr(2);
5647 #endif
5648 if (pCtrlCfg->u32UsrDataRd == (GET_USRDATA_BUFFADD(u8Idx)+MVD3_FW_USER_DATA_BUF_LEN))
5649 {
5650 pCtrlCfg->u32UsrDataRd = GET_USRDATA_BUFFADD(u8Idx); //wrap to BufStart
5651 }
5652 MVD_DEBUGINFO(printf("CC Rd=0x%lx Wr=0x%lx\n", (unsigned long)pCtrlCfg->u32UsrDataRd, (unsigned long)u32UsrDataWr));
5653
5654 if (pCtrlCfg->u32UsrDataRd == u32UsrDataWr)
5655 {
5656 MVD_DEBUGERROR(printf("%s: no data? Rd=0x%lx Wr=0x%lx\n", __FUNCTION__, (unsigned long)pCtrlCfg->u32UsrDataRd, (unsigned long)u32UsrDataWr));
5657 return FALSE;
5658 }
5659
5660 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,pCtrlCfg->u32UsrDataRd,u32UsrData);
5661
5662 u32UsrData = HAL_MVD_PA2NonCacheSeg(u32UsrData);
5663
5664 HAL_MVD_CPU_Sync();
5665 HAL_MVD_ReadMemory();
5666
5667 #if defined(MVD_SUPPORT_X4_CC)
5668 stUsrDataExt = *(volatile FW_USER_DATA_BUF_EXT*)u32UsrData;
5669
5670 pUsrInfo->u32Pts = stUsrDataExt.pts;
5671 pUsrInfo->u8PicStruct = stUsrDataExt.PicStruct;
5672 pUsrInfo->u8PicType = stUsrDataExt.picType;
5673 pUsrInfo->u8TopFieldFirst = stUsrDataExt.top_ff;
5674 pUsrInfo->u8RptFirstField = stUsrDataExt.rpt_ff;
5675 pUsrInfo->u16TmpRef = stUsrDataExt.tmpRef;
5676 pUsrInfo->u8ByteCnt = stUsrDataExt.userdatabytecnt;
5677 pUsrInfo->u32DataBuf = u32UsrData + MVD_FW_USER_DATA_EXT_HDR_LEN;
5678 #else
5679 stUsrDataInfo = *(volatile FW_USER_DATA_BUF*)u32UsrData;
5680
5681 pUsrInfo->u8PicType = stUsrDataInfo.picType;
5682 pUsrInfo->u8TopFieldFirst = stUsrDataInfo.top_ff;
5683 pUsrInfo->u8RptFirstField = stUsrDataInfo.rpt_ff;
5684 pUsrInfo->u16TmpRef = stUsrDataInfo.tmpRef;
5685 pUsrInfo->u8ByteCnt = stUsrDataInfo.userdatabytecnt;
5686 pUsrInfo->u32DataBuf = u32UsrData + MVD_FW_USER_DATA_HDR_LEN;
5687 #endif
5688 //update read pointer
5689 pCtrlCfg->u32UsrDataRd += MVD_FW_USER_DATA_PKT_LEN;
5690 #if 0
5691 printf("xxInfo: ");
5692 printf("%02d, ", pUsrInfo->u16TmpRef);
5693 printf("%d, ", pUsrInfo->u8PicStruct);
5694 printf("%d, ", pUsrInfo->u8TopFieldFirst);
5695 printf("0x%x, ", pUsrInfo->u32DataBuf);
5696 printf("%d, ", pUsrInfo->u8ByteCnt);
5697 printf("%ld, ", pUsrInfo->u32Pts);
5698 printf("%d\n", pUsrInfo->u8PicType);
5699 #endif
5700 return TRUE;
5701 }
5702
5703
HAL_MVD_Map2DrvSlqTbl(MS_U8 u8Idx,MS_VIRT u32HWPtr)5704 MS_VIRT HAL_MVD_Map2DrvSlqTbl(MS_U8 u8Idx, MS_VIRT u32HWPtr)
5705 {
5706 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
5707 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
5708 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
5709 MS_VIRT u32HWSt = HAL_MVD_GetMemOffset(pstMemCfg->u32BSAddr);
5710 MS_VIRT u32DrvPtr;
5711
5712 if ((u32HWPtr<u32HWSt) && (u32HWPtr!=0))
5713 {
5714 MVD_DEBUGERROR(printf("Invalid u32HWPtr=0x%lx\n", (unsigned long)u32HWPtr));
5715 return 0;
5716 }
5717 if ((pstCtrlCfg->bSlqTblSync) && (u32HWPtr!=0))
5718 {
5719 u32DrvPtr = pstSlqTblInfo->pDrvSlqTbl->u32StAdd + (u32HWPtr - u32HWSt);
5720 return u32DrvPtr;
5721 }
5722 return u32HWPtr;
5723 }
5724
5725
MVD_SLQTblGetFileEndPkt(MS_U8 u8Idx,MVD_PacketInfo * pFileEnd)5726 static void MVD_SLQTblGetFileEndPkt(MS_U8 u8Idx, MVD_PacketInfo* pFileEnd)
5727 {
5728 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
5729 MS_VIRT u32EndPattern = HAL_MVD_GetMemOffset(pstMemCfg->u32DrvBufAddr+SLQ_TBL_SIZE*3);
5730
5731 pFileEnd->u32StAddr = SLQ_TBL_SIZE*3;//u32EndPattern - HAL_MVD_GetMemOffset(pstMemCfg->u32DrvBufAddr);
5732 pFileEnd->u32Length = END_PATTERN_SIZE;
5733 pFileEnd->u32TimeStamp = MVD_NULLPKT_PTS;
5734 pFileEnd->u32ID_L = MVD_U32_MAX;
5735 pFileEnd->u32ID_H = MVD_U32_MAX;
5736 MVD_DEBUGINFO(printf("u32EndPattern(0x%lx)=0x%x 0x%x 0x%x 0x%x\n", (unsigned long)pFileEnd->u32StAddr,
5737 HAL_MVD_MemRead4Byte(u32EndPattern), HAL_MVD_MemRead4Byte(u32EndPattern+4),
5738 HAL_MVD_MemRead4Byte(u32EndPattern+8), HAL_MVD_MemRead4Byte(u32EndPattern+12)));
5739 }
5740
5741
MVD_SLQTblGetDummyPkt(MVD_PacketInfo * pDummy)5742 static void MVD_SLQTblGetDummyPkt(MVD_PacketInfo* pDummy)
5743 {
5744 //MS_U32 u32DummyES = HAL_MVD_GetMemOffset(pstMemCfg->u32DrvBufAddr+SLQ_TBL_SIZE*2);
5745
5746 pDummy->u32StAddr = SLQ_TBL_SIZE*2;//u32DummyES - HAL_MVD_GetMemOffset(pstMemCfg->u32DrvBufAddr);
5747 pDummy->u32Length = DUMMY_SIZE;
5748 pDummy->u32TimeStamp = MVD_NULLPKT_PTS;
5749 pDummy->u32ID_L = MVD_U32_MAX;
5750 pDummy->u32ID_H = MVD_U32_MAX;
5751 #if 0
5752 printf("u32DummyES(0x%x-->0x%x, size=0x%x)=0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", u32DummyES,
5753 pDummy->u32StAddr, pDummy->u32Length, HAL_MVD_MemRead4Byte(u32DummyES),
5754 HAL_MVD_MemRead4Byte(u32DummyES+4),HAL_MVD_MemRead4Byte(u32DummyES+8),HAL_MVD_MemRead4Byte(u32DummyES+12));
5755 #endif
5756
5757 }
5758
5759
HAL_MVD_SLQTblInsertPattern(MS_U8 u8Idx,MVD_PatternType ePattern)5760 MS_BOOL HAL_MVD_SLQTblInsertPattern(MS_U8 u8Idx, MVD_PatternType ePattern)
5761 {
5762 MS_U32 i;
5763 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
5764
5765 if (pstSlqTblInfo->pDrvSlqTbl->u32Empty < SLQ_TBL_SAFERANGE)
5766 {
5767 MVD_DEBUGINFO(printf("SLQTbl full!(0x%lx) Cannot insert pattern any more!\n", (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32Empty));
5768 return FALSE;
5769 }
5770
5771 #if SLQ_NEW_PUSH
5772 if(pstSlqTblInfo->pSlqStatus->bSlqCtrlBit)
5773 {
5774 if(pstSlqTblInfo->pSlqStatus->bSlqPicWaitNextStart)
5775 {
5776 pstSlqTblInfo->pDrvSlqTbl->u32WrPtr = pstSlqTblInfo->pSlqStatus->u32VaildWptrAddr;
5777 }
5778 pstSlqTblInfo->pSlqStatus->bSlqCtrlBit = FALSE;
5779 }
5780 #endif // #if SLQ_NEW_PUSH
5781 for (i =0; i<2; i++)
5782 { //insert dummy pattern
5783 MVD_PacketInfo stDummyPkt;
5784
5785 if (E_MVD_PATTERN_FLUSH == ePattern)
5786 {
5787 MVD_SLQTblGetDummyPkt(&stDummyPkt);
5788 }
5789 else if (E_MVD_PATTERN_FILEEND == ePattern)
5790 {
5791 MVD_SLQTblGetFileEndPkt(u8Idx, &stDummyPkt);
5792 }
5793 else
5794 {
5795 MVD_DEBUGERROR(printf("Invalid MVD_PatternType! Won't insert pattern!\n"));
5796 return FALSE;
5797 }
5798 #if SLQ_NEW_PUSH
5799 pstSlqTblInfo->pSlqStatus->bSlqFireRdy = TRUE;
5800 #endif
5801 //printf("WrPtr 0x%x ", pstSlqTblInfo->pDrvSlqTbl->u32WrPtr);
5802 HAL_MVD_SLQTblSendPacket(u8Idx, &stDummyPkt);
5803 //printf("==> 0x%x\n", pstSlqTblInfo->pDrvSlqTbl->u32WrPtr);
5804 HAL_MVD_SetSLQWritePtr(u8Idx, FALSE);
5805 }
5806 return TRUE;
5807 }
5808
5809
5810 #define FLAG_LAST_FRM_SHOW (MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CMD_LAST_FRAME_SHOW, sizeof(MS_U32)))
HAL_MVD_IsDispFinish(MS_U8 u8Idx)5811 E_MVD_Result HAL_MVD_IsDispFinish(MS_U8 u8Idx)
5812 {
5813 MS_U32 u32TimeCnt;
5814 MVD_SrcMode curSrcMode = HAL_MVD_GetSrcMode(u8Idx);
5815 MS_U32 u32FeByteCnt = 0;
5816 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
5817 MS_VIRT u32FileEndPtr = pstSlqTblInfo->u32FileEndPtr;
5818 MS_U32 u32Id = MVD_GetStreamId(u8Idx);
5819 MS_U8 u8VPUIdx = HAL_VPU_EX_GetTaskId(u32Id);
5820 #ifdef VDEC3
5821 MS_VIRT u32VBBUAddr = HAL_MVD_GetVBBUTableAddr(u8VPUIdx);
5822 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
5823 #endif
5824
5825 //printf("MDrv_MVD_IsDispFinish::");
5826 if (GET_FRMINFO_BUFFADD(u8Idx)==0)
5827 {
5828 MVD_DEBUGERROR(printf("%s err: pu8MVDGetFrameInfoBufStart=NULL\n", __FUNCTION__));
5829 return E_MVD_RET_FAIL;
5830 }
5831
5832 //printf("0x%x\n", FLAG_LAST_FRM_SHOW);
5833 if ((E_MVD_SLQ_TBL_MODE == curSrcMode) && (TRUE != FLAG_LAST_FRM_SHOW))
5834 {
5835 //insert pattern when each time checking IsDispFinish
5836 #ifdef VDEC3
5837 if(pstCtrlCfg->u8McuMode == TRUE)
5838 {
5839 u32TimeCnt= HAL_MVD_GetTime();
5840 while ((HAL_MVD_GetTime() - u32TimeCnt) < 20) // timeout 20 ms
5841 {
5842 if(HAL_VPU_EX_GetVBBUVacancy(u32VBBUAddr) > 0)
5843 {
5844 HAL_VPU_EX_PacketInfo stVpuPkt;
5845 MVD_PacketInfo stDummyPkt;
5846 MVD_SLQTblGetFileEndPkt(u8Idx,&stDummyPkt);
5847
5848 stVpuPkt.u32Offset = stDummyPkt.u32StAddr;
5849 stVpuPkt.u32Length = stDummyPkt.u32Length;
5850 stVpuPkt.u64TimeStamp = (MS_U64)stDummyPkt.u32TimeStamp;
5851 //If in display queue mode
5852 stVpuPkt.u64TimeStamp |= ((MS_U64)stDummyPkt.u32ID_H << 32);
5853 stVpuPkt.u32ID_H = stDummyPkt.u32ID_H;
5854 stVpuPkt.u32ID_L = stDummyPkt.u32ID_L;
5855
5856 HAL_VPU_EX_Push2VBBU(u32Id, &stVpuPkt,u32VBBUAddr);
5857 }
5858
5859 if (TRUE == FLAG_LAST_FRM_SHOW)
5860 {
5861 break;
5862 }
5863 }
5864
5865 if (TRUE != FLAG_LAST_FRM_SHOW)
5866 {
5867 MVD_DEBUGERROR(printf("MDrv_MVD_IsDispFinish TIMEOUT\n"));
5868 return E_MVD_RET_TIME_OUT;
5869 }
5870 else
5871 {
5872 return E_MVD_RET_OK;
5873 }
5874 }
5875 else
5876 #endif
5877 {
5878 //insert pattern when each time checking IsDispFinish
5879 if (HAL_MVD_SLQTblInsertPattern(u8Idx, E_MVD_PATTERN_FILEEND))
5880 {
5881 u32FeByteCnt += END_PATTERN_SIZE;
5882 }
5883
5884 if ((u32FileEndPtr == HAL_MVD_Map2DrvSlqTbl(u8Idx, HAL_MVD_GetSLQReadPtr(u8Idx))) &&
5885 (HAL_MVD_IsMcuMode(u8Idx) == FALSE) &&
5886 (HAL_MVD_IsMStreamerMode(u8Idx) == FALSE))
5887 {
5888 //insert padding pattern until timeout
5889 u32TimeCnt= HAL_MVD_GetTime();
5890 while ((HAL_MVD_GetTime() - u32TimeCnt) < CMD_TIMEOUT_MS)
5891 {
5892 if (TRUE == FLAG_LAST_FRM_SHOW)
5893 {
5894 //printf("\nDisp finished!\n");
5895 break;
5896 }
5897 //insert file-end pattern again
5898 if (HAL_MVD_SLQTblInsertPattern(u8Idx, E_MVD_PATTERN_FILEEND))
5899 {
5900 u32FeByteCnt += END_PATTERN_SIZE;
5901 }
5902 }
5903 if ((HAL_MVD_GetTime() - u32TimeCnt) >= CMD_TIMEOUT_MS)
5904 {
5905 MVD_DEBUGERROR(printf("\n***** MDrv_MVD_IsDispFinish TIMEOUT!!! *****\n\n"));
5906 if (E_MVD_CODEC_VC1_MAIN == HAL_MVD_GetCodecType(u8Idx))
5907 {
5908 if ((HAL_MVD_GetPayloadLen(u8Idx) > 0x200000)
5909 && (TRUE != HAL_MVD_GotFileEndPattern(u8Idx)))
5910 {
5911 MVD_DEBUGERROR(printf("RCV payloadLen(0x%x) invalid!\n",
5912 HAL_MVD_GetPayloadLen(u8Idx)));
5913 }
5914 }
5915 MVD_DEBUGERROR(printf("***** fe=%lx, rd=%lx(%lx,%lx), wr=%lx, empty=%lx, u32FeByteCnt=%x\n",
5916 (unsigned long)u32FileEndPtr, (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32RdPtr, (unsigned long)HAL_MVD_Map2DrvSlqTbl(u8Idx, HAL_MVD_GetSLQReadPtr(u8Idx)),
5917 (unsigned long)HAL_MVD_GetSLQReadPtr(u8Idx), (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32WrPtr, (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32Empty, u32FeByteCnt));
5918 return E_MVD_RET_TIME_OUT;
5919 }
5920 else
5921 {
5922 return E_MVD_RET_OK;
5923 }
5924 }
5925 else
5926 {
5927 //just return fail if readPtr is not closed to file-end ptr
5928 MVD_DEBUGINFO(printf("fe=%lx, rd=%lx(%lx), wr=%lx, empty=%lx\n", (unsigned long)u32FileEndPtr, (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32RdPtr,
5929 (unsigned long)HAL_MVD_Map2DrvSlqTbl(u8Idx, (unsigned long)HAL_MVD_GetSLQReadPtr(u8Idx)), (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32WrPtr, (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32Empty));
5930 return E_MVD_RET_FAIL;
5931 }
5932 }
5933 }
5934
5935 if (FLAG_LAST_FRM_SHOW)
5936 {
5937 return E_MVD_RET_OK;
5938 }
5939 else
5940 {
5941 return E_MVD_RET_FAIL;
5942 }
5943 }
5944
5945 //------------------------------------------------------------------------------
5946 /// Set MVD SLQ start & end address
5947 /// @param -u32start \b IN : start address
5948 /// @param -u32end \b IN : end address
5949 //------------------------------------------------------------------------------
HAL_MVD_SetSLQStartEnd(MS_U8 u8Idx,MS_U32 u32start,MS_U32 u32end)5950 static void HAL_MVD_SetSLQStartEnd(MS_U8 u8Idx, MS_U32 u32start, MS_U32 u32end)
5951 {
5952 MVD_CmdArg mvdcmd;
5953
5954 if ((u32start > SLQ_ADDR_LEN) || ((u32end+1) > SLQ_ADDR_LEN))
5955 {
5956 MVD_DEBUGERROR(printf("MDrv_MVD_SetSLQStartEnd: only support 27bit add!\n"));
5957 }
5958
5959 SET_CMDARG(mvdcmd, (u32end+1), u8Idx);
5960 if (HAL_MVD_MVDCommand( CMD_SLQ_END, &mvdcmd ) == FALSE)
5961 {
5962 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLQ_END ) );
5963 return;
5964 }
5965
5966 SET_CMDARG(mvdcmd, u32start, u8Idx);
5967 if (HAL_MVD_MVDCommand( CMD_SLQ_START, &mvdcmd ) == FALSE)
5968 {
5969 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLQ_START ) );
5970 return;
5971 }
5972
5973 return;
5974 }
5975
HAL_MVD_DecodeIFrame(MS_U8 u8Idx,MS_PHY u32FrameBufAddr,MS_PHY u32StreamBufAddr,MS_PHY u32StreamBufEndAddr)5976 MS_BOOL HAL_MVD_DecodeIFrame(MS_U8 u8Idx, MS_PHY u32FrameBufAddr, MS_PHY u32StreamBufAddr, MS_PHY u32StreamBufEndAddr )
5977 {
5978 MS_U32 u32deley = 0;
5979 MS_U32 u32time = 0;
5980 MVD_CmdArg mvdcmd;
5981 MS_VIRT u32MVDFWSLQTABTmpbufAdr = GET_SLQ_BUFFADD(u8Idx);
5982
5983 MVD_DEBUGINFO(printf("%s offset FBAdd=0x%lx streamStart=0x%lx streamEnd=0x%lx\n",
5984 __FUNCTION__, (unsigned long)u32FrameBufAddr, (unsigned long)u32StreamBufAddr, (unsigned long)u32StreamBufEndAddr));
5985
5986 HAL_MVD_SetCodecInfo(u8Idx, E_MVD_CODEC_MPEG2, E_MVD_SLQ_MODE, DISABLE_PARSER);
5987 HAL_MVD_SetFrameBuffAddr(u8Idx, u32FrameBufAddr, HAL_MVD_GetFBMode(u8Idx));
5988
5989 SETUP_CMDARG(mvdcmd);
5990 mvdcmd.Arg0 = 1;
5991 SET_DECNUM(mvdcmd, u8Idx);
5992 SET_CMD_RET_FALSE(CMD_DISPLAY_CTL, &mvdcmd);
5993
5994 if (HAL_MVD_StepDecode(u8Idx) == FALSE)
5995 {
5996 MVD_DEBUGERROR( printf( "HAL_MVD_StepDecode fail!!\r\n") );
5997 return FALSE;
5998 }
5999
6000 SETUP_CMDARG(mvdcmd);
6001 mvdcmd.Arg0 = 1;
6002 mvdcmd.Arg1 = 1;
6003 SET_DECNUM(mvdcmd, u8Idx);
6004 SET_CMD_RET_FALSE(CMD_FAST_SLOW, &mvdcmd);
6005
6006 //set data
6007 HAL_MVD_Delayms(2);
6008
6009 HAL_MVD_CPU_Sync();
6010 HAL_MVD_FlushMemory();
6011
6012 //wait vld init success or data may lost!
6013 #define WAIT_INIT_SUCCESS_TIME 100 //100ms
6014 u32deley = HAL_MVD_GetTime();
6015 while ((HAL_MVD_GetDecodeStatus(u8Idx)==DEC_STAT_IDLE) && (u32time<WAIT_INIT_SUCCESS_TIME))
6016 {
6017 u32time = HAL_MVD_GetTime()-u32deley;
6018 }
6019 if (u32time>=WAIT_INIT_SUCCESS_TIME)
6020 {
6021 MVD_DEBUGERROR(printf("%s: wait init_success timeout!!!\n", __FUNCTION__));
6022 }
6023 HAL_MVD_SetSLQStartEnd(u8Idx, u32StreamBufAddr, u32StreamBufEndAddr);
6024 MVD_DEBUGINFO(printf("set MVD3_FW_SLQ_TAB_TMPBUF_ADR=%lx\n",(unsigned long)u32MVDFWSLQTABTmpbufAdr));
6025
6026 HAL_MVD_CPU_Sync();
6027 HAL_MVD_FlushMemory();
6028 HAL_MVD_SetSLQStartEnd(u8Idx, u32MVDFWSLQTABTmpbufAdr, u32MVDFWSLQTABTmpbufAdr+MVD3_FW_SLQ_TAB_TMPBUF_LEN);
6029
6030 HAL_MVD_CPU_Sync();
6031 HAL_MVD_ReadMemory();
6032
6033 // wait decode complete
6034 #define WAIT_DECODE_DONE_TIME 33 //To decode 1 frame should take less than 33ms
6035 u32deley = HAL_MVD_GetTime();
6036 u32time = 0;
6037 while (HAL_MVD_GetPicCounter(u8Idx)<1 && (u32time<WAIT_DECODE_DONE_TIME))
6038 {
6039 u32time = HAL_MVD_GetTime()-u32deley;
6040 }
6041 if (u32time >= WAIT_DECODE_DONE_TIME)
6042 {
6043 MVD_DEBUGERROR(printf ("MDrv_MVD_DecodeIFrame time out(du=%d, st=%d, now=%d)\n", u32time, u32deley, HAL_MVD_GetTime()));
6044 MVD_DEBUGERROR(printf("frmCnt=%d state=0x%x lastCmd=0x%x\n", HAL_MVD_GetPicCounter(u8Idx), HAL_MVD_GetDecodeStatus(u8Idx), HAL_MVD_GetLastCmd(u8Idx)));
6045 return FALSE;
6046 }
6047 MVD_DEBUGINFO(printf ("MDrv_MVD_DecodeIFrame time (%d, %d)\n", u32time, u32deley));
6048 //printf("frmCnt=%ld state=0x%x lastCmd=0x%x\n", HAL_MVD_GetPicCounter(u8Idx), HAL_MVD_GetDecodeStatus(u8Idx), HAL_MVD_GetLastCmd(u8Idx));
6049
6050 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
6051 pCtrlCfg->bDecodeIFrame = TRUE;
6052
6053 return TRUE;
6054 }
6055
6056
6057 //------------------------------------------------------------------------------
6058 /// Set bit stream buffer address to MVD
6059 /// @param -u32start \b IN : start address
6060 /// @param -u32end \b IN : end address
6061 //------------------------------------------------------------------------------
MVD_SetBitStreamAddr(MS_U8 u8Idx,MS_VIRT u32start,MS_VIRT u32end)6062 static void MVD_SetBitStreamAddr(MS_U8 u8Idx, MS_VIRT u32start, MS_VIRT u32end)
6063 {
6064 MVD_CmdArg mvdcmd;
6065 MS_ASSERT((u32start%8)==0);
6066 u32start >>= 3;
6067 SET_CMDARG(mvdcmd, u32start, u8Idx);
6068 if (HAL_MVD_MVDCommand( CMD_STREAM_BUF_START, &mvdcmd ) == FALSE)
6069 {
6070 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_STREAM_BUF_START ) );
6071 return;
6072 }
6073
6074 MS_ASSERT((u32end%8)==0);
6075 u32end >>= 3;
6076 SET_CMDARG(mvdcmd, u32end, u8Idx);
6077 if (HAL_MVD_MVDCommand( CMD_STREAM_BUF_END, &mvdcmd ) == FALSE)
6078 {
6079 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_STREAM_BUF_END ) );
6080 return;
6081 }
6082 return;
6083 }
6084
HAL_MVD_SetInternalBuffAddr(MS_U8 u8Idx,MS_VIRT u32start,MS_U32 u32len)6085 MS_BOOL HAL_MVD_SetInternalBuffAddr(MS_U8 u8Idx, MS_VIRT u32start, MS_U32 u32len)
6086 {
6087 MS_VIRT tmpAdr, tmpLen;
6088 MVD_FWCfg* pFwCfg = NULL;
6089 MVD_FWBuff* pBuff = &(pMVDHalContext->stFWBuff[u8Idx]);
6090 MVD_MEMCfg* pstMemCfg = NULL;
6091 MVD_SLQTBLInfo* pstSlqTblInfo = NULL;
6092 MS_U32 u32Id = MVD_GetStreamId(u8Idx);
6093 MS_U8 u8VPUIdx = HAL_VPU_EX_GetTaskId(u32Id);
6094 MS_VIRT u32BuffStart = u32start+(MVD_FW_TASK_OFFSET*u8VPUIdx);
6095 MS_VIRT VPUSHMAddr = HAL_VPU_EX_GetSHMAddr();
6096 MS_VIRT u32StartOffset;
6097 MS_U8 u8MiuSel;
6098
6099 if(VPUSHMAddr != 0)
6100 {
6101 _phy_to_miu_offset(u8MiuSel, u32StartOffset, VPUSHMAddr);
6102
6103 u32StartOffset -= MVD_FW_CODE_LEN;
6104
6105 if(u8Idx == 0)
6106 {
6107 u32BuffStart = u32StartOffset; // for main decoder
6108 }
6109 else if(u8Idx == 1)
6110 {
6111 u32BuffStart = u32StartOffset + 0x20000; // VPUSHMAddr+128K bytes
6112 }
6113 }
6114
6115 MVD_DEBUGINFO(printf("MVD FW shared mem start = 0x%lx\n", (unsigned long)u32BuffStart));
6116 MVD_GetFWBuffAdd(u32BuffStart, u32len, pBuff);
6117 MVD_SetFWBuffAdd(u8Idx, pBuff);
6118
6119 tmpAdr = pBuff->u32DecFrmInfoAdd + MVD_FW_DECFRM_INFO_BUF_LEN;
6120
6121 HAL_MVD_MemGetMap(u8Idx, E_MVD_MMAP_FB, &tmpAdr, &tmpLen);
6122 MVD_DEBUGINFO(printf("set MVD_FRAMEBUFFER_ADR=%lx\n",(unsigned long)tmpAdr));
6123 HAL_MVD_SetFrameBuffAddr(u8Idx, tmpAdr, HAL_MVD_GetFBMode(u8Idx));
6124 pFwCfg = HAL_MVD_GetFWCfg(u8Idx);
6125 HAL_MVD_SetFrameBuffNum(u8Idx, pFwCfg->u8FBNum,pFwCfg->u32FBUsedSize);
6126
6127 // If VD_MHEG5(CPU) and MVD HW engine are run on different MIU,
6128 // IAP, DP, and MV buffers are allocated after FB.
6129 // The reason is that these 3 buffers are used by MVD HW engine.
6130 if(pMVDHalContext->bCMAUsed == FALSE)
6131 {
6132 tmpAdr += pFwCfg->u32FBUsedSize;
6133 pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
6134 if (pstMemCfg->u32FBSize < (pFwCfg->u32FBUsedSize + MVD_HW_BUF_TOTAL_LEN))
6135 {
6136 MVD_DEBUGERROR(printf("MVD HW buffers larger than FB size!!!\n"));
6137 }
6138 MVD_DEBUGINFO(printf("MVD FB boundary =0x%lx\n",(unsigned long)tmpAdr));
6139 tmpAdr = HAL_MVD_SetHWBuffer(u8Idx, tmpAdr);
6140 }
6141
6142 HAL_MVD_MemGetMap(u8Idx, E_MVD_MMAP_BS, &tmpAdr, &tmpLen);
6143 MVD_DEBUGINFO(printf("set MVD_BITSTREAM_ADR=%lx\n",(unsigned long)tmpAdr));
6144 MVD_SetBitStreamAddr(u8Idx, tmpAdr,tmpAdr+tmpLen);
6145 pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
6146 pstSlqTblInfo->u32ESBuffEnd = tmpAdr+tmpLen;
6147
6148 if((pFwCfg->stFBReduction.LumaFBReductionMode != E_MVD_FB_REDUCTION_NONE)
6149 || (pFwCfg->stFBReduction.ChromaFBReductionMode != E_MVD_FB_REDUCTION_NONE))
6150 {
6151 //for chips not support reduction mode, just ignore related config.
6152 MVD_DEBUGERROR(printf("MVD Err: Not support FB reduction mode!!\n"));
6153 }
6154
6155 return TRUE;
6156 }
6157
6158 //------------------------------------------------------------------------------
6159 /// Issue "Decode Pause" command.
6160 //------------------------------------------------------------------------------
HAL_MVD_DecodePause(MS_U8 u8Idx)6161 void HAL_MVD_DecodePause(MS_U8 u8Idx)
6162 {
6163 MVD_CmdArg mvdcmd;
6164 SETUP_CMDARG(mvdcmd);
6165 SET_DECNUM(mvdcmd, u8Idx);
6166 if (HAL_MVD_MVDCommand(CMD_PAUSE, &mvdcmd)== FALSE)
6167 {
6168 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PAUSE) );
6169 return;
6170 }
6171
6172 return;
6173 }
6174
6175
6176 //------------- Below functions are for MediaCodec SLQ Table --------------------
6177 #if _SLQTBL_DUMP_PTS
_SLQTbl_DumpPtsTbl(MS_U8 u8Idx,MS_U32 u32EntryStart,MS_U32 u32EntryEnd)6178 static void _SLQTbl_DumpPtsTbl(MS_U8 u8Idx, MS_U32 u32EntryStart, MS_U32 u32EntryEnd)
6179 {
6180 MS_U32 i;
6181 MS_VIRT u32EsRp, u32EsStart, u32EsEnd;
6182 MS_VIRT u32MVDFWPtsTblAddr = GET_PTSTBL_BUFFADD(u8Idx);
6183
6184 for (i=u32EntryStart; i<u32EntryEnd; i++)
6185 {
6186 u32EsRp = pstSlqTblInfo->pDrvEsTbl->u32StAdd + i*8;
6187
6188 u32EsEnd = HAL_MVD_MemRead4Byte(u32EsRp+4);
6189 u32EsStart = HAL_MVD_MemRead4Byte(u32EsRp); //report StartAdd as read_pointer
6190 printf("ES[%x] Start=0x%x End=0x%x u32EsRp=%x\n",
6191 i, u32EsStart, u32EsEnd, u32EsRp);
6192 }
6193
6194 printf("\n=======Dump PTS table========\n");
6195 printf("addr\t byte_cnt\t dummy_cnt\t id_low\t id_high\t time_stamp\n");
6196 for (i=u32EntryStart; i<u32EntryEnd; i++)
6197 {
6198 printf("0x%x\t 0x%08lx\t 0x%08lx\t 0x%08lx\t 0x%08lx\t 0x%08lx\n", u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN,
6199 HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN), //byteCnt
6200 HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN+4), //dummyPktCnt
6201 HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN+8), //idLow
6202 HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN+12),//idHigh
6203 HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN+16) //pts
6204 );
6205 }
6206 printf("=====================================\n");
6207 }
6208 #endif
6209
6210
6211 #if SLQ_NEW_PUSH
MVD_SLQTblGetHdrPkt(MS_U8 u8Idx,MVD_PacketInfo * pDivxHdr,MVD_PacketInfo * pDivxData)6212 void MVD_SLQTblGetHdrPkt(MS_U8 u8Idx, MVD_PacketInfo* pDivxHdr, MVD_PacketInfo* pDivxData)
6213 #else
6214 static void MVD_SLQTblGetDivxHdrPkt(MS_U8 u8Idx, MVD_PacketInfo* pDivxHdr, MVD_PacketInfo* pDivxData)
6215 #endif
6216 {
6217 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
6218 MS_VIRT u32DivXPattern = pstSlqTblInfo->pDrvDivxTbl->u32WrPtr;
6219 MS_U32 u32FrmSize = pDivxData->u32Length;
6220 MVD_CodecType curCodecType = HAL_MVD_GetCodecType(u8Idx);
6221 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
6222 #ifdef VDEC3
6223 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
6224 #endif
6225 #if SLQ_NEW_PUSH
6226 if(pstSlqTblInfo->pSlqStatus->bSlqCtrlBit && pstCtrlCfg->u8McuMode == FALSE)
6227 {
6228 if(pstSlqTblInfo->pSlqStatus->bSlqPicWaitNextStart && pstSlqTblInfo->pSlqStatus->bSlqPicStart)
6229 {
6230 //printf("Show KC the SlqPushLength = 0x%x\n",pstSlqTblInfo->pSlqStatus->u32SlqPushLength);
6231 if (E_MVD_CODEC_DIVX311 == curCodecType)
6232 {
6233 HAL_MVD_MemWrite4Byte(pstSlqTblInfo->pSlqStatus->u32SlqPatternAddr +4, pstSlqTblInfo->pSlqStatus->u32SlqPushLength);
6234 HAL_MVD_MemWrite4Byte(pstSlqTblInfo->pSlqStatus->u32SlqPatternAddr , DIVX_PATTERN);
6235 }
6236 else if(E_MVD_CODEC_VC1_MAIN == curCodecType)
6237 {//rcv
6238 HAL_MVD_MemWrite4Byte(pstSlqTblInfo->pSlqStatus->u32SlqPatternAddr +4, RCV_PATTERN);
6239 HAL_MVD_MemWrite4Byte(pstSlqTblInfo->pSlqStatus->u32SlqPatternAddr , pstSlqTblInfo->pSlqStatus->u32SlqPushLength);
6240 }
6241 else if (E_MVD_CODEC_VC1_ADV == curCodecType)
6242 {
6243 HAL_MVD_MemWrite4Byte(pstSlqTblInfo->pSlqStatus->u32SlqPatternAddr , VC1_PATTERN);
6244 }
6245 pstSlqTblInfo->pSlqStatus->u32SlqPushLength = 0;
6246 pstSlqTblInfo->pSlqStatus->u32SlqPatternAddr = 0;
6247 pstSlqTblInfo->pSlqStatus->bSlqFireRdy =TRUE;
6248 pstSlqTblInfo->pSlqStatus->u32VaildWptrAddr = pstSlqTblInfo->pDrvSlqTbl->u32WrPtr;// - 16;
6249 pstSlqTblInfo->pSlqStatus->bSlqPicWaitNextStart = FALSE;
6250 pstSlqTblInfo->pSlqStatus->bSlqPicCollect = FALSE;
6251 }
6252
6253 if(pstSlqTblInfo->pSlqStatus->bSlqPicStart)
6254 {
6255 pstSlqTblInfo->pSlqStatus->u32SlqPatternAddr = u32DivXPattern;
6256 pstSlqTblInfo->pSlqStatus->u32SlqPushLength += u32FrmSize;
6257 pstSlqTblInfo->pSlqStatus->bSlqPicCollect = TRUE;
6258 pstSlqTblInfo->pSlqStatus->bSlqPicWaitNextStart =TRUE;
6259 }
6260 else if(pstSlqTblInfo->pSlqStatus->bSlqPicCollect)
6261 {
6262 pstSlqTblInfo->pSlqStatus->u32SlqPushLength += u32FrmSize;
6263 pstSlqTblInfo->pSlqStatus->bSlqPicWaitNextStart =TRUE;
6264 }
6265 }
6266 else
6267 {
6268 HAL_MVD_MemWrite4Byte(u32DivXPattern, DIVX_PATTERN);
6269 HAL_MVD_MemWrite4Byte(u32DivXPattern +4,u32FrmSize);
6270 }
6271 #else
6272 HAL_MVD_MemWrite4Byte(u32DivXPattern, DIVX_PATTERN);
6273 HAL_MVD_MemWrite4Byte(u32DivXPattern+4, u32FrmSize);
6274 #endif
6275 pDivxHdr->u32StAddr = u32DivXPattern - HAL_MVD_GetMemOffset(pstMemCfg->u32DrvBufAddr);
6276 pDivxHdr->u32TimeStamp = pDivxData->u32TimeStamp; //unit: ms
6277 pDivxHdr->u32ID_L = pDivxData->u32ID_L;
6278 pDivxHdr->u32ID_H = pDivxData->u32ID_H;
6279 //printf("u32DivXPattern(0x%x==>0x%x)=0x%x 0x%x\n", u32DivXPattern, pDivxHdr->u32StAddr,
6280 // HAL_MVD_MemRead4Byte(u32DivXPattern), HAL_MVD_MemRead4Byte(u32DivXPattern+4));
6281 if (E_MVD_CODEC_VC1_ADV == curCodecType)
6282 {
6283 pstSlqTblInfo->pDrvDivxTbl->u32WrPtr += 4;
6284 pDivxHdr->u32Length = 4;
6285 }
6286 else
6287 {
6288 pstSlqTblInfo->pDrvDivxTbl->u32WrPtr += 8;
6289 if(pstCtrlCfg->u8McuMode == TRUE)
6290 {
6291 pDivxHdr->u32Length = 64;
6292 if (pstSlqTblInfo->pDrvDivxTbl->u32WrPtr >= pstSlqTblInfo->pDrvDivxTbl->u32EndAdd)
6293 {
6294 pstSlqTblInfo->pDrvDivxTbl->u32WrPtr = pstSlqTblInfo->pDrvDivxTbl->u32StAdd;
6295 }
6296 }
6297 else
6298 {
6299 pDivxHdr->u32Length = 8;
6300 }
6301 }
6302
6303 #if SLQ_NEW_PUSH
6304 if(pstSlqTblInfo->pSlqStatus->bSlqPicStart && pstCtrlCfg->u8McuMode == FALSE)
6305 {
6306 if (E_MVD_CODEC_VC1_ADV == curCodecType)
6307 {
6308 pstSlqTblInfo->pDrvDivxTbl->u32WrPtr += 4;
6309 pDivxHdr->u32Length = 4;
6310 }
6311 else
6312 {
6313 pstSlqTblInfo->pDrvDivxTbl->u32WrPtr += 8;
6314 pDivxHdr->u32Length = 8;
6315 }
6316 }
6317 #endif
6318 }
6319
MVD_SLQTblInitFileEndPkt(MS_U8 u8Idx,MVD_CodecType eType)6320 static void MVD_SLQTblInitFileEndPkt(MS_U8 u8Idx, MVD_CodecType eType)
6321 {
6322 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
6323 MS_PHY u32EndPattern = HAL_MVD_GetMemOffset(pstMemCfg->u32DrvBufAddr+SLQ_TBL_SIZE*3);
6324 MS_PHY temp = 0;
6325
6326 #if 0
6327 _MVD_Memset(u32EndPattern, 0xff, END_PATTERN_SIZE);
6328 #else
6329 //_miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,u32EndPattern,temp);
6330 temp = u32EndPattern+pMVDHalContext->stMiuCfg.u8FWMiuSel*HAL_MIU1_BASE;
6331 memset((void*)(MS_PA2KSEG1(temp)),0xff,END_PATTERN_SIZE);
6332 MsOS_FlushMemory();
6333 MsOS_ReadMemory();
6334 #endif
6335
6336 if ((E_MVD_CODEC_FLV == eType)||(E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER == eType))
6337 {
6338 HAL_MVD_MemWrite4Byte(u32EndPattern, FLV_PATTERN);
6339 HAL_MVD_MemWrite4Byte(u32EndPattern+4, 0xffffffff);
6340 HAL_MVD_MemWrite4Byte(u32EndPattern+8, END_PATTERN_1); //scw
6341 HAL_MVD_MemWrite4Byte(u32EndPattern+12,END_PATTERN_2); //scw
6342 HAL_MVD_MemWrite4Byte(u32EndPattern+16,END_PATTERN_3); //scw
6343 //printf("##########FileEnd for FLV/SVH!, u32EndPattern=%x\n",u32EndPattern);
6344 }
6345 else if (E_MVD_CODEC_DIVX311 == eType)
6346 {
6347 HAL_MVD_MemWrite4Byte(u32EndPattern, DIVX_PATTERN);
6348 HAL_MVD_MemWrite4Byte(u32EndPattern+4, 0xffffffff);
6349 HAL_MVD_MemWrite4Byte(u32EndPattern+8, END_PATTERN_1); //scw
6350 HAL_MVD_MemWrite4Byte(u32EndPattern+12,END_PATTERN_2); //scw
6351 HAL_MVD_MemWrite4Byte(u32EndPattern+16,END_PATTERN_3); //scw
6352 //printf("##########FileEnd for DIVX311!, u32EndPattern=%x\n",u32EndPattern);
6353 }
6354 else if ((E_MVD_CODEC_MPEG2 == eType)||(E_MVD_CODEC_MPEG4 == eType))
6355 {
6356 HAL_MVD_MemWrite4Byte(u32EndPattern, MPEG_PATTERN_0);
6357 HAL_MVD_MemWrite4Byte(u32EndPattern+4, END_PATTERN_1);
6358 HAL_MVD_MemWrite4Byte(u32EndPattern+8, END_PATTERN_2);
6359 HAL_MVD_MemWrite4Byte(u32EndPattern+12,END_PATTERN_3);
6360 //printf("##########FileEnd for MPEG2/4!, u32EndPattern=%x\n",u32EndPattern);
6361 }
6362 else
6363 {
6364 HAL_MVD_MemWrite4Byte(u32EndPattern, END_PATTERN_0);
6365 HAL_MVD_MemWrite4Byte(u32EndPattern+4, END_PATTERN_1);
6366 HAL_MVD_MemWrite4Byte(u32EndPattern+8, END_PATTERN_2); //scw
6367 HAL_MVD_MemWrite4Byte(u32EndPattern+12,END_PATTERN_3); //scw
6368 //printf("##########FileEnd for VC1!, u32EndPattern=%x\n",u32EndPattern);
6369 }
6370
6371 MVD_DEBUGINFO(printf("u32EndPattern(0x%lx)=0x%x 0x%x\n", (unsigned long)u32EndPattern,
6372 HAL_MVD_MemRead4Byte(u32EndPattern), HAL_MVD_MemRead4Byte(u32EndPattern+4)));
6373 }
6374
6375
MVD_SLQTblInitDummyPkt(MS_U8 u8Idx,MVD_CodecType eType)6376 static void MVD_SLQTblInitDummyPkt(MS_U8 u8Idx, MVD_CodecType eType)
6377 {
6378 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
6379 MS_PHY u32DummyES = HAL_MVD_GetMemOffset(pstMemCfg->u32DrvBufAddr+SLQ_TBL_SIZE*2);
6380 MS_U32 u32DummyPattern[3];
6381 MS_U32 u32PatternSize;
6382 MS_U32 i;
6383 MS_PHY temp = 0;
6384
6385 //printf("eType = 0x%x\n", eType);
6386 //initial content for dummy packet
6387 #if 0
6388 _MVD_Memset(u32DummyES, 0xff, DUMMY_SIZE);
6389 #else
6390 temp = u32DummyES+pMVDHalContext->stMiuCfg.u8FWMiuSel*HAL_MIU1_BASE;
6391 memset((void*)(MS_PA2KSEG1(temp)),0xff,DUMMY_SIZE);
6392 MsOS_FlushMemory();
6393 MsOS_ReadMemory();
6394 #endif
6395
6396 switch (eType)
6397 {
6398 case E_MVD_CODEC_FLV:
6399 case E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER:
6400 u32DummyPattern[0] = FLV_PATTERN;
6401 u32PatternSize = 1;
6402 break;
6403
6404 case E_MVD_CODEC_DIVX311:
6405 u32DummyPattern[0] = DIVX_PATTERN;
6406 u32PatternSize = 1;
6407 break;
6408
6409 case E_MVD_CODEC_VC1_ADV: //vc1
6410 u32DummyPattern[0] = VC1_PATTERN_0;
6411 u32DummyPattern[1] = VC1_PATTERN_1;
6412 u32DummyPattern[2] = VC1_PATTERN_2;
6413 u32PatternSize = 3;
6414 break;
6415
6416 case E_MVD_CODEC_VC1_MAIN: //rcv
6417 u32DummyPattern[0] = RCV_PATTERN_0;
6418 u32DummyPattern[1] = RCV_PATTERN_1;
6419 u32DummyPattern[2] = RCV_PATTERN_2;
6420 u32PatternSize = 3;
6421 break;
6422
6423 default:
6424 u32DummyPattern[0] = DUMMY_PATTERN;
6425 u32PatternSize = 1;
6426 break;
6427 }
6428 for (i=0; i<u32PatternSize; i++)
6429 {
6430 HAL_MVD_MemWrite4Byte(u32DummyES+i*4, u32DummyPattern[i]);
6431 }
6432 #if 0
6433 printf("u32DummyES(0x%x)=0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", u32DummyES, HAL_MVD_MemRead4Byte(u32DummyES),
6434 HAL_MVD_MemRead4Byte(u32DummyES+4),HAL_MVD_MemRead4Byte(u32DummyES+8),HAL_MVD_MemRead4Byte(u32DummyES+12));
6435 #endif
6436
6437 }
6438
MVD_SLQTblInitDrvSlqTbl(MVD_SLQ_TBL_ST * pDrvSlqTbl,MS_U32 u32Addr)6439 static void MVD_SLQTblInitDrvSlqTbl(MVD_SLQ_TBL_ST* pDrvSlqTbl, MS_U32 u32Addr)
6440 {
6441 MS_PHY temp = 0;
6442 pDrvSlqTbl->u32StAdd = u32Addr;
6443 pDrvSlqTbl->u32EndAdd = u32Addr + SLQ_TBL_SIZE;
6444 pDrvSlqTbl->u32EntryCntMax = SLQ_ENTRY_MAX;
6445
6446 //reset SLQ table read/write pointers
6447 pDrvSlqTbl->u32RdPtr = pDrvSlqTbl->u32StAdd;
6448 pDrvSlqTbl->u32WrPtr = pDrvSlqTbl->u32StAdd;
6449 pDrvSlqTbl->pu32LastEntry = &pDrvSlqTbl->u32WrPtr;
6450
6451 #if (!MVD_TURBO_INIT)
6452 //reset SLQ table
6453 #if 0
6454 _MVD_Memset(pDrvSlqTbl->u32StAdd, 0, SLQ_TBL_SIZE);
6455 #else
6456 temp = pDrvSlqTbl->u32StAdd+pMVDHalContext->stMiuCfg.u8FWMiuSel*HAL_MIU1_BASE;
6457 memset((void*)(MS_PA2KSEG1(temp)),0,SLQ_TBL_SIZE);
6458 MsOS_FlushMemory();
6459 MsOS_ReadMemory();
6460 #endif
6461 #endif
6462 pDrvSlqTbl->u32Empty = SLQ_TBL_SIZE;
6463 //_SLQTbl_DumpInfo(pDrvSlqTbl);
6464 }
6465
MVD_SLQTblInitSlqStatus(MVD_SLQ_STATUS * pSlqStatus,MS_VIRT u32WrPtr)6466 static void MVD_SLQTblInitSlqStatus(MVD_SLQ_STATUS* pSlqStatus, MS_VIRT u32WrPtr)
6467 {
6468 #if SLQ_NEW_PUSH
6469 pSlqStatus->u32VaildWptrAddr = u32WrPtr ;
6470 pSlqStatus->bSlqPicWaitNextStart = FALSE;
6471 pSlqStatus->bSlqCtrlBit = FALSE;
6472 pSlqStatus->u32SlqPushLength = 0;
6473 pSlqStatus->bSlqPicStart = FALSE;
6474 pSlqStatus->bSlqPicCollect = FALSE;
6475 pSlqStatus->bSlqEnLastFrameShow =FALSE;
6476 pSlqStatus->bSlqFireRdy = FALSE;
6477 #endif
6478 }
6479
MVD_SLQTblInitDrvDivxTbl(MVD_SLQ_ES_ST * pDrvDivxTbl,MS_U32 u32StAdd,MS_U32 u32Val)6480 static void MVD_SLQTblInitDrvDivxTbl(MVD_SLQ_ES_ST* pDrvDivxTbl, MS_U32 u32StAdd, MS_U32 u32Val)
6481 {
6482 MS_PHY temp = 0;
6483 ///// init SLQ entries for DivX311
6484 pDrvDivxTbl->u32StAdd = u32StAdd;
6485 pDrvDivxTbl->u32EndAdd= pDrvDivxTbl->u32StAdd + SLQ_TBL_SIZE;
6486 pDrvDivxTbl->u32WrPtr = pDrvDivxTbl->u32StAdd;
6487 //pDrvDivxTbl->u32RdPtr = pDrvDivxTbl->u32StAdd;
6488 #if (!MVD_TURBO_INIT)
6489 //reset DivX311 pattern table
6490 #if 0
6491 _MVD_Memset(pDrvDivxTbl->u32StAdd, 0, u32Val);
6492 #else
6493 temp = pDrvDivxTbl->u32StAdd+pMVDHalContext->stMiuCfg.u8FWMiuSel*HAL_MIU1_BASE;
6494 memset((void*)(MS_PA2KSEG1(temp)),0,u32Val);
6495 MsOS_FlushMemory();
6496 MsOS_ReadMemory();
6497 #endif
6498 #endif
6499 }
6500
MVD_SLQTblInitDrvEsTbl(MVD_SLQ_ES_ST * pDrvEsTbl,MS_U32 u32StAdd,MS_U32 u32Val)6501 static void MVD_SLQTblInitDrvEsTbl(MVD_SLQ_ES_ST* pDrvEsTbl, MS_U32 u32StAdd, MS_U32 u32Val)
6502 {
6503 UNUSED(u32Val);
6504 MS_PHY temp = 0;
6505 ///// init ES table
6506 pDrvEsTbl->u32StAdd = u32StAdd;
6507 pDrvEsTbl->u32EndAdd= pDrvEsTbl->u32StAdd + ES_TBL_SIZE;
6508 pDrvEsTbl->u32WrPtr = pDrvEsTbl->u32StAdd;
6509 //reset ES table
6510 #if 0
6511 _MVD_Memset(pDrvEsTbl->u32StAdd, 0, ES_TBL_SIZE);
6512 #else
6513 temp = pDrvEsTbl->u32StAdd+pMVDHalContext->stMiuCfg.u8FWMiuSel*HAL_MIU1_BASE;
6514 memset((void*)(MS_PA2KSEG1(temp)),0,ES_TBL_SIZE);
6515 MsOS_FlushMemory();
6516 MsOS_ReadMemory();
6517 #endif
6518 }
6519
6520 //------------------------------------------------------------------------------------------------------------
6521 // Layout of drvProcBuffer
6522 // -----------------
6523 // drvProcBuff | SlqTbl entries | <- pstSlqTblInfo->pDrvSlqTbl->u32StAdd
6524 // | 8K bytes |
6525 // | (1024 entries) |
6526 // | |
6527 // |-----------------|
6528 // | DivX311 | <- pstSlqTblInfo->pDrvSlqTbl->u32EndAdd <- pstSlqTblInfo->pDrvDivxTbl->u32StAdd
6529 // | 8K bytes |
6530 // | (1024 entries) |
6531 // | |
6532 // |-----------------|
6533 // | Flush Patterns |... <- pstSlqTblInfo->pDrvDivxTbl->u32EndAdd <- _drvDummy.u32StAdd
6534 // | 8K bytes |
6535 // | (1024 entries) |
6536 // | |
6537 // |-----------------|
6538 // | FileEnd Pattern |... <- _drvDummy.u32EndAdd <- _drvFileEnd.u32StAdd
6539 // | 8K bytes |
6540 // | (1024 entries) |
6541 // | |
6542 // |-----------------|
6543 // | ES table |... <- _drvFileEnd.u32EndAdd <- pstSlqTblInfo->pDrvEsTbl->u32StAdd
6544 // | 8K bytes |
6545 // | (1024 entries) |
6546 // | |
6547 // |-----------------|
6548 // | |........ End of drvProcBuff
6549 //
6550 //------------------------------------------------------------------------------------------------------------
HAL_MVD_SLQTblInit(MS_U8 u8Idx)6551 MS_BOOL HAL_MVD_SLQTblInit(MS_U8 u8Idx)
6552 {
6553 MS_VIRT u32Addr, u32Len;
6554 MVD_CodecType curCodecType = HAL_MVD_GetCodecType(u8Idx);
6555 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
6556 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
6557
6558 if(curCodecType == E_MVD_CODEC_UNKNOWN)
6559 {
6560 MVD_DEBUGERROR(printf("%s: unknow codec type!\n", __FUNCTION__));
6561 return FALSE;
6562 }
6563 pstSlqTblInfo->u32DummyPktCnt = 0;//reset dummy packet counter
6564 pstSlqTblInfo->u32SlqByteCnt = 0; //reset SLQ table byte counter
6565 pstSlqTblInfo->bSlqTblHasValidData = FALSE;
6566
6567 HAL_MVD_MemGetMap(u8Idx, E_MVD_MMAP_DRV, &u32Addr, &u32Len);
6568
6569 //init SLQ table attributes & reset SLQ table read/write pointers
6570 MVD_SLQTblInitDrvSlqTbl(pstSlqTblInfo->pDrvSlqTbl, u32Addr);
6571 pstSlqTblInfo->u32FileEndPtr = pstSlqTblInfo->pDrvSlqTbl->u32StAdd;
6572
6573 MVD_SLQTblInitSlqStatus(pstSlqTblInfo->pSlqStatus, pstSlqTblInfo->pDrvSlqTbl->u32WrPtr);
6574
6575 //set SLQ table start/end to F/W
6576 HAL_MVD_SetSLQTblBufStartEnd(u8Idx, HAL_MVD_GetMemOffset(pstMemCfg->u32BSAddr), HAL_MVD_GetMemOffset(pstMemCfg->u32BSAddr+SLQ_TBL_SIZE));
6577
6578 ///// init SLQ entries for DivX311
6579 MVD_SLQTblInitDrvDivxTbl(pstSlqTblInfo->pDrvDivxTbl, pstSlqTblInfo->pDrvSlqTbl->u32EndAdd, SLQ_TBL_SIZE);
6580
6581 ///// init flush pattern
6582 MVD_SLQTblInitDummyPkt(u8Idx, curCodecType);
6583
6584 ///// init file-end pattern
6585 MVD_SLQTblInitFileEndPkt(u8Idx, curCodecType);
6586
6587 MVD_SLQTblInitDrvEsTbl(pstSlqTblInfo->pDrvEsTbl, (pstSlqTblInfo->pDrvDivxTbl->u32EndAdd + DUMMY_SIZE*2), pstMemCfg->u32DrvBufSize);
6588
6589 pstSlqTblInfo->u32PreEsRd = MVD_U32_MAX; //reset ES read pointer
6590 pstSlqTblInfo->u32PreEsWr = 0; //reset ES write pointer
6591
6592 return TRUE;
6593 }
6594
6595
6596 #if 0
6597 static void _SLQTbl_DumpInfo(MVD_SLQ_TBL_ST* pInfo)
6598 {
6599 printf("str=0x%x\n", pInfo->u32StAdd);
6600 printf("end=0x%x\n", pInfo->u32EndAdd);
6601 printf("cnt=0x%x\n", pInfo->u32EntryCntMax);
6602 printf("rd =0x%x\n", pInfo->u32RdPtr);
6603 printf("wr =0x%x\n", pInfo->u32WrPtr);
6604 return;
6605 }
6606 #endif
6607
6608
HAL_MVD_GetQueueVacancy(MS_U8 u8Idx,MS_BOOL bCached)6609 MS_U32 HAL_MVD_GetQueueVacancy(MS_U8 u8Idx, MS_BOOL bCached)
6610 {
6611 MS_U32 u32Empty;
6612 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
6613
6614 #if 0
6615 if (MDrv_MVD_GetVldErrCount()!=0)
6616 {
6617 printf("QQQ wPtr= 0x%x(0x%x) rPtr=0x%x(0x%x) vldErr=0x%x\n", writePtrLast[u8Idx], pstSlqTblInfo->pDrvSlqTbl->u32WrPtr,
6618 HAL_MVD_GetSLQReadPtr(u8Idx), pstSlqTblInfo->pDrvSlqTbl->u32RdPtr, MDrv_MVD_GetVldErrCount(u8Idx));
6619 printf("Previous EsRead=0x%x EsWrite=0x%x\n", pstSlqTblInfo->u32PreEsRd, pstSlqTblInfo->u32PreEsWr);
6620 _SLQTbl_DumpPtsTbl(u8Idx, 0x0, 0x620);
6621 while(1);
6622 }
6623 #endif
6624
6625 u32Empty = pstSlqTblInfo->pDrvSlqTbl->u32Empty;
6626 if ((TRUE == bCached) && (u32Empty > SLQTBL_CHECKVACANCY_WATERLEVEL))
6627 {
6628 //To have better performance, we only query F/W read pointer
6629 //when queue_vacancy is lower than water_level
6630 if (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr > pstSlqTblInfo->pDrvSlqTbl->u32RdPtr)
6631 {
6632 u32Empty = SLQ_TBL_SIZE - (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr - pstSlqTblInfo->pDrvSlqTbl->u32RdPtr);
6633 }
6634 else
6635 {
6636 u32Empty = pstSlqTblInfo->pDrvSlqTbl->u32RdPtr - pstSlqTblInfo->pDrvSlqTbl->u32WrPtr;
6637 }
6638
6639 if (u32Empty == 0)// && (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr == pstSlqTblInfo->pDrvSlqTbl->u32StAdd))
6640 {
6641 u32Empty = SLQ_TBL_SIZE;
6642 }
6643 u32Empty -= SLQ_TBL_SAFERANGE;
6644 return (u32Empty / SLQ_ENTRY_LEN);
6645 }
6646
6647 pstSlqTblInfo->pDrvSlqTbl->u32RdPtr = HAL_MVD_Map2DrvSlqTbl(u8Idx, HAL_MVD_GetSLQReadPtr(u8Idx));
6648 //printf("QV=0x%x rd=0x%x==>", u32Empty, pstSlqTblInfo->pDrvSlqTbl->u32RdPtr);
6649 if (pstSlqTblInfo->pDrvSlqTbl->u32RdPtr >= (pstSlqTblInfo->pDrvSlqTbl->u32StAdd+SLQ_ENTRY_LEN))
6650 {
6651 if (pstSlqTblInfo->pDrvSlqTbl->u32RdPtr >= pstSlqTblInfo->pDrvSlqTbl->u32EndAdd)
6652 {
6653 MVD_DEBUGERROR(printf("%s: readPtr 0x%lx out of range: too large!\n",
6654 __FUNCTION__, (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32RdPtr));
6655 }
6656 pstSlqTblInfo->pDrvSlqTbl->u32RdPtr -= SLQ_ENTRY_LEN;
6657 }
6658 else if (pstSlqTblInfo->pDrvSlqTbl->u32RdPtr == pstSlqTblInfo->pDrvSlqTbl->u32StAdd)
6659 {
6660 pstSlqTblInfo->pDrvSlqTbl->u32RdPtr = pstSlqTblInfo->pDrvSlqTbl->u32EndAdd - SLQ_ENTRY_LEN;
6661 }
6662 else
6663 {
6664 MVD_DEBUGERROR(printf("%s: readPtr 0x%lx out of range: too small!\n",
6665 __FUNCTION__, (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32RdPtr));
6666 pstSlqTblInfo->pDrvSlqTbl->u32RdPtr = pstSlqTblInfo->pDrvSlqTbl->u32StAdd;
6667 }
6668 //printf("0x%x\n", pstSlqTblInfo->pDrvSlqTbl->u32RdPtr);
6669
6670 if (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr > pstSlqTblInfo->pDrvSlqTbl->u32RdPtr)
6671 {
6672 u32Empty = SLQ_TBL_SIZE - (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr - pstSlqTblInfo->pDrvSlqTbl->u32RdPtr);
6673 }
6674 else
6675 {
6676 u32Empty = pstSlqTblInfo->pDrvSlqTbl->u32RdPtr - pstSlqTblInfo->pDrvSlqTbl->u32WrPtr;
6677 }
6678
6679 if (u32Empty == 0)// && (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr == pstSlqTblInfo->pDrvSlqTbl->u32StAdd))
6680 {
6681 u32Empty = SLQ_TBL_SIZE;
6682 }
6683
6684 pstSlqTblInfo->pDrvSlqTbl->u32Empty = u32Empty;
6685
6686 if (u32Empty < SLQ_TBL_SAFERANGE)
6687 {//to avoid write_pointer catch up to read_pointer
6688 u32Empty= 0;
6689 }
6690 else
6691 {
6692 u32Empty -= SLQ_TBL_SAFERANGE;
6693 }
6694
6695 //printf("%s r=0x%x w=0x%x u32Empty=0x%x\n", __FUNCTION__,
6696 // pstSlqTblInfo->pDrvSlqTbl->u32RdPtr, pstSlqTblInfo->pDrvSlqTbl->u32WrPtr, u32Empty);
6697 return (u32Empty / SLQ_ENTRY_LEN);
6698 }
6699
HAL_MVD_PushQueue(MS_U8 u8Idx,MVD_PacketInfo * pInfo)6700 E_MVD_Result HAL_MVD_PushQueue(MS_U8 u8Idx, MVD_PacketInfo* pInfo)
6701 {
6702 E_MVD_Result eRet=E_MVD_RET_INVALID_PARAM;
6703 MVD_CodecType curCodecType = HAL_MVD_GetCodecType(u8Idx);
6704 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
6705 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
6706 MS_U32 u32Id = MVD_GetStreamId(u8Idx);
6707 MS_U8 u8VPUIdx = HAL_VPU_EX_GetTaskId(u32Id);
6708 #ifdef VDEC3
6709 MS_VIRT u32VBBUAddr = HAL_MVD_GetVBBUTableAddr(u8VPUIdx);
6710 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
6711 #endif
6712 if (pInfo == NULL)
6713 {
6714 MVD_DEBUGERROR(printf("PushQueue NULL pInfo\n"));
6715 return E_MVD_RET_INVALID_PARAM;
6716 }
6717
6718 #ifndef VDEC3
6719 if(pMVDHalContext->bAutoInsertDummyPattern[u8Idx] == TRUE)
6720 #else
6721 if(pstCtrlCfg->u8McuMode == TRUE)
6722 #endif
6723 {
6724 MS_U8* temp = (MS_U8*)(MS_PA2KSEG1( (MS_PHY)(pInfo->u32StAddr)+pstMemCfg->u32BSAddr));
6725 MS_U32 i;
6726 MS_U32 u32DummyPattern[3];
6727 MS_U32 u32PatternSize;
6728
6729 switch (curCodecType)
6730 {
6731 case E_MVD_CODEC_FLV:
6732 case E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER:
6733 u32DummyPattern[0] = FLV_PATTERN;
6734 u32PatternSize = 1;
6735 break;
6736
6737 case E_MVD_CODEC_DIVX311:
6738 u32DummyPattern[0] = DIVX_PATTERN;
6739 u32PatternSize = 1;
6740 break;
6741
6742 case E_MVD_CODEC_VC1_ADV: //vc1
6743 u32DummyPattern[0] = VC1_PATTERN_0;
6744 u32DummyPattern[1] = VC1_PATTERN_3;
6745 u32PatternSize = 2;
6746 break;
6747 case E_MVD_CODEC_VC1_MAIN: //rcv
6748 u32DummyPattern[0] = RCV_PATTERN_3;
6749 u32DummyPattern[1] = RCV_PATTERN_1;
6750 u32DummyPattern[2] = RCV_PATTERN_3;
6751 u32PatternSize = 3;
6752 break;
6753
6754 default:
6755 u32DummyPattern[0] = DUMMY_PATTERN;
6756 u32DummyPattern[1] = DUMMY_PATTERN;
6757 u32PatternSize = 2;
6758 break;
6759 }
6760
6761
6762 for (i=0; i<u32PatternSize; i++)
6763 {
6764 temp[4*i+pInfo->u32Length] = ((u32DummyPattern[i])&0xff);
6765 temp[4*i+pInfo->u32Length+1] = ((u32DummyPattern[i]>>8)&0xff);
6766 temp[4*i+pInfo->u32Length+2] = ((u32DummyPattern[i]>>16)&0xff);
6767 temp[4*i+pInfo->u32Length+3] = ((u32DummyPattern[i]>>24)&0xff);
6768 }
6769
6770 for(i=u32PatternSize*4;i<256;i++)
6771 {
6772 temp[pInfo->u32Length+i] = 0xFF;
6773 }
6774
6775 pInfo->u32Length += 256;
6776 }
6777
6778
6779 #if _SLQTBL_DUMP_PUSHQ
6780 {
6781 //static MS_U32 u32pqTimes[MAX_DEC_NUM]= {0, 0};
6782
6783 printf("Push[%x] st=0x%x len=0x%x pts=0x%x\n", pMVDHalContext->u32pqTimes[u8Idx]++,
6784 pInfo->u32StAddr, pInfo->u32Length, pInfo->u32TimeStamp);
6785 }
6786 #endif
6787
6788 #if SLQ_NEW_PUSH
6789 if((pInfo->u32StAddr & SLQ_PIC_START_FLAG) == SLQ_PIC_START_FLAG)
6790 {
6791 pInfo->u32StAddr = pInfo->u32StAddr&~SLQ_PIC_START_FLAG;
6792 pstSlqTblInfo->pSlqStatus->bSlqPicStart =TRUE;
6793 pstSlqTblInfo->pSlqStatus->bSlqCtrlBit = TRUE;
6794 }
6795 else
6796 {
6797 pstSlqTblInfo->pSlqStatus->bSlqPicStart = FALSE;
6798 }
6799 #endif
6800 //check input parameters
6801 if (pInfo->u32StAddr >= pstMemCfg->u32BSSize)
6802 {
6803 //since u32StAddr is offset, it shouldn't be larger than size.
6804 MVD_DEBUGERROR(printf("PushQueue invalid u32StAddr=0x%lx, bsSize=0x%lx\n", (unsigned long)pInfo->u32StAddr, (unsigned long)pstMemCfg->u32BSSize));
6805 return E_MVD_RET_INVALID_PARAM;
6806 }
6807 else if ((pInfo->u32TimeStamp == MVD_NULLPKT_PTS) && (pInfo->u32Length==0))
6808 {
6809 // AVI NULL packet.
6810 pstSlqTblInfo->u32DummyPktCnt++;
6811 //printf("Pos:0x%x%08x; PTS:%08d; NullPKT:%d\n", pInfo->u32ID_H, pInfo->u32ID_L, pInfo->u32TimeStamp, pstSlqTblInfo->u32DummyPktCnt);
6812 return E_MVD_RET_OK;
6813 }
6814
6815 if (FALSE == (HAL_MVD_IsMStreamerMode(u8Idx) ||HAL_MVD_IsMcuMode(u8Idx)))
6816 { //Check repeat PTS for non-MStreamer/Mcu mode.
6817 //printf(".Pos:0x%x%08x; PTS:%08d; NullPKT:%d\n", pInfo->u32ID_H, pInfo->u32ID_L, pInfo->u32TimeStamp, pstSlqTblInfo->u32DummyPktCnt);
6818 if (pInfo->u32TimeStamp == pstSlqTblInfo->u32LastPts)
6819 {
6820 //printf("Repeat PTS!\n");
6821 if (pInfo->u32TimeStamp != MVD_NULLPKT_PTS)
6822 pInfo->u32TimeStamp = MVD_NULLPKT_PTS; //repeat PTS
6823 }
6824 else
6825 {
6826 pstSlqTblInfo->u32LastPts = pInfo->u32TimeStamp;
6827 }
6828 }
6829
6830 //check queue vacancy
6831 if (pstSlqTblInfo->pDrvSlqTbl->u32Empty >= SLQ_TBL_SAFERANGE)
6832 { //put packets
6833 #if SLQ_NEW_PUSH
6834 if (E_MVD_CODEC_DIVX311 == curCodecType
6835 ||E_MVD_CODEC_VC1_MAIN == curCodecType //rcv
6836 ||E_MVD_CODEC_VC1_ADV == curCodecType)
6837 {
6838 MVD_PacketInfo stHdr;
6839 if((pstSlqTblInfo->pSlqStatus->bSlqCtrlBit) || (E_MVD_CODEC_DIVX311 == curCodecType))
6840 {
6841 MVD_SLQTblGetHdrPkt(u8Idx, &stHdr, pInfo);
6842
6843 if(pstSlqTblInfo->pSlqStatus->bSlqPicStart||(!pstSlqTblInfo->pSlqStatus->bSlqCtrlBit))
6844 {
6845 if (HAL_MVD_IsMStreamerMode(u8Idx) || HAL_MVD_IsMcuMode(u8Idx))
6846 { //to mark this packet's pts as unused.
6847 stHdr.u32TimeStamp = MVD_NULLPKT_PTS;
6848 stHdr.u32ID_H = MVD_NULLPKT_PTS;
6849 }
6850 #ifdef VDEC3
6851 if(pstCtrlCfg->u8McuMode == TRUE)
6852 {
6853 if(HAL_VPU_EX_GetVBBUVacancy(u32VBBUAddr) > 1)
6854 {
6855 HAL_VPU_EX_PacketInfo stVpuPkt;
6856
6857 stVpuPkt.u32Offset = stHdr.u32StAddr;
6858 stVpuPkt.u32Length = stHdr.u32Length;
6859 stVpuPkt.u64TimeStamp = (MS_U64)stHdr.u32TimeStamp;
6860 //If in display queue mode
6861 stVpuPkt.u64TimeStamp |= ((MS_U64)stHdr.u32ID_H << 32);
6862 stVpuPkt.u32ID_H = stHdr.u32ID_H;
6863 stVpuPkt.u32ID_L = stHdr.u32ID_L;
6864
6865 pstSlqTblInfo->bSlqTblHasValidData = TRUE;
6866 eRet = (E_MVD_Result)HAL_VPU_EX_Push2VBBU(u32Id, &stVpuPkt, u32VBBUAddr);
6867 }
6868 else
6869 {
6870 return E_MVD_RET_FAIL;
6871 }
6872 }
6873 else
6874 #endif
6875 {
6876 HAL_MVD_SLQTblSendPacket(u8Idx, &stHdr);
6877 }
6878 }
6879 }
6880 }
6881 #else
6882 if (E_MVD_CODEC_DIVX311 == curCodecType)
6883 {
6884 MVD_PacketInfo stDivxHdr;
6885 MVD_SLQTblGetDivxHdrPkt(u8Idx, &stDivxHdr, pInfo);
6886 if (HAL_MVD_IsMStreamerMode(u8Idx) || HAL_MVD_IsMcuMode(u8Idx))
6887 { //to mark this packet's pts as unused.
6888 stDivxHdr.u32TimeStamp = MVD_NULLPKT_PTS;
6889 stDivxHdr.u32ID_H = MVD_NULLPKT_PTS;
6890 }
6891 HAL_MVD_SLQTblSendPacket(u8Idx, &stDivxHdr);
6892 }
6893 #endif
6894
6895 #ifdef VDEC3
6896 if(pstCtrlCfg->u8McuMode == TRUE)
6897 {
6898 if(HAL_VPU_EX_GetVBBUVacancy(u32VBBUAddr) > 0)
6899 {
6900 HAL_VPU_EX_PacketInfo stVpuPkt;
6901
6902 stVpuPkt.u32Offset = pInfo->u32StAddr;
6903 stVpuPkt.u32Length = pInfo->u32Length;
6904 stVpuPkt.u64TimeStamp = (MS_U64)pInfo->u32TimeStamp;
6905 //If in display queue mode
6906 stVpuPkt.u64TimeStamp |= ((MS_U64)pInfo->u32ID_H << 32);
6907 stVpuPkt.u32ID_H = pInfo->u32ID_H;
6908 stVpuPkt.u32ID_L = pInfo->u32ID_L;
6909
6910 pstSlqTblInfo->bSlqTblHasValidData = TRUE;
6911 eRet = (E_MVD_Result)HAL_VPU_EX_Push2VBBU(u32Id, &stVpuPkt, u32VBBUAddr);
6912 //VPRINTF("[%d]%s[%d],ret=%d,u32StAddr %x,u32Length %d,u32TimeStamp %d\n",u8Idx,__FUNCTION__,__LINE__,eRet,(unsigned int)pInfo->u32StAddr,(unsigned int)pInfo->u32Length,(unsigned int)pInfo->u32TimeStamp);
6913 return eRet;
6914 }
6915 else
6916 {
6917 return E_MVD_RET_FAIL;
6918 }
6919 }
6920 else
6921 #endif
6922 {
6923 HAL_MVD_SLQTblSendPacket(u8Idx, pInfo);
6924 eRet=E_MVD_RET_OK;
6925 pstSlqTblInfo->bSlqTblHasValidData = TRUE;
6926 }
6927 }
6928 else
6929 {
6930 MS_ASSERT(0); //shouldn't be here!
6931 MVD_DEBUGERROR(printf("PushQueue FULL!!! empty=0x%lx\n", (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32Empty));
6932 //Player will only push queue when queue vacancy != 0
6933 eRet=E_MVD_RET_QUEUE_FULL;
6934 }
6935
6936 if (E_MVD_RET_OK != eRet)
6937 {
6938 MVD_DEBUGERROR(printf("%s ret = %d\n", __FUNCTION__, eRet));
6939 }
6940 return eRet;
6941 }
6942
6943
MVD_FlushTSQueue(MS_U8 u8Idx)6944 static E_MVD_Result MVD_FlushTSQueue(MS_U8 u8Idx)
6945 {
6946 if (HAL_MVD_GetLastCmd(u8Idx)!=CMD_PAUSE)
6947 {
6948 HAL_MVD_PauseDisp(u8Idx);
6949 HAL_MVD_DecodePause(u8Idx);
6950 HAL_MVD_FlushDisplayBuf(u8Idx);
6951 }
6952
6953 if(HAL_MVD_SkipData(u8Idx) == FALSE)
6954 {
6955 return E_MVD_RET_FAIL;
6956 }
6957 else
6958 {
6959 return E_MVD_RET_OK;
6960 }
6961 }
6962
6963
MVD_PatternLenIsValid(MS_U8 u8Idx,MS_U32 u32Len)6964 static MS_BOOL MVD_PatternLenIsValid(MS_U8 u8Idx, MS_U32 u32Len)
6965 {
6966 MS_U32 u32ValidLen = 0;
6967 MVD_CodecType curCodecType = HAL_MVD_GetCodecType(u8Idx);
6968 #define MAX_VALIDLEN 0x200000 //2M
6969
6970 if (E_MVD_CODEC_VC1_MAIN != curCodecType)
6971 {
6972 return TRUE;
6973 }
6974 else
6975 {
6976 //only RCV has to check this
6977 u32ValidLen = HAL_MVD_GetPayloadLen(u8Idx);
6978 if (u32ValidLen > MAX_VALIDLEN)
6979 { //avoid the extreme large value due to error bitstream
6980 u32ValidLen = MAX_VALIDLEN;
6981 }
6982 MVD_DEBUGINFO(printf("(%x) ValidLen=0x%x CurLen=0x%x\n",
6983 (u32Len > u32ValidLen), u32ValidLen, u32Len));
6984 return (u32Len > u32ValidLen);
6985 }
6986 }
6987
MVD_FlushSlqTblQueue(MS_U8 u8Idx)6988 static E_MVD_Result MVD_FlushSlqTblQueue(MS_U8 u8Idx)
6989 {
6990 MS_U32 u32TimeCnt;
6991 MS_U32 u32PatternByteCnt = 0;
6992 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
6993 MS_U32 u32Id = MVD_GetStreamId(u8Idx);
6994 MS_U8 u8VPUIdx = HAL_VPU_EX_GetTaskId(u32Id);
6995 #ifdef VDEC3
6996 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
6997 MS_VIRT u32VBBUAddr = HAL_MVD_GetVBBUTableAddr(u8VPUIdx);
6998 #endif
6999 HAL_MVD_ResetHandShake(u8Idx,MVD_HANDSHAKE_PAUSE);
7000 HAL_MVD_PauseDisp(u8Idx);
7001 HAL_MVD_DecodePause(u8Idx);
7002 HAL_MVD_FlushDisplayBuf(u8Idx);
7003
7004 u32TimeCnt = HAL_MVD_GetTime();
7005 while (((HAL_MVD_GetTime() - u32TimeCnt) < CMD_TIMEOUT_MS) ||
7006 (TRUE != MVD_PatternLenIsValid(u8Idx, u32PatternByteCnt)))
7007 {
7008 if (HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_PAUSE))
7009 {
7010 MVD_DEBUGINFO(printf("\nPause finished!\n"));
7011 break;
7012 }
7013
7014 #ifdef VDEC3
7015 if(pstCtrlCfg->u8McuMode == TRUE)
7016 {
7017 if(HAL_VPU_EX_GetVBBUVacancy(u32VBBUAddr) > 0)
7018 {
7019 HAL_VPU_EX_PacketInfo stVpuPkt;
7020 MVD_PacketInfo stDummyPkt;
7021 MVD_SLQTblGetDummyPkt(&stDummyPkt);
7022
7023 stVpuPkt.u32Offset = stDummyPkt.u32StAddr;
7024 stVpuPkt.u32Length = stDummyPkt.u32Length;
7025 stVpuPkt.u64TimeStamp = (MS_U64)stDummyPkt.u32TimeStamp;
7026 //If in display queue mode
7027 stVpuPkt.u64TimeStamp |= ((MS_U64)stDummyPkt.u32ID_H << 32);
7028 stVpuPkt.u32ID_H = stDummyPkt.u32ID_H;
7029 stVpuPkt.u32ID_L = stDummyPkt.u32ID_L;
7030
7031 HAL_VPU_EX_Push2VBBU(u32Id, &stVpuPkt,u32VBBUAddr);
7032 }
7033 }
7034 else
7035 #endif
7036 {
7037 if (pstSlqTblInfo->pDrvSlqTbl->u32Empty < SLQ_TBL_SAFERANGE)
7038 {
7039 HAL_MVD_GetQueueVacancy(u8Idx, FALSE); //update pstSlqTblInfo->pDrvSlqTbl->u32Empty
7040 HAL_MVD_Delayms(1); //avoid busy query
7041 }
7042 //insert dummy pattern
7043 if (TRUE == HAL_MVD_SLQTblInsertPattern(u8Idx, E_MVD_PATTERN_FLUSH))
7044 {
7045 u32PatternByteCnt += DUMMY_SIZE*2; //2 dummy were inserted
7046 }
7047 }
7048
7049
7050 //Timeout for RCV
7051 if ((HAL_MVD_GetTime() - u32TimeCnt) > (CMD_TIMEOUT_MS*10))
7052 {
7053 MVD_DEBUGERROR(printf("RCV timeout!!! pl=%d, pbc=%d, emp=%ld\n",
7054 HAL_MVD_GetPayloadLen(u8Idx), u32PatternByteCnt,
7055 (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32Empty));
7056 break;
7057 }
7058 }
7059 MVD_DEBUGINFO(printf("====> %s (t1=%u t2=%u diff=%u)\n", __FUNCTION__,
7060 u32TimeCnt, HAL_MVD_GetTime(), (HAL_MVD_GetTime() - u32TimeCnt)));
7061 //if ((HAL_MVD_GetTime() - u32TimeCnt) >= CMD_TIMEOUT_MS)
7062 if (TRUE != HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_PAUSE))
7063 {
7064 MVD_DEBUGERROR(printf("\n***** MDrv_MVD_FlushQueue PAUSE TIMEOUT!!! *****\n\n"));
7065 MVD_DEBUGERROR(printf("ValidLen=0x%x CurPatternLen=0x%x\n",
7066 HAL_MVD_GetPayloadLen(u8Idx), u32PatternByteCnt));
7067
7068 return E_MVD_RET_FAIL;
7069 }
7070
7071 //flush ES buffer & reset SLQ tbl
7072 HAL_MVD_ResetHandShake(u8Idx, MVD_HANDSHAKE_SLQ_RST);
7073 if (HAL_MVD_SlqTblRst(u8Idx) == TRUE)
7074 {
7075 //return E_MVD_RET_OK;
7076 }
7077
7078 u32TimeCnt = HAL_MVD_GetTime();
7079 while (((HAL_MVD_GetTime() - u32TimeCnt) < CMD_TIMEOUT_MS))
7080 {
7081 if (HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_SLQ_RST))
7082 {
7083 MVD_DEBUGINFO(printf("\nSlqRst finished!\n"));
7084 break;
7085 }
7086 }
7087 MVD_DEBUGINFO(printf("====> %s (t1=%u t2=%u diff=%u)\n", __FUNCTION__,
7088 u32TimeCnt, HAL_MVD_GetTime(), (HAL_MVD_GetTime() - u32TimeCnt)));
7089 if (TRUE != HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_SLQ_RST))
7090 {
7091 MVD_DEBUGERROR(printf("\n***** MDrv_MVD_FlushQueue SlqRst TIMEOUT!!! *****\n\n"));
7092 return E_MVD_RET_FAIL;
7093 }
7094
7095 HAL_MVD_SLQTblInit(u8Idx); //reset related buffers
7096
7097 return E_MVD_RET_OK;
7098 }
7099
HAL_MVD_FlushQueue(MS_U8 u8Idx)7100 E_MVD_Result HAL_MVD_FlushQueue(MS_U8 u8Idx)
7101 {
7102 E_MVD_Result eRet = E_MVD_RET_OK;
7103 MVD_SrcMode curSrcMode = HAL_MVD_GetSrcMode(u8Idx);
7104
7105 if (HAL_MVD_GetDecodeStatus(u8Idx) == E_MVD_STAT_IDLE)
7106 {
7107 return eRet;
7108 }
7109
7110 //flush ES buffer (and cmd queue if used)
7111 if (E_MVD_SLQ_TBL_MODE == curSrcMode)
7112 {
7113 eRet = MVD_FlushSlqTblQueue(u8Idx);
7114 }
7115 else if (E_MVD_TS_FILE_MODE == curSrcMode)
7116 {
7117 eRet = MVD_FlushTSQueue(u8Idx);
7118 }
7119 if (E_MVD_RET_OK != eRet)
7120 {
7121 return eRet;
7122 }
7123
7124 MVD_RstFrmInfo(u8Idx, E_MVD_FRMINFO_DECODE);
7125 //flush display buffer
7126
7127 if (HAL_MVD_FlushDisplayBuf(u8Idx) != TRUE)
7128 {
7129 return E_MVD_RET_FAIL;
7130 }
7131
7132 if (TRUE == HAL_MVD_SkipToIFrame(u8Idx))
7133 {
7134 return E_MVD_RET_OK;
7135 }
7136 else
7137 {
7138 return E_MVD_RET_FAIL;
7139 }
7140 }
7141
HAL_MVD_IsAllBufferEmpty(MS_U8 u8Idx)7142 MS_BOOL HAL_MVD_IsAllBufferEmpty(MS_U8 u8Idx)
7143 {
7144 return HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_SKIP_DATA);
7145 }
7146
HAL_MVD_EnableInt(MS_U8 u8Idx,MS_U32 bEn)7147 MS_BOOL HAL_MVD_EnableInt(MS_U8 u8Idx, MS_U32 bEn)
7148 {
7149 MVD_CmdArg mvdcmd;
7150 MS_U32 u32IntFlag = 0;
7151
7152 u32IntFlag = (((bEn & E_MVD_EVENT_USER_DATA) == E_MVD_EVENT_USER_DATA) ? INT_USER_DATA : 0) |
7153 (((bEn & E_MVD_EVENT_USER_DATA_DISP) == E_MVD_EVENT_USER_DATA_DISP) ? INT_USER_DATA_DISP : 0) |
7154 (((bEn & E_MVD_EVENT_PIC_FOUND) == E_MVD_EVENT_PIC_FOUND) ? INT_PIC_FOUND : 0) |
7155 (((bEn & E_MVD_EVENT_FIRST_FRAME) == E_MVD_EVENT_FIRST_FRAME) ? INT_FIRST_FRAME : 0) |
7156 (((bEn & E_MVD_EVENT_DISP_RDY) == E_MVD_EVENT_DISP_RDY) ? INT_DISP_RDY : 0) |
7157 (((bEn & E_MVD_EVENT_SEQ_FOUND) == E_MVD_EVENT_SEQ_FOUND) ? INT_SEQ_FOUND : 0)|
7158 (((bEn & E_MVD_EVENT_DEC_ONE_FRAME) == E_MVD_EVENT_DEC_ONE_FRAME) ? INT_DEC_DONE : 0)|
7159 (((bEn & E_MVD_EVENT_DEC_ERR) == E_MVD_EVENT_DEC_ERR) ? INT_DEC_ERR : 0)|
7160 (((bEn & E_MVD_EVENT_DEC_DATA_ERR) == E_MVD_EVENT_DEC_DATA_ERR) ? INT_VES_INVALID : 0)|
7161 (((bEn & E_MVD_EVENT_XC_LOW_DEALY) == E_MVD_EVENT_XC_LOW_DEALY) ? INT_XC_LOW_DELAY : 0)|
7162 (((bEn & E_MVD_EVENT_DEC_I) == E_MVD_EVENT_DEC_I) ? INT_DEC_I : 0);
7163 if (((bEn & E_MVD_EVENT_DISP_VSYNC) == E_MVD_EVENT_DISP_VSYNC) ||
7164 ((bEn & E_MVD_EVENT_UNMUTE) == E_MVD_EVENT_UNMUTE))
7165 {
7166 u32IntFlag |= INT_DISP_VSYNC;
7167 }
7168
7169 MVD_DEBUGINFO(printf("u32IntFlag = 0x%x\n", u32IntFlag));
7170 SETUP_CMDARG(mvdcmd);
7171 mvdcmd.Arg0 = u32IntFlag & 0xff;
7172 mvdcmd.Arg1 = (u32IntFlag>>8) & 0xff;
7173 mvdcmd.Arg2 = (u32IntFlag>>16) & 0xff;
7174 SET_DECNUM(mvdcmd, u8Idx);
7175 SET_CMD_RET_FALSE(CMD_ENABLE_INT_STAT, &mvdcmd);
7176
7177 return TRUE;
7178 }
7179
HAL_MVD_EnablePTSDetector(MS_U8 u8Idx,MS_BOOL bEn)7180 E_MVD_Result HAL_MVD_EnablePTSDetector(MS_U8 u8Idx, MS_BOOL bEn)
7181 {
7182 MVD_CmdArg stCmdArg;
7183
7184 SETUP_CMDARG(stCmdArg);
7185 if(TRUE == bEn)
7186 {
7187 stCmdArg.Arg0 = 1;
7188 }
7189 SET_DECNUM(stCmdArg, u8Idx);
7190 if (HAL_MVD_MVDCommand(CMD_PTS_DETECTOR_EN, &stCmdArg) == FALSE)
7191 {
7192 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PTS_DETECTOR_EN ) );
7193 return E_MVD_RET_FAIL;
7194 }
7195 return E_MVD_RET_OK;
7196 }
7197
HAL_MVD_DisablePBFrameMode(MS_U8 u8Idx,MS_BOOL bEn)7198 E_MVD_Result HAL_MVD_DisablePBFrameMode(MS_U8 u8Idx, MS_BOOL bEn)
7199 {
7200 MVD_CmdArg stCmdArg;
7201
7202 SETUP_CMDARG(stCmdArg);
7203 if(TRUE == bEn)
7204 {
7205 stCmdArg.Arg0 = 1;
7206 }
7207 SET_DECNUM(stCmdArg, u8Idx);
7208 if (HAL_MVD_MVDCommand(CMD_DISABLE_PATCH_PBFRAME, &stCmdArg) == FALSE)
7209 {
7210 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PTS_DETECTOR_EN ) );
7211 return E_MVD_RET_FAIL;
7212 }
7213 return E_MVD_RET_OK;
7214 }
7215
HAL_MVD_EnableDispOneField(MS_U8 u8Idx,MS_BOOL bEn)7216 E_MVD_Result HAL_MVD_EnableDispOneField(MS_U8 u8Idx, MS_BOOL bEn)
7217 {
7218 MVD_CmdArg stCmdArg;
7219
7220 SETUP_CMDARG(stCmdArg);
7221 if(TRUE == bEn)
7222 {
7223 stCmdArg.Arg0 = 1;
7224 }
7225 SET_DECNUM(stCmdArg, u8Idx);
7226 if (HAL_MVD_MVDCommand(CMD_SHOW_ONE_FIELD, &stCmdArg) == FALSE)
7227 {
7228 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SHOW_ONE_FIELD ) );
7229 return E_MVD_RET_FAIL;
7230 }
7231 return E_MVD_RET_OK;
7232 }
7233
HAL_MVD_SetFdMaskDelayCount(MS_U8 u8Idx,MS_U16 u16Cnt)7234 E_MVD_Result HAL_MVD_SetFdMaskDelayCount(MS_U8 u8Idx, MS_U16 u16Cnt)
7235 {
7236 MVD_CmdArg stCmdArg;
7237
7238 SETUP_CMDARG(stCmdArg);
7239 //16bits and unit in vsync for mute the fd_mask
7240 stCmdArg.Arg0 = u16Cnt & 0xff;
7241 stCmdArg.Arg1 = (u16Cnt>>8) & 0xff;
7242 SET_DECNUM(stCmdArg, u8Idx);
7243 if (HAL_MVD_MVDCommand(CMD_FD_MASK_DELAY_CNT, &stCmdArg) == FALSE)
7244 {
7245 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FD_MASK_DELAY_CNT ) );
7246 return E_MVD_RET_FAIL;
7247 }
7248 return E_MVD_RET_OK;
7249 }
7250
HAL_MVD_SetOutputFRCMode(MS_U8 u8Idx,MS_U8 u8FrameRate,MS_U8 u8Interlace)7251 E_MVD_Result HAL_MVD_SetOutputFRCMode(MS_U8 u8Idx, MS_U8 u8FrameRate, MS_U8 u8Interlace)
7252 {
7253 MVD_CmdArg stCmdArg;
7254 if((u8Interlace != 0) && (u8Interlace != 1))
7255 {
7256 return E_MVD_RET_FAIL;
7257 }
7258 SETUP_CMDARG(stCmdArg);
7259 stCmdArg.Arg0 = u8FrameRate;
7260 stCmdArg.Arg1 = u8Interlace;
7261 SET_DECNUM(stCmdArg, u8Idx);
7262 if (HAL_MVD_MVDCommand(CMD_FRC_OUPUT, &stCmdArg) == FALSE)
7263 {
7264 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FRC_OUPUT ) );
7265 return E_MVD_RET_FAIL;
7266 }
7267 return E_MVD_RET_OK;
7268 }
7269
7270
HAL_MVD_SetFRCDropType(MS_U8 u8Idx,MS_U8 u8DropType)7271 E_MVD_Result HAL_MVD_SetFRCDropType(MS_U8 u8Idx, MS_U8 u8DropType)
7272 {
7273 MVD_CmdArg stCmdArg;
7274
7275 if((u8DropType != FRC_DROP_FRAME)
7276 && (u8DropType != FRC_DROP_FIELD))
7277 {
7278 return E_MVD_RET_FAIL;
7279 }
7280
7281 SETUP_CMDARG(stCmdArg);
7282 stCmdArg.Arg0 = u8DropType;
7283 SET_DECNUM(stCmdArg, u8Idx);
7284 if (HAL_MVD_MVDCommand(CMD_FRC_DROP_BEHAVIOR, &stCmdArg) == FALSE)
7285 {
7286 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FRC_DROP_BEHAVIOR ) );
7287 return E_MVD_RET_FAIL;
7288 }
7289 return E_MVD_RET_OK;
7290 }
7291
HAL_MVD_SetDisableSeqChange(MS_U8 u8Idx,MS_BOOL bEnable)7292 E_MVD_Result HAL_MVD_SetDisableSeqChange(MS_U8 u8Idx, MS_BOOL bEnable)
7293 {
7294 MVD_CmdArg stCmdArg;
7295
7296 SETUP_CMDARG(stCmdArg);
7297 stCmdArg.Arg0 = bEnable;
7298 SET_DECNUM(stCmdArg, u8Idx);
7299 if (HAL_MVD_MVDCommand(CMD_FORBID_RESOLUTION_CHANGE, &stCmdArg) == FALSE)
7300 {
7301 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FORBID_RESOLUTION_CHANGE ) );
7302 return E_MVD_RET_FAIL;
7303 }
7304 MVD_DEBUGINFO(printf("MVD CMD_FORBID_RESOLUTION_CHANGE(0x%x) OK\n", bEnable));
7305
7306 return E_MVD_RET_OK;
7307 }
7308
HAL_MVD_DbgGetData(MS_VIRT u32Addr,MS_U32 * u32Data)7309 E_MVD_Result HAL_MVD_DbgGetData(MS_VIRT u32Addr, MS_U32* u32Data)
7310 {
7311 MVD_CmdArg mvdcmd;
7312 MS_U32 u32Val;
7313
7314 if (!u32Data)
7315 {
7316 return E_MVD_RET_INVALID_PARAM;
7317 }
7318
7319 SET_CMDARG(mvdcmd, u32Addr, 0); //FIXME
7320 if (HAL_MVD_MVDCommand( CMD_RD_IO, &mvdcmd ) == FALSE)
7321 {
7322 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_RD_IO ) );
7323 return E_MVD_RET_FAIL;
7324 }
7325
7326 u32Val = (((MS_U32)mvdcmd.Arg2)) | ((MS_U32)mvdcmd.Arg3 << 8) |
7327 (((MS_U32)mvdcmd.Arg4) << 16) | (((MS_U32)mvdcmd.Arg5) << 24);
7328 *u32Data = u32Val;
7329
7330 return E_MVD_RET_OK;
7331 }
7332
7333
HAL_MVD_DbgDumpBits(MS_U8 u8Idx,MS_PHY u32base,MS_U32 u32size)7334 void HAL_MVD_DbgDumpBits(MS_U8 u8Idx, MS_PHY u32base, MS_U32 u32size)
7335 {
7336 MVD_CmdArg mvdcmd;
7337
7338 u32base = HAL_MVD_GetMemOffset(u32base);
7339 printf("%s base=0x%lx size=0x%x\n", __FUNCTION__, (unsigned long)u32base, u32size);
7340 MS_ASSERT((u32base%8)==0);
7341 u32base >>= 3;
7342 SET_CMDARG(mvdcmd, u32base, u8Idx);
7343 if (HAL_MVD_MVDCommand( CMD_DUMP_BITSTREAM_BASE, &mvdcmd ) == FALSE)
7344 {
7345 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\n", CMD_DUMP_BITSTREAM_BASE ) );
7346 return;
7347 }
7348
7349 MS_ASSERT((u32size%8)==0);
7350 u32size >>= 3;
7351 SET_CMDARG(mvdcmd, u32size, u8Idx);
7352 if (HAL_MVD_MVDCommand( CMD_DUMP_BITSTREAM_LENGTH, &mvdcmd ) == FALSE)
7353 {
7354 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\n", CMD_DUMP_BITSTREAM_LENGTH ) );
7355 return;
7356 }
7357 return;
7358 }
7359
7360
HAL_MVD_GetActiveFormat(MS_U8 u8Idx)7361 MS_U8 HAL_MVD_GetActiveFormat(MS_U8 u8Idx)
7362 {
7363 MVD_CmdArg mvdcmd;
7364 MS_U8 u8Afd = 0;
7365
7366 SETUP_CMDARG(mvdcmd);
7367 SET_DECNUM(mvdcmd, u8Idx);
7368 if (HAL_MVD_MVDCommand( CMD_GET_AFD, &mvdcmd ) == FALSE)
7369 {
7370 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_GET_AFD ) );
7371 return 0xff;
7372 }
7373 u8Afd = mvdcmd.Arg0;
7374 return u8Afd;
7375 }
7376
HAL_MVD_EnableAVSync(MS_U8 u8Idx,MS_BOOL bEnable)7377 MS_BOOL HAL_MVD_EnableAVSync(MS_U8 u8Idx, MS_BOOL bEnable)
7378 {
7379 MVD_CmdArg mvdcmd;
7380 SETUP_CMDARG(mvdcmd);
7381 mvdcmd.Arg0 = bEnable;
7382 SET_DECNUM(mvdcmd, u8Idx);
7383 SET_CMD_RET_FALSE(CMD_SYNC_ON, &mvdcmd);
7384
7385 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
7386 pCtrlCfg->bAVSyncOn = bEnable;
7387
7388 return TRUE;
7389 }
7390
HAL_MVD_SetAVSyncDelay(MS_U8 u8Idx,MS_U32 u32Delay)7391 MS_BOOL HAL_MVD_SetAVSyncDelay(MS_U8 u8Idx, MS_U32 u32Delay)
7392 {
7393 MVD_CmdArg mvdcmd;
7394 SET_CMDARG(mvdcmd, _MS_TO_90K(u32Delay), u8Idx); //u32Delay ms ==> 90k counter
7395 SET_CMD_RET_FALSE(CMD_SYNC_OFFSET, &mvdcmd);
7396 return TRUE;
7397 }
7398
HAL_MVD_SetAVSyncThreshold(MS_U8 u8Idx,MS_U32 u32Th)7399 MS_BOOL HAL_MVD_SetAVSyncThreshold(MS_U8 u8Idx, MS_U32 u32Th)
7400 {
7401 MVD_CmdArg mvdcmd;
7402
7403 if (u32Th == 0x00)
7404 {
7405 return FALSE; //invalid parameter, do nothing
7406 }
7407 if (u32Th > 0xff)
7408 {
7409 u32Th = 0xff; //set to maximum
7410 }
7411
7412 SETUP_CMDARG(mvdcmd);
7413 mvdcmd.Arg3 = u32Th;
7414 SET_DECNUM(mvdcmd, u8Idx);
7415 SET_CMD_RET_FALSE(CMD_SYN_THRESHOLD, &mvdcmd);
7416 return TRUE;
7417 }
7418
HAL_MVD_SetAVSyncFreerunThreshold(MS_U8 u8Idx,MS_U32 u32Th)7419 MS_BOOL HAL_MVD_SetAVSyncFreerunThreshold(MS_U8 u8Idx, MS_U32 u32Th)
7420 {
7421 MVD_CmdArg mvdcmd;
7422 SET_CMDARG(mvdcmd, u32Th, u8Idx);
7423 SET_CMD_RET_FALSE(CMD_AVSYNC_FREERUN_THRESHOLD, &mvdcmd);
7424 return TRUE;
7425 }
7426
HAL_MVD_ChangeAVsync(MS_U8 u8Idx,MS_BOOL bEnable,MS_U16 u16PTS)7427 MS_BOOL HAL_MVD_ChangeAVsync(MS_U8 u8Idx, MS_BOOL bEnable, MS_U16 u16PTS)
7428 {
7429 MVD_CmdArg mvdcmd;
7430
7431 u16PTS = _MS_TO_90K(u16PTS); //u16PTS ms ==> 90k counter
7432 SETUP_CMDARG(mvdcmd);
7433 mvdcmd.Arg0 = (MS_U8)bEnable;
7434 mvdcmd.Arg1 = 0;
7435 mvdcmd.Arg2 = (MS_U8)(u16PTS&0xff);
7436 mvdcmd.Arg3 = (MS_U8)((u16PTS&0xff00)>>8);
7437 SET_DECNUM(mvdcmd, u8Idx);
7438 SET_CMD_RET_FALSE(CMD_MVD_FAST_INT, &mvdcmd);
7439 return TRUE;
7440 }
7441
HAL_MVD_GetIsSyncRep(MS_U8 u8Idx)7442 MS_BOOL HAL_MVD_GetIsSyncRep(MS_U8 u8Idx)
7443 {
7444 MS_U32 u32IntStat = 0;
7445 MS_BOOL bRet = FALSE;
7446
7447 u32IntStat = HAL_MVD_GetIntState(u8Idx);
7448 if (u32IntStat != 0)
7449 {
7450 bRet = ((u32IntStat&INT_SYN_REP)==INT_SYN_REP) ? TRUE : FALSE;
7451 }
7452 return bRet;
7453 }
7454
HAL_MVD_GetIsSyncSkip(MS_U8 u8Idx)7455 MS_BOOL HAL_MVD_GetIsSyncSkip(MS_U8 u8Idx)
7456 {
7457 MS_U32 u32IntStat = 0;
7458 MS_BOOL bRet = FALSE;
7459
7460 u32IntStat = HAL_MVD_GetIntState(u8Idx);
7461 if (u32IntStat != 0)
7462 {
7463 bRet = ((u32IntStat&INT_SYN_SKIP)==INT_SYN_SKIP) ? TRUE : FALSE;
7464 }
7465
7466 return bRet;
7467 }
7468
HAL_MVD_GetIsSyncReach(MS_U8 u8Idx)7469 MS_U8 HAL_MVD_GetIsSyncReach(MS_U8 u8Idx)
7470 {
7471 #define MVD_SYNC_DONE 1
7472 if(MVD_GetSyncStat(u8Idx, 1) == MVD_SYNC_DONE)
7473 return 1;
7474 else
7475 return 0xFF;
7476 }
7477
HAL_MVD_GetDispRdy(MS_U8 u8Idx)7478 MS_U8 HAL_MVD_GetDispRdy(MS_U8 u8Idx)
7479 {
7480 if (HAL_MVD_GetPicCounter(u8Idx) > 0)
7481 {
7482 return 1;
7483 }
7484 else
7485 {
7486 return 0;
7487 }
7488 }
7489
HAL_MVD_GetDecodeStatus(MS_U8 u8Idx)7490 MVD_DecStat HAL_MVD_GetDecodeStatus(MS_U8 u8Idx)
7491 {
7492 MVD_CmdArg mvdcmd;
7493 MVD_DecStat stat = E_MVD_STAT_UNKNOWN;
7494
7495 SETUP_CMDARG(mvdcmd);
7496 SET_DECNUM(mvdcmd, u8Idx);
7497 if (HAL_MVD_MVDCommand(CMD_DECODE_STATUS, &mvdcmd) == FALSE)
7498 {
7499 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DECODE_STATUS ) );
7500 return E_MVD_STAT_UNKNOWN;
7501 }
7502
7503 switch(mvdcmd.Arg1)
7504 {
7505 case DEC_STAT_IDLE:
7506 stat = E_MVD_STAT_IDLE;
7507 break;
7508 case DEC_STAT_FIND_SC:
7509 stat = E_MVD_STAT_FIND_STARTCODE;
7510 break;
7511 case DEC_STAT_FIND_SPE_SC:
7512 stat = E_MVD_STAT_FIND_SPECIALCODE;
7513 break;
7514 case DEC_STAT_FIND_FRAMEBUFFER:
7515 stat = E_MVD_STAT_FIND_FRAMEBUFFER;
7516 break;
7517 case DEC_STAT_WAIT_DECODE_DONE:
7518 stat = E_MVD_STAT_WAIT_DECODEDONE;
7519 break;
7520 case DEC_STAT_DECODE_DONE:
7521 stat = E_MVD_STAT_DECODE_DONE;
7522 break;
7523 case DEC_STAT_WAIT_VDFIFO:
7524 stat = E_MVD_STAT_WAIT_VDFIFO;
7525 break;
7526 case DEC_STAT_INIT_SUCCESS:
7527 stat = E_MVD_STAT_INIT_SUCCESS;
7528 break;
7529 default:
7530 break;
7531 }
7532
7533 return stat;
7534 }
7535
HAL_MVD_GetLastCmd(MS_U8 u8Idx)7536 MS_U8 HAL_MVD_GetLastCmd(MS_U8 u8Idx)
7537 {
7538 MVD_CmdArg mvdcmd;
7539 SETUP_CMDARG(mvdcmd);
7540 SET_DECNUM(mvdcmd, u8Idx);
7541 if (HAL_MVD_MVDCommand( CMD_DECODE_STATUS, &mvdcmd ) == FALSE)
7542 {
7543 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DECODE_STATUS ) );
7544 return 0xff;
7545 }
7546
7547 return (mvdcmd.Arg0);
7548 }
7549
HAL_MVD_GetParserByteCnt(MS_U8 u8Idx)7550 MS_U32 HAL_MVD_GetParserByteCnt(MS_U8 u8Idx)
7551 {
7552 MVD_CmdArg mvdcmd;
7553 MS_U32 u32Cnt = 0;
7554
7555 SETUP_CMDARG(mvdcmd);
7556
7557 //To be accurate, it's "VLD byte count", instead of "parser byte count".
7558 mvdcmd.Arg0 = 0x34;
7559 mvdcmd.Arg1 = 0x2;
7560 SET_DECNUM(mvdcmd, u8Idx);
7561 if (HAL_MVD_MVDCommand( CMD_RD_IO, &mvdcmd ) == FALSE)
7562 {
7563 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_RD_IO ) );
7564 return 0;
7565 }
7566 u32Cnt = (((MS_U32)mvdcmd.Arg2)) | ((MS_U32)mvdcmd.Arg3 << 8) |
7567 (((MS_U32)mvdcmd.Arg4) << 16) | (((MS_U32)mvdcmd.Arg5) << 24);
7568
7569 //printf(" parser byte count = %lu byte \n", u32Cnt);
7570 return u32Cnt;
7571 }
7572
HAL_MVD_DropErrorFrame(MS_U8 u8Idx,MS_BOOL bDrop)7573 MS_BOOL HAL_MVD_DropErrorFrame(MS_U8 u8Idx, MS_BOOL bDrop)
7574 {
7575 MVD_CmdArg mvdcmd;
7576 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
7577
7578 SETUP_CMDARG(mvdcmd);
7579 mvdcmd.Arg1 = (MS_U8)bDrop;
7580 mvdcmd.Arg2 = (MS_U8)pstCtrlCfg->bDropDispfrm;
7581 mvdcmd.Arg3 = (MS_U8)pstCtrlCfg->eFrcMode;
7582 SET_DECNUM(mvdcmd, u8Idx);
7583 SET_CMD_RET_FALSE(CMD_DISPLAY_CTL, &mvdcmd);
7584 return TRUE;
7585 }
7586
HAL_MVD_SetDivXCfg(MS_U8 u8Idx,MS_U8 u8MvAdjust,MS_U8 u8IdctSel)7587 void HAL_MVD_SetDivXCfg(MS_U8 u8Idx, MS_U8 u8MvAdjust, MS_U8 u8IdctSel)
7588 {
7589 MVD_CmdArg stCmdArg;
7590
7591 SETUP_CMDARG(stCmdArg);
7592 stCmdArg.Arg0 = u8MvAdjust;
7593 SET_DECNUM(stCmdArg, u8Idx);
7594 if (HAL_MVD_MVDCommand(CMD_DIVX_PATCH, &stCmdArg) == FALSE)
7595 {
7596 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DIVX_PATCH ) );
7597 return;
7598 }
7599
7600 SETUP_CMDARG(stCmdArg);
7601 stCmdArg.Arg0 = u8IdctSel;
7602 SET_DECNUM(stCmdArg, u8Idx);
7603 if (HAL_MVD_MVDCommand(CMD_IDCT_SEL, &stCmdArg) == FALSE)
7604 {
7605 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_IDCT_SEL ) );
7606 return;
7607 }
7608
7609 return;
7610 }
7611
7612 #define _IsNotInStreamBuff(x) \
7613 (((x) < pstMemCfg->u32DrvBufSize) || \
7614 ((x) > pstMemCfg->u32BSSize) )
7615
7616 //------------------------------------------------------------------------------
7617 /// Get read pointer in ElementaryStream buffer for SLQ table mode
7618 /// @return -the read pointer
7619 //------------------------------------------------------------------------------
MVD_GetSlqTblESReadPtr(MS_U8 u8Idx)7620 MS_VIRT MVD_GetSlqTblESReadPtr(MS_U8 u8Idx)
7621 {
7622 MS_U32 u32Idx;
7623 MS_U32 u32SlqRp = 0, u32SlqRp1 = 0;
7624 MS_VIRT u32EsRp;
7625 MS_VIRT u32EsStart;
7626 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
7627 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
7628 MVD_CodecType curCodecType = HAL_MVD_GetCodecType(u8Idx);
7629
7630 u32SlqRp1 = HAL_MVD_GetSLQReadPtr(u8Idx);
7631
7632 if (u32SlqRp1 == 0)
7633 {
7634 return MVD_U32_MAX;
7635 }
7636 else
7637 {
7638 u32SlqRp = HAL_MVD_Map2DrvSlqTbl(u8Idx, u32SlqRp1);
7639 }
7640
7641 pstSlqTblInfo->pDrvSlqTbl->u32RdPtr = u32SlqRp; //update pstSlqTblInfo->pDrvSlqTbl->u32RdPtr
7642
7643 //report (readPtr-1) for HW may still use (readPtr)
7644 if (u32SlqRp > (pstSlqTblInfo->pDrvSlqTbl->u32StAdd))
7645 {
7646 u32Idx = ((u32SlqRp - pstSlqTblInfo->pDrvSlqTbl->u32StAdd)/SLQ_ENTRY_LEN) - 1;
7647 }
7648 else
7649 {
7650 u32Idx = SLQ_ENTRY_MAX - 1;
7651 }
7652 u32EsRp = pstSlqTblInfo->pDrvEsTbl->u32StAdd + u32Idx*8;
7653
7654 u32EsStart = HAL_MVD_MemRead4Byte(u32EsRp); //report StartAdd as read_pointer
7655 #if 0
7656 MS_U32 u32EsEnd;
7657 u32EsEnd = HAL_MVD_MemRead4Byte(u32EsRp+4);
7658 printf("GetESReadPtr ES[%x] Start=0x%x End=0x%x u32EsRp=%x u32SlqRp=%x\n",
7659 u32Idx, HAL_MVD_MemRead4Byte(u32EsRp), u32EsEnd, u32EsRp, u32SlqRp);
7660 #endif
7661
7662 if ((_IsNotInStreamBuff(u32EsStart)) && (u32EsStart != 0))
7663 { //ESRead is not in BS buffer, so this entry is a divx or dummy pattern.
7664 //Report the last ESRead, instead of this one.
7665 if(curCodecType == E_MVD_CODEC_DIVX311)
7666 {
7667 //update last slq index es end address
7668 if(u32Idx == 0)
7669 {
7670 u32Idx = SLQ_ENTRY_MAX-1;
7671 }
7672 else
7673 {
7674 u32Idx = u32Idx-1;
7675 }
7676 u32EsRp = pstSlqTblInfo->pDrvEsTbl->u32StAdd + u32Idx*8;
7677 u32EsStart = HAL_MVD_MemRead4Byte(u32EsRp); //report StartAdd as read_pointer
7678 if(_IsNotInStreamBuff(u32EsStart))
7679 {
7680 return (pstSlqTblInfo->u32PreEsRd);
7681 }
7682 }
7683 else
7684 {
7685 MVD_DEBUGINFO(printf("0x%lx Not in BS, report u32PreEsRd=0x%lx\n", (unsigned long)u32EsStart, (unsigned long)pstSlqTblInfo->u32PreEsRd));
7686 return (pstSlqTblInfo->u32PreEsRd);
7687 }
7688 }
7689 pstSlqTblInfo->u32PreEsRd = u32EsStart;
7690
7691 return u32EsStart;
7692 }
7693
7694 //------------------------------------------------------------------------------
7695 /// Get write pointer in ElementaryStream buffer for SLQ table mode
7696 /// @return -the read pointer
7697 //------------------------------------------------------------------------------
MVD_GetSlqTblESWritePtr(MS_U8 u8Idx)7698 MS_VIRT MVD_GetSlqTblESWritePtr(MS_U8 u8Idx)
7699 {
7700 MS_VIRT u32EsWp;
7701 MS_VIRT u32EsEnd;
7702 MS_U32 u32Idx;
7703 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
7704 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
7705
7706 if (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr > (pstSlqTblInfo->pDrvSlqTbl->u32StAdd))
7707 {
7708 u32Idx = ((pstSlqTblInfo->pDrvSlqTbl->u32WrPtr - pstSlqTblInfo->pDrvSlqTbl->u32StAdd)/SLQ_ENTRY_LEN) - 1;
7709 }
7710 else
7711 {
7712 u32Idx = SLQ_ENTRY_MAX - 1;
7713 }
7714 u32EsWp = pstSlqTblInfo->pDrvEsTbl->u32StAdd + u32Idx*8;
7715
7716 u32EsEnd = HAL_MVD_MemRead4Byte(u32EsWp+4);
7717 #if 0
7718 printf("GetESWritePtr[%x] ES Start=0x%x End=0x%x u32EsWp=%x\n",
7719 (u32EsWp - pstSlqTblInfo->pDrvEsTbl->u32StAdd)/8,
7720 HAL_MVD_MemRead4Byte(u32EsWp), u32EsEnd, u32EsWp);
7721 #endif
7722
7723 if ((_IsNotInStreamBuff(u32EsEnd)) && (u32EsEnd != 0))
7724 { //ESRead is not in BS buffer, so this entry is a divx pattern.
7725 //Report the last ESRead, instead of this one.
7726 MVD_DEBUGINFO(printf("0x%lx Not in BS, report u32PreEsWr=0x%lx\n", (unsigned long)u32EsEnd, (unsigned long)pstSlqTblInfo->u32PreEsWr));
7727 return (pstSlqTblInfo->u32PreEsWr);
7728 }
7729 pstSlqTblInfo->u32PreEsWr = u32EsEnd;
7730
7731 return u32EsEnd;
7732 }
7733
7734
HAL_MVD_GetSLQReadPtr(MS_U8 u8Idx)7735 MS_VIRT HAL_MVD_GetSLQReadPtr(MS_U8 u8Idx)
7736 {
7737 MS_VIRT u32RdPtr = 0;
7738
7739 if (!(pMVDHalContext->bSlqTblHKCtrl[u8Idx]))
7740 {
7741 #ifndef VDEC3
7742 MVD_CmdArg mvdcmd;
7743 SETUP_CMDARG(mvdcmd);
7744 SET_DECNUM(mvdcmd, u8Idx);
7745 if (HAL_MVD_MVDCommand( CMD_SLQ_GET_TBL_RPTR, &mvdcmd ) == FALSE)
7746 {
7747 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLQ_GET_TBL_RPTR ) );
7748 return 0;
7749 }
7750 u32RdPtr = mvdcmd.Arg0 | (mvdcmd.Arg1<<8) | (mvdcmd.Arg2<<16) | (mvdcmd.Arg3<<24);
7751 #else
7752 u32RdPtr = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SLQ_TBL_RPTR, sizeof(MS_U32));
7753 #endif
7754 }
7755 else
7756 {
7757 u32RdPtr = HAL_MVD_SlqTblProbeRdPtr(u8Idx);
7758 }
7759
7760 //printf("##### HAL_MVD_GetSLQReadPtr 0x%x\n", readPtr);
7761
7762 if(u32RdPtr == 0)//not start decode yet,MVD return 0
7763 {
7764 u32RdPtr = 0;
7765 }
7766 else
7767 {
7768 u32RdPtr = u32RdPtr << 3;
7769 }
7770
7771 return u32RdPtr;
7772 }
7773
7774
HAL_MVD_SetSLQWritePtr(MS_U8 u8Idx,MS_BOOL bCheckData)7775 MS_BOOL HAL_MVD_SetSLQWritePtr(MS_U8 u8Idx, MS_BOOL bCheckData)
7776 {
7777 MVD_CmdArg mvdcmd;
7778 MS_VIRT u32WrPtr;
7779 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
7780 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
7781 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
7782
7783 if (FALSE == pstSlqTblInfo->bRdyToFireCmd)
7784 {
7785 //check FW is init success and thus ready to update write pointer
7786 MS_U32 u32TimeCnt;
7787
7788 u32TimeCnt = HAL_MVD_GetTime();
7789 while ((HAL_MVD_GetTime() - u32TimeCnt) < CMD_TIMEOUT_MS)
7790 {
7791 if (HAL_MVD_GetDecodeStatus(u8Idx) != E_MVD_STAT_IDLE)
7792 {
7793 pstSlqTblInfo->bRdyToFireCmd = TRUE;
7794 MVD_DEBUGVERBAL(printf("time=0x%x ms, ", (HAL_MVD_GetTime() - u32TimeCnt)));
7795 break;
7796 }
7797 }
7798 if (FALSE == pstSlqTblInfo->bRdyToFireCmd)
7799 {
7800 MVD_DEBUGERROR(printf("%s: err timeout(%d)! stat=0x%x\n", __FUNCTION__,
7801 HAL_MVD_GetTime() - u32TimeCnt, HAL_MVD_GetDecodeStatus(u8Idx)));
7802 return FALSE;
7803 }
7804 else
7805 {
7806 MVD_DEBUGVERBAL(printf("%s: ready to update WrPtr.\n", __FUNCTION__));
7807 }
7808 }
7809
7810
7811 MS_ASSERT(pstSlqTblInfo->pDrvSlqTbl->u32WrPtr < pstSlqTblInfo->pDrvSlqTbl->u32EndAdd);
7812 MS_ASSERT(pstSlqTblInfo->pDrvSlqTbl->u32WrPtr >= pstSlqTblInfo->pDrvSlqTbl->u32StAdd);
7813 #if SLQ_NEW_PUSH
7814 if((!pstSlqTblInfo->pSlqStatus->bSlqFireRdy)&&pstSlqTblInfo->pSlqStatus->bSlqCtrlBit)
7815 {
7816 MVD_DEBUGINFO(printf("**** pstSlqTblInfo->pSlqStatus->bSlqFireRdy is not Ready ** \n"));
7817 return FALSE;
7818 }
7819 pstSlqTblInfo->pSlqStatus->bSlqFireRdy = FALSE;
7820 #endif
7821 if ((bCheckData==TRUE) && (FALSE==pstSlqTblInfo->bSlqTblHasValidData))
7822 {
7823 MVD_DEBUGINFO(printf("**** SlqWrPtr(0x%lx) is not update!(%x, %x) ****\n",
7824 (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32WrPtr, bCheckData, pstSlqTblInfo->bSlqTblHasValidData));
7825 return FALSE;
7826 }
7827 pstSlqTblInfo->bSlqTblHasValidData = FALSE;
7828
7829 if (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr != pstSlqTblInfo->pDrvSlqTbl->u32EndAdd)
7830 {
7831 u32WrPtr = pstSlqTblInfo->pDrvSlqTbl->u32WrPtr;
7832 }
7833 else
7834 {
7835 u32WrPtr = pstSlqTblInfo->pDrvSlqTbl->u32StAdd;
7836 }
7837
7838 if (pstCtrlCfg->bSlqTblSync)
7839 {
7840 //Update SLQ table, DivX311 patterns, and dummy patterns to bitstream buffer
7841 MS_VIRT u32SrcOffset = pstSlqTblInfo->pDrvSlqTbl->u32StAdd;
7842 MS_VIRT u32SrcAdd = u32SrcOffset;
7843 MS_VIRT u32DstAdd = pstMemCfg->u32BSAddr;
7844 MS_VIRT u32DstOffset = HAL_MVD_GetMemOffset(pstMemCfg->u32BSAddr);
7845 MS_VIRT u32TblWr;
7846
7847 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,u32SrcOffset,u32SrcAdd);
7848
7849
7850 HAL_MVD_CPU_Sync();
7851
7852 #ifndef MSOS_TYPE_LINUX_KERNEL//BDMA
7853 BDMA_Result bdmaRlt;
7854
7855 bdmaRlt = MDrv_BDMA_CopyHnd(u32SrcAdd, u32DstAdd, pstMemCfg->u32DrvBufSize, pstSlqTblInfo->bdmaCpyType, BDMA_OPCFG_DEF);
7856
7857 if (E_BDMA_OK != bdmaRlt)
7858 {
7859 MVD_DEBUGERROR(printf("%s MDrv_BDMA_MemCopy fail ret=%x!\n", __FUNCTION__, bdmaRlt));
7860 }
7861 #endif
7862 MVD_DEBUGINFO(printf("SlqWrPtr_BDMA src=0x%lx dst=0x%lx size=0x%lx cpyType=0x%x\n",
7863 (unsigned long)u32SrcAdd, (unsigned long)u32DstAdd, (unsigned long)pstMemCfg->u32DrvBufSize, pstSlqTblInfo->bdmaCpyType));
7864
7865 u32TblWr = u32DstOffset + (u32WrPtr - pstSlqTblInfo->pDrvSlqTbl->u32StAdd);
7866
7867 u32WrPtr = u32TblWr;
7868 }
7869 //printf("wPtr= 0x%x(0x%x) rPtr=0x%x(0x%x)\n", writePtr, pstSlqTblInfo->pDrvSlqTbl->u32WrPtr,
7870 // HAL_MVD_GetSLQReadPtr(u8Idx), pstSlqTblInfo->pDrvSlqTbl->u32RdPtr);
7871
7872
7873 //writePtrLast[u8Idx] = u32WrPtr;
7874 #if SLQ_NEW_PUSH
7875 if(!pstSlqTblInfo->pSlqStatus->bSlqEnLastFrameShow && pstSlqTblInfo->pSlqStatus->bSlqCtrlBit)
7876 {
7877 u32WrPtr = pstSlqTblInfo->pSlqStatus->u32VaildWptrAddr;
7878 }
7879 #endif
7880 MS_ASSERT((u32WrPtr%8)==0);
7881 u32WrPtr >>= 3;
7882
7883 if (!(pMVDHalContext->bSlqTblHKCtrl[u8Idx]))
7884 {
7885 SET_CMDARG(mvdcmd, u32WrPtr, u8Idx);
7886 HAL_MVD_CPU_Sync();
7887 SET_CMD_RET_FALSE(CMD_SLQ_UPDATE_TBL_WPTR, &mvdcmd);
7888 }
7889 else
7890 {
7891 HAL_MVD_SlqTblLoadWrPtr(u8Idx, u32WrPtr);
7892 if (HAL_MVD_SlqTblProbeWrPtr(u8Idx) != u32WrPtr)
7893 {
7894 MVD_DEBUGERROR(printf("Ooops! SlqWrPtr update fail!!! 0x%lx != 0x%lx\n", (unsigned long)HAL_MVD_SlqTblProbeWrPtr(u8Idx), (unsigned long)u32WrPtr));
7895 return FALSE;
7896 }
7897 }
7898
7899 return TRUE;
7900 }
7901
HAL_MVD_SetOverflowTH(MS_U8 u8Idx,MS_U32 u32Threshold)7902 void HAL_MVD_SetOverflowTH(MS_U8 u8Idx, MS_U32 u32Threshold)
7903 {
7904 MVD_CmdArg mvdcmd;
7905
7906 MS_ASSERT((u32Threshold%8)==0);
7907 u32Threshold >>= 3;
7908 SET_CMDARG(mvdcmd, u32Threshold, u8Idx);
7909 if (HAL_MVD_MVDCommand( CMD_DMA_OVFTH, &mvdcmd ) == FALSE)
7910 {
7911 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DMA_OVFTH ) );
7912 return;
7913 }
7914 return;
7915 }
7916
7917 //------------------------------------------------------------------------------
7918 /// Set bitstream buffer underflow threshold
7919 /// @return -none
7920 //------------------------------------------------------------------------------
HAL_MVD_SetUnderflowTH(MS_U8 u8Idx,MS_U32 u32Threshold)7921 void HAL_MVD_SetUnderflowTH(MS_U8 u8Idx, MS_U32 u32Threshold)
7922 {
7923 MVD_CmdArg mvdcmd;
7924
7925 MS_ASSERT((u32Threshold%8)==0);
7926 u32Threshold >>= 3;
7927 SET_CMDARG(mvdcmd, u32Threshold, u8Idx);
7928 if (HAL_MVD_MVDCommand( CMD_DMA_UNFTH, &mvdcmd ) == FALSE)
7929 {
7930 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DMA_UNFTH ) );
7931 return;
7932 }
7933 return;
7934 }
7935
HAL_MVD_GenPattern(MS_U8 u8Idx,MVD_PatternType ePattern,MS_PHY u32PAddr,MS_U32 * pu32Size)7936 MS_BOOL HAL_MVD_GenPattern(MS_U8 u8Idx, MVD_PatternType ePattern, MS_PHY u32PAddr, MS_U32* pu32Size)
7937 {
7938 MS_U8* pu8DummyData = NULL;
7939 MVD_CodecType curCodecType = HAL_MVD_GetCodecType(u8Idx);
7940
7941 if ((!pu32Size) || (*pu32Size < SKIP_PATTERN_SIZE))
7942 {
7943 return FALSE;
7944 }
7945
7946 pu8DummyData = (MS_U8*) HAL_MVD_PA2NonCacheSeg(u32PAddr);
7947
7948 if(pu8DummyData == NULL)
7949 {
7950 printf("%s %d NULL Address\n",__FILE__,__LINE__);
7951 return FALSE;
7952 }
7953
7954 switch (ePattern)
7955 {
7956 case E_MVD_PATTERN_FLUSH:
7957 #if 0
7958 *pu8DummyData = SKIP_PATTERN_0;
7959 pu8DummyData++;
7960 *pu8DummyData = SKIP_PATTERN_1;
7961 *pu32Size = SKIP_PATTERN_SIZE;
7962 #else
7963 pu8DummyData[0] = SKIP_PATTERN_0&0xff;
7964 pu8DummyData[1] = (SKIP_PATTERN_0>>8)&0xff;
7965 pu8DummyData[2] = (SKIP_PATTERN_0>>16)&0xff;
7966 pu8DummyData[3] = (SKIP_PATTERN_0>>24)&0xff;
7967
7968 pu8DummyData[4] = SKIP_PATTERN_1&0xff;
7969 pu8DummyData[5] = (SKIP_PATTERN_1>>8)&0xff;
7970 pu8DummyData[6] = (SKIP_PATTERN_1>>16)&0xff;
7971 pu8DummyData[7] = (SKIP_PATTERN_1>>24)&0xff;
7972
7973 *pu32Size = SKIP_PATTERN_SIZE;
7974 #endif
7975 break;
7976 case E_MVD_PATTERN_FILEEND:
7977 if ((E_MVD_CODEC_FLV == curCodecType)||(E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER == curCodecType))
7978 {
7979 #if 0
7980 *pu8DummyData = FLV_PATTERN;
7981 pu8DummyData++;
7982 *pu8DummyData = 0xffffffff;
7983 pu8DummyData++;
7984 *pu8DummyData = END_PATTERN_1;
7985 pu8DummyData++;
7986 *pu8DummyData = END_PATTERN_2;
7987 pu8DummyData++;
7988 *pu8DummyData = END_PATTERN_3;
7989 #else
7990 pu8DummyData[0] = FLV_PATTERN&0xff;
7991 pu8DummyData[1] = (FLV_PATTERN>>8)&0xff;
7992 pu8DummyData[2] = (FLV_PATTERN>>16)&0xff;
7993 pu8DummyData[3] = (FLV_PATTERN>>24)&0xff;
7994
7995 pu8DummyData[4] = 0xffffffff&0xff;
7996 pu8DummyData[5] = (0xffffffff>>8)&0xff;
7997 pu8DummyData[6] = (0xffffffff>>16)&0xff;
7998 pu8DummyData[7] = (0xffffffff>>24)&0xff;
7999
8000 pu8DummyData[8] = END_PATTERN_1&0xff;
8001 pu8DummyData[9] = (END_PATTERN_1>>8)&0xff;
8002 pu8DummyData[10] = (END_PATTERN_1>>16)&0xff;
8003 pu8DummyData[11] = (END_PATTERN_1>>24)&0xff;
8004
8005 pu8DummyData[12] = END_PATTERN_2&0xff;
8006 pu8DummyData[13] = (END_PATTERN_2>>8)&0xff;
8007 pu8DummyData[14] = (END_PATTERN_2>>16)&0xff;
8008 pu8DummyData[15] = (END_PATTERN_2>>24)&0xff;
8009
8010 pu8DummyData[16] = END_PATTERN_3&0xff;
8011 pu8DummyData[17] = (END_PATTERN_3>>8)&0xff;
8012 pu8DummyData[18] = (END_PATTERN_3>>16)&0xff;
8013 pu8DummyData[19] = (END_PATTERN_3>>24)&0xff;
8014
8015 #endif
8016
8017 }
8018 else if (E_MVD_CODEC_DIVX311 == curCodecType)
8019 {
8020 #if 0
8021 *pu8DummyData = DIVX_PATTERN;
8022 pu8DummyData++;
8023 *pu8DummyData = 0xffffffff;
8024 pu8DummyData++;
8025 *pu8DummyData = END_PATTERN_1;
8026 pu8DummyData++;
8027 *pu8DummyData = END_PATTERN_2;
8028 pu8DummyData++;
8029 *pu8DummyData = END_PATTERN_3;
8030 #else
8031 pu8DummyData[0] = DIVX_PATTERN&0xff;
8032 pu8DummyData[1] = (DIVX_PATTERN>>8)&0xff;
8033 pu8DummyData[2] = (DIVX_PATTERN>>16)&0xff;
8034 pu8DummyData[3] = (DIVX_PATTERN>>24)&0xff;
8035
8036 pu8DummyData[4] = 0xffffffff&0xff;
8037 pu8DummyData[5] = (0xffffffff>>8)&0xff;
8038 pu8DummyData[6] = (0xffffffff>>16)&0xff;
8039 pu8DummyData[7] = (0xffffffff>>24)&0xff;
8040
8041 pu8DummyData[8] = END_PATTERN_1&0xff;
8042 pu8DummyData[9] = (END_PATTERN_1>>8)&0xff;
8043 pu8DummyData[10] = (END_PATTERN_1>>16)&0xff;
8044 pu8DummyData[11] = (END_PATTERN_1>>24)&0xff;
8045
8046 pu8DummyData[12] = END_PATTERN_2&0xff;
8047 pu8DummyData[13] = (END_PATTERN_2>>8)&0xff;
8048 pu8DummyData[14] = (END_PATTERN_2>>16)&0xff;
8049 pu8DummyData[15] = (END_PATTERN_2>>24)&0xff;
8050
8051 pu8DummyData[16] = END_PATTERN_3&0xff;
8052 pu8DummyData[17] = (END_PATTERN_3>>8)&0xff;
8053 pu8DummyData[18] = (END_PATTERN_3>>16)&0xff;
8054 pu8DummyData[19] = (END_PATTERN_3>>24)&0xff;
8055 #endif
8056 }
8057 else if ((E_MVD_CODEC_MPEG2 == curCodecType)||(E_MVD_CODEC_MPEG4 == curCodecType))
8058 {
8059 #if 0
8060 *pu8DummyData = MPEG_PATTERN_0;
8061 pu8DummyData++;
8062 *pu8DummyData = END_PATTERN_1;
8063 pu8DummyData++;
8064 *pu8DummyData = END_PATTERN_2;
8065 pu8DummyData++;
8066 *pu8DummyData = END_PATTERN_3;
8067 #else
8068 pu8DummyData[0] = MPEG_PATTERN_0&0xff;
8069 pu8DummyData[1] = (MPEG_PATTERN_0>>8)&0xff;
8070 pu8DummyData[2] = (MPEG_PATTERN_0>>16)&0xff;
8071 pu8DummyData[3] = (MPEG_PATTERN_0>>24)&0xff;
8072
8073 pu8DummyData[4] = END_PATTERN_1&0xff;
8074 pu8DummyData[5] = (END_PATTERN_1>>8)&0xff;
8075 pu8DummyData[6] = (END_PATTERN_1>>16)&0xff;
8076 pu8DummyData[7] = (END_PATTERN_1>>24)&0xff;
8077
8078 pu8DummyData[8] = END_PATTERN_2&0xff;
8079 pu8DummyData[9] = (END_PATTERN_2>>8)&0xff;
8080 pu8DummyData[10] = (END_PATTERN_2>>16)&0xff;
8081 pu8DummyData[11] = (END_PATTERN_2>>24)&0xff;
8082
8083 pu8DummyData[12] = END_PATTERN_3&0xff;
8084 pu8DummyData[13] = (END_PATTERN_3>>8)&0xff;
8085 pu8DummyData[14] = (END_PATTERN_3>>16)&0xff;
8086 pu8DummyData[15] = (END_PATTERN_3>>24)&0xff;
8087 #endif
8088 }
8089 else
8090 {
8091 #if 0
8092 *pu8DummyData = END_PATTERN_0;
8093 pu8DummyData++;
8094 *pu8DummyData = END_PATTERN_1;
8095 pu8DummyData++;
8096 *pu8DummyData = END_PATTERN_2;
8097 pu8DummyData++;
8098 *pu8DummyData = END_PATTERN_3;
8099 #else
8100 pu8DummyData[0] = END_PATTERN_0&0xff;
8101 pu8DummyData[1] = (END_PATTERN_0>>8)&0xff;
8102 pu8DummyData[2] = (END_PATTERN_0>>16)&0xff;
8103 pu8DummyData[3] = (END_PATTERN_0>>24)&0xff;
8104
8105 pu8DummyData[4] = END_PATTERN_1&0xff;
8106 pu8DummyData[5] = (END_PATTERN_1>>8)&0xff;
8107 pu8DummyData[6] = (END_PATTERN_1>>16)&0xff;
8108 pu8DummyData[7] = (END_PATTERN_1>>24)&0xff;
8109
8110 pu8DummyData[8] = END_PATTERN_2&0xff;
8111 pu8DummyData[9] = (END_PATTERN_2>>8)&0xff;
8112 pu8DummyData[10] = (END_PATTERN_2>>16)&0xff;
8113 pu8DummyData[11] = (END_PATTERN_2>>24)&0xff;
8114
8115 pu8DummyData[12] = END_PATTERN_3&0xff;
8116 pu8DummyData[13] = (END_PATTERN_3>>8)&0xff;
8117 pu8DummyData[14] = (END_PATTERN_3>>16)&0xff;
8118 pu8DummyData[15] = (END_PATTERN_3>>24)&0xff;
8119 #endif
8120 }
8121 *pu32Size = 16;
8122 break;
8123 default:
8124 break;
8125 }
8126
8127 return TRUE;
8128 }
8129
8130
8131
HAL_MVD_DbgDump(MS_U8 u8Idx)8132 void HAL_MVD_DbgDump(MS_U8 u8Idx)
8133 {
8134 MS_U32 u32VdCnt=0;
8135 //static MS_U32 u32PreVdCnt[MAX_DEC_NUM]= {0, 0};
8136 MS_U32 u32ErrCnt=0;
8137 //static MS_U32 u32PreErrCnt[MAX_DEC_NUM]= {0, 0};
8138 //static MS_BOOL b1stDump[MAX_DEC_NUM]= {TRUE, TRUE};
8139 MVD_FrmInfo stFrm = {_INIT_ADDR, _INIT_ADDR, _INIT_TIMESTAMP, _INIT_ID,
8140 _INIT_ID, _INIT_LEN, _INIT_LEN, _INIT_LEN, 0xff, E_MVD_PIC_UNKNOWN};
8141 MVD_SrcMode curSrcMode = HAL_MVD_GetSrcMode(u8Idx);
8142 #ifndef VDEC3
8143 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
8144 #endif
8145 if (pMVDHalContext->b1stDump[u8Idx])
8146 {
8147 MVD_FWCfg* pFwCfg = NULL;
8148 pFwCfg = HAL_MVD_GetFWCfg(u8Idx);
8149 printf("curDisablePESParsing = %d\n", pFwCfg->bDisablePESParsing);
8150 pMVDHalContext->b1stDump[u8Idx] = FALSE;
8151 }
8152
8153 u32VdCnt = HAL_MVD_GetParserByteCnt(u8Idx);
8154 u32ErrCnt= HAL_MVD_GetVldErrCount(u8Idx);
8155 printf("input: vfifo=%d(full=%d,empty=%d), vdCnt=%d(%d), vldErr=%d(%d); ",
8156 HAL_MVD_RegReadByte(0x1564)>>6, HAL_MVD_RegReadByte(0x1564)&0x20,
8157 HAL_MVD_RegReadByte(0x1564)&0x10, u32VdCnt, (u32VdCnt-pMVDHalContext->u32PreVdCnt[u8Idx]),
8158 u32ErrCnt, (u32ErrCnt-pMVDHalContext->u32PreErrCnt[u8Idx]));
8159 pMVDHalContext->u32PreVdCnt[u8Idx] = u32VdCnt;
8160 pMVDHalContext->u32PreErrCnt[u8Idx] = u32ErrCnt;
8161
8162 printf("state: fw=0x%x, lastCmd=0x%x, pc=0x%x\n",
8163 HAL_MVD_GetDecodeStatus(u8Idx), HAL_MVD_GetLastCmd(u8Idx), HAL_VPU_EX_GetProgCnt());
8164 printf("cnt: dec=%d, skip=%d, drop=%ld\n", HAL_MVD_GetPicCounter(u8Idx), HAL_MVD_GetSkipPicCounter(u8Idx), 0x0UL);
8165 HAL_MVD_GetFrmInfo(u8Idx, E_MVD_FRMINFO_DECODE, &stFrm);
8166 printf("frm Dec Y=%lx UV=%lx Pitch=%x; ", (unsigned long)stFrm.u32LumaAddr, (unsigned long)stFrm.u32ChromaAddr, stFrm.u16Pitch);
8167 HAL_MVD_GetFrmInfo(u8Idx, E_MVD_FRMINFO_DISPLAY, &stFrm);
8168 printf("Disp Y=%lx UV=%lx Pitch=%x\n", (unsigned long)stFrm.u32LumaAddr, (unsigned long)stFrm.u32ChromaAddr, stFrm.u16Pitch);
8169 if (curSrcMode == E_MVD_SLQ_TBL_MODE)
8170 {
8171 #ifndef VDEC3
8172 printf("fe=%x, rd=%x(%x), wr=%x, empty=%x; ", pstSlqTblInfo->u32FileEndPtr, pstSlqTblInfo->pDrvSlqTbl->u32RdPtr,
8173 HAL_MVD_Map2DrvSlqTbl(u8Idx, HAL_MVD_GetSLQReadPtr(u8Idx)), pstSlqTblInfo->pDrvSlqTbl->u32WrPtr, pstSlqTblInfo->pDrvSlqTbl->u32Empty);
8174
8175 printf("es rd=0x%lx, wr=0x%lx\n", (unsigned long)MVD_GetSlqTblESReadPtr(u8Idx), (unsigned long)MVD_GetSlqTblESWritePtr(u8Idx));
8176 #endif
8177 }
8178 else if (curSrcMode == E_MVD_TS_FILE_MODE)
8179 {
8180 printf("es rd=0x%lx, wr=0x%lx\n", (unsigned long)HAL_MVD_GetTsFileESReadPtr(u8Idx), (unsigned long)HAL_MVD_GetTsFileESWritePtr(u8Idx));
8181 }
8182 }
8183
8184 #ifdef MS_DEBUG
8185 #define _STRINGIFY_HAL_SID(x) \
8186 (x==E_HAL_MVD_MAIN_STREAM0)?"E_HAL_MVD_MAIN_STREAM0": \
8187 ((x==E_HAL_MVD_SUB_STREAM0)?"E_HAL_MVD_SUB_STREAM0":"E_HAL_MVD_STREAM_NONE")
MVD_DumpMVDStream(void)8188 void MVD_DumpMVDStream(void)
8189 {
8190 //if (_u8HalDbgLevel == 0) return;
8191 MS_U8 i = 0;
8192 for (i=0; i< MAX_DEC_NUM; i++)
8193 {
8194 MVD_DEBUGINFO(printf("[%d] eStreamId=0x%x(%s) bUsed=0x%x\n", i, pMVDHalContext->_stMVDStream[i].eStreamId,
8195 _STRINGIFY_HAL_SID(pMVDHalContext->_stMVDStream[i].eStreamId), pMVDHalContext->_stMVDStream[i].bUsed));
8196 }
8197 }
8198 #endif
HAL_MVD_Init_Share_Mem(void)8199 MS_BOOL HAL_MVD_Init_Share_Mem(void)
8200 {
8201 #if (defined(MSOS_TYPE_LINUX) || defined(MSOS_TYPE_ECOS) || defined(MSOS_TYPE_LINUX_KERNEL))
8202 #if !defined(SUPPORT_X_MODEL_FEATURE)
8203 MS_U32 u32ShmId;
8204 MS_VIRT u32Addr;
8205 MS_U32 u32BufSize;
8206
8207
8208 if (FALSE == MsOS_SHM_GetId( (MS_U8*)"Linux MVD HAL",
8209 sizeof(MVD_Hal_CTX),
8210 &u32ShmId,
8211 &u32Addr,
8212 &u32BufSize,
8213 MSOS_SHM_QUERY))
8214 {
8215 if (FALSE == MsOS_SHM_GetId((MS_U8*)"Linux MVD HAL",
8216 sizeof(MVD_Hal_CTX),
8217 &u32ShmId,
8218 &u32Addr,
8219 &u32BufSize,
8220 MSOS_SHM_CREATE))
8221 {
8222 printf("[%s]SHM allocation failed!!! use global structure instead!!!\n",__FUNCTION__);
8223 if(pMVDHalContext == NULL)
8224 {
8225 pMVDHalContext = &gMVDHalContext;
8226 memset(pMVDHalContext,0,sizeof(MVD_Hal_CTX));
8227 HAL_MVD_Context_Init();
8228 printf("[%s]Global structure init Success!!!\n",__FUNCTION__);
8229 }
8230 else
8231 {
8232 printf("[%s]Global structure exists!!!\n",__FUNCTION__);
8233 }
8234 //return FALSE;
8235 }
8236 else
8237 {
8238 memset((MS_U8*)u32Addr,0,sizeof(MVD_Hal_CTX));
8239 pMVDHalContext = (MVD_Hal_CTX*)u32Addr; // for one process
8240 HAL_MVD_Context_Init();
8241 }
8242 }
8243 else
8244 {
8245 pMVDHalContext = (MVD_Hal_CTX*)u32Addr; // for another process
8246 }
8247 #else
8248 if(pMVDHalContext == NULL)
8249 {
8250 pMVDHalContext = &gMVDHalContext;
8251 memset(pMVDHalContext,0,sizeof(MVD_Hal_CTX));
8252 HAL_MVD_Context_Init();
8253 }
8254 #endif
8255 OSAL_MVD_MutexInit();
8256 #else
8257 if(pMVDHalContext == NULL)
8258 {
8259 pMVDHalContext = &gMVDHalContext;
8260 memset(pMVDHalContext,0,sizeof(MVD_Hal_CTX));
8261 HAL_MVD_Context_Init();
8262 }
8263 #endif
8264
8265
8266 return TRUE;
8267
8268 }
8269
8270 //------------------------------------------------------------------------------
HAL_MVD_GetFreeStream(HAL_MVD_StreamType eStreamType)8271 HAL_MVD_StreamId HAL_MVD_GetFreeStream(HAL_MVD_StreamType eStreamType)
8272 {
8273 MS_U32 i = 0;
8274
8275 #ifdef MS_DEBUG
8276 MVD_DumpMVDStream();
8277 #endif
8278 if (eStreamType == E_HAL_MVD_MAIN_STREAM)
8279 {
8280 for (i = 0;
8281 i <
8282 ((E_HAL_MVD_MAIN_STREAM_MAX - E_HAL_MVD_MAIN_STREAM_BASE) +
8283 (E_HAL_MVD_SUB_STREAM_MAX - E_HAL_MVD_SUB_STREAM_BASE)); i++)
8284 {
8285 if ((E_HAL_MVD_MAIN_STREAM_BASE & pMVDHalContext->_stMVDStream[i].eStreamId) && (FALSE == pMVDHalContext->_stMVDStream[i].bUsed))
8286 {
8287 return pMVDHalContext->_stMVDStream[i].eStreamId;
8288 }
8289 }
8290 }
8291 else if (eStreamType == E_HAL_MVD_SUB_STREAM)
8292 {
8293 for (i = 0;
8294 i <
8295 ((E_HAL_MVD_MAIN_STREAM_MAX - E_HAL_MVD_MAIN_STREAM_BASE) +
8296 (E_HAL_MVD_SUB_STREAM_MAX - E_HAL_MVD_SUB_STREAM_BASE)); i++)
8297 {
8298 if ((E_HAL_MVD_SUB_STREAM_BASE & pMVDHalContext->_stMVDStream[i].eStreamId) && (FALSE == pMVDHalContext->_stMVDStream[i].bUsed))
8299 {
8300 return pMVDHalContext->_stMVDStream[i].eStreamId;
8301 }
8302 }
8303 }
8304 #ifdef VDEC3
8305 else if ((eStreamType >= E_HAL_MVD_N_STREAM) && (eStreamType < E_HAL_MVD_N_STREAM + MAX_DEC_NUM))
8306 {
8307 i = eStreamType - E_HAL_MVD_N_STREAM;
8308 if (!pMVDHalContext->_stMVDStream[i].bUsed)
8309 {
8310 return pMVDHalContext->_stMVDStream[i].eStreamId;
8311 }
8312 }
8313 #endif
8314
8315 return E_HAL_MVD_STREAM_NONE;
8316 }
8317
HAL_MVD_SidToIdx(HAL_MVD_StreamId eSID)8318 MS_U8 HAL_MVD_SidToIdx(HAL_MVD_StreamId eSID)
8319 {
8320 #ifdef VDEC3
8321 return eSID - E_HAL_MVD_N_STREAM_BASE;
8322 #else
8323 MS_U8 u8Idx = 0;
8324 switch (eSID)
8325 {
8326 case E_HAL_MVD_MAIN_STREAM0:
8327 u8Idx = 0;
8328 break;
8329 case E_HAL_MVD_SUB_STREAM0:
8330 u8Idx = 1;
8331 break;
8332 #if 0
8333 case E_HAL_MVD_SUB_STREAM1:
8334 u8Idx = 2;
8335 break;
8336 #endif
8337 default:
8338 u8Idx = 0;
8339 break;
8340 }
8341 return u8Idx;
8342 #endif
8343 }
8344
HAL_MVD_ReleaseFdMask(MS_U8 u8Idx,MS_BOOL bRls)8345 MS_BOOL HAL_MVD_ReleaseFdMask(MS_U8 u8Idx, MS_BOOL bRls)
8346 {
8347 MVD_CmdArg mvdcmd;
8348
8349 SETUP_CMDARG(mvdcmd);
8350 mvdcmd.Arg0 = bRls; //1 to release the fd mask
8351 MVD_DEBUGINFO(printf("%s: release=0x%x\n", __FUNCTION__, bRls));
8352 SET_DECNUM(mvdcmd, u8Idx);
8353 SET_CMD_RET_FALSE(CMD_UPDATE_FRAME, &mvdcmd);
8354
8355 return TRUE;
8356 }
8357
HAL_MVD_ParserRstDone(MS_U8 u8Idx,MS_BOOL bEnable)8358 MS_BOOL HAL_MVD_ParserRstDone(MS_U8 u8Idx, MS_BOOL bEnable)
8359 {
8360 #define PARSER_RST_TIMEOUT 0x40000
8361 MS_U32 u32TimeOut = 0;
8362 MVD_CmdArg mvdcmd;
8363
8364 HAL_MVD_ResetHandShake(u8Idx, MVD_HANDSHAKE_PARSER_RST);
8365 SETUP_CMDARG(mvdcmd);
8366 mvdcmd.Arg1 = bEnable;
8367 SET_DECNUM(mvdcmd, u8Idx);
8368 SET_CMD_RET_FALSE(CMD_PTS_TBL_RESET, &mvdcmd);
8369
8370 while ((TRUE != HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_PARSER_RST)) && (u32TimeOut < PARSER_RST_TIMEOUT))
8371 {
8372 u32TimeOut++;
8373 }
8374 if (u32TimeOut >= PARSER_RST_TIMEOUT)
8375 {
8376 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail timeout!!\r\n", CMD_PTS_TBL_RESET ) );
8377 return FALSE;
8378 }
8379 return TRUE;
8380 }
8381
HAL_MVD_FlushPTSBuf(MS_U8 u8Idx,MS_BOOL bEnable)8382 MS_BOOL HAL_MVD_FlushPTSBuf(MS_U8 u8Idx, MS_BOOL bEnable)
8383 {
8384 #ifdef VDEC3
8385 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
8386
8387 if(pstCtrlCfg->u8McuMode == FALSE)
8388 #endif
8389 {
8390 MVD_CmdArg mvdcmd;
8391 SETUP_CMDARG(mvdcmd);
8392 mvdcmd.Arg0 = bEnable;
8393 if (HAL_MVD_MVDCommand( CMD_SEND_UNI_PTS, &mvdcmd ) == FALSE)
8394 {
8395 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SEND_UNI_PTS ) );
8396 return FALSE;
8397 }
8398 }
8399 return TRUE;
8400 }
8401
8402
HAL_MVD_GetSLQNum(MS_U8 u8Idx)8403 MS_U32 HAL_MVD_GetSLQNum(MS_U8 u8Idx)
8404 {
8405 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
8406 MS_VIRT u32RdPtr = HAL_MVD_GetSLQReadPtr(u8Idx);
8407 MS_VIRT u32Diff = 0;
8408
8409 if (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr >= u32RdPtr)
8410 {
8411 u32Diff = pstSlqTblInfo->pDrvSlqTbl->u32WrPtr - u32RdPtr;
8412 }
8413 else
8414 {
8415 u32Diff = SLQ_TBL_SIZE - (u32RdPtr - pstSlqTblInfo->pDrvSlqTbl->u32WrPtr);
8416 }
8417
8418 // printf("slq wptr = 0x%x, rptr = 0x%x\n", pstSlqTblInfo->pDrvSlqTbl->u32WrPtr, u32RdPtr);
8419
8420 return (u32Diff/SLQ_ENTRY_LEN);
8421 }
8422
8423
HAL_MVD_GetDispQNum(MS_U8 u8Idx)8424 MS_U32 HAL_MVD_GetDispQNum(MS_U8 u8Idx)
8425 {
8426 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DISPQ_NUM, sizeof(MS_U8));
8427 }
HAL_MVD_SetAutoMute(MS_U8 u8Idx,MS_BOOL bEn)8428 MS_BOOL HAL_MVD_SetAutoMute(MS_U8 u8Idx, MS_BOOL bEn)
8429 {
8430 MVD_CmdArg mvdcmd;
8431
8432 SETUP_CMDARG(mvdcmd);
8433 mvdcmd.Arg0 = bEn; //1 to enable
8434 MVD_DEBUGINFO(printf("%s: bEn=%x\n", __FUNCTION__, bEn));
8435 SET_DECNUM(mvdcmd, u8Idx);
8436 SET_CMD_RET_FALSE(CMD_ENABLE_AUTO_MUTE, &mvdcmd);
8437
8438 return TRUE;
8439 }
8440
HAL_MVD_SetVSizeAlign(MS_U8 u8Idx,MS_BOOL bEn)8441 MS_BOOL HAL_MVD_SetVSizeAlign(MS_U8 u8Idx, MS_BOOL bEn)
8442 {
8443 MVD_CmdArg mvdcmd;
8444
8445 SETUP_CMDARG(mvdcmd);
8446 mvdcmd.Arg0 = bEn; //1 to enable VSize alignment to 4x
8447 MVD_DEBUGINFO(printf("%s: bEn=%x\n", __FUNCTION__, bEn));
8448 SET_DECNUM(mvdcmd, u8Idx);
8449 SET_CMD_RET_FALSE(CMD_FORCE_ALIGN_VSIZE, &mvdcmd);
8450
8451 return TRUE;
8452 }
8453
HAL_MVD_GetFrmRateIsSupported(MS_U16 u16HSize,MS_U16 u16VSize,MS_U32 u32FrmRate)8454 MS_BOOL HAL_MVD_GetFrmRateIsSupported(MS_U16 u16HSize, MS_U16 u16VSize, MS_U32 u32FrmRate)
8455 {
8456 MVD_DEBUGINFO(printf("%s w:%d, h:%d, fr:%d, MAX:%lld\n", __FUNCTION__, u16HSize, u16VSize, u32FrmRate, MVD_HW_MAX_PIXEL));
8457 return (((MS_U64)u16HSize*(MS_U64)u16VSize*(MS_U64)u32FrmRate) <= MVD_HW_MAX_PIXEL);
8458 }
8459
HAL_MVD_GetColorInfo(MS_U8 u8Idx,MVD_Color_Info * pstColorInfo)8460 MS_BOOL HAL_MVD_GetColorInfo(MS_U8 u8Idx, MVD_Color_Info* pstColorInfo)
8461 {
8462 MS_VIRT pu8MVDGetFrameInfoBufStart = GET_FRMINFO_BUFFADD(u8Idx);
8463
8464 if((pu8MVDGetFrameInfoBufStart==0) || (pstColorInfo==0))
8465 {
8466 MVD_DEBUGERROR(printf("HAL_MVD_GetColorInfo error: pu8MVDGetFrameInfoBufStart=NULL\n"));
8467 return FALSE;
8468 }
8469
8470 pstColorInfo->bColor_Descript = (MS_BOOL)(HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_COLOR_DESCRIPT));
8471
8472 if(pstColorInfo->bColor_Descript)
8473 {
8474 pstColorInfo->u8Color_Primaries = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_COLOR_PRIMARIES);
8475 pstColorInfo->u8Transfer_Char = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TRANSFER_CHAR);
8476 pstColorInfo->u8Matrix_Coef = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_MATRIX_COEF);
8477 }
8478 return TRUE;
8479
8480 }
8481
8482
8483 //------------------------------------------------------------------------------
8484 /// Wait MVD generate CRC done or timeout
8485 /// @return -MVD generate CRC done or timeout
8486 //------------------------------------------------------------------------------
_HAL_MVD_CrcTimeOut(MS_U8 u8Idx)8487 MS_BOOL _HAL_MVD_CrcTimeOut(MS_U8 u8Idx)
8488 {
8489 MS_U32 i;
8490 MS_U32 u32StartTime = MsOS_GetSystemTime();
8491
8492 for ( i = 0; i < MVD_PollingTimes; i++ )
8493 {
8494 ///- wait until MVD generate CRC done or timeout
8495 if ( ( HAL_MVD_RegReadByte(MVD_CRC_CTL) & MVD_CRC_CTL_DONE ) == MVD_CRC_CTL_DONE )
8496 {
8497 return FALSE;
8498 }
8499
8500 if ((TRUE == pMVDHalContext->bStopped[u8Idx]) || ((MsOS_GetSystemTime()-u32StartTime)>1300))
8501 {
8502 MVD_DEBUGINFO(printf("%s: bStopped(%x) or timeout(%d)\n", __FUNCTION__, pMVDHalContext->bStopped[u8Idx], MsOS_GetSystemTime()-u32StartTime));
8503 return TRUE;
8504 }
8505
8506 }
8507 MVD_DEBUGERROR( printf("_HAL_MVD_CrcTimeOut=%x\n", i) );
8508 return TRUE;
8509 }
8510
HAL_MVD_GetCrcValue(MS_U8 u8Idx,MVD_CrcIn * pCrcIn,MVD_CrcOut * pCrcOut)8511 E_MVD_Result HAL_MVD_GetCrcValue(MS_U8 u8Idx, MVD_CrcIn *pCrcIn, MVD_CrcOut *pCrcOut)
8512 {
8513 E_MVD_Result eRet = E_MVD_RET_OK;
8514 MS_U32 u32tmp = 0;
8515
8516 OSAL_MVD_LockHwMutex();
8517
8518 MVD_DEBUGINFO(printf("%s width=0x%x, height=0x%x, pitch=0x%x, luma=0x%lx, chroma=0x%lx\n",
8519 __FUNCTION__, pCrcIn->u32HSize, pCrcIn->u32VSize, pCrcIn->u32Strip, (unsigned long)pCrcIn->u32YStartAddr, (unsigned long)pCrcIn->u32UVStartAddr));
8520
8521 //Set generate CRC value
8522 u32tmp = ((pCrcIn->u32HSize + MVD_WIDTH_ALIGN_MASK) >> MVD_WIDTH_ALIGN_BITS) << MVD_WIDTH_ALIGN_BITS;
8523 HAL_MVD_RegWriteByte(MVD_CRC_HSIZE, u32tmp & 0xf0);
8524 HAL_MVD_RegWriteByte(MVD_CRC_HSIZE+1, (u32tmp >> 8) & 0x3f);
8525
8526 u32tmp = ((pCrcIn->u32VSize + MVD_WIDTH_ALIGN_MASK) >> MVD_WIDTH_ALIGN_BITS) << MVD_WIDTH_ALIGN_BITS;
8527 HAL_MVD_RegWriteByte(MVD_CRC_VSIZE, u32tmp & 0xff);
8528 HAL_MVD_RegWriteByte(MVD_CRC_VSIZE+1, (u32tmp >> 8) & 0xff);
8529
8530 u32tmp = (pCrcIn->u32Strip) >> 3;
8531 HAL_MVD_RegWriteByte(MVD_CRC_STRIP, u32tmp & 0xff);
8532 HAL_MVD_RegWriteByte((MVD_CRC_STRIP+1), (u32tmp >> 8) & 0xff);
8533
8534 u32tmp = (pCrcIn->u32YStartAddr) >> 3;
8535 HAL_MVD_RegWrite4Byte(MVD_CRC_Y_START, u32tmp & MVD_CRC_Y_START_LEN);
8536
8537 u32tmp = (pCrcIn->u32UVStartAddr) >> 3;
8538 HAL_MVD_RegWrite4Byte(MVD_CRC_UV_START, u32tmp & MVD_CRC_UV_START_LEN);
8539
8540 //Fire
8541 HAL_MVD_RegWriteBit(MVD_CRC_CTL, 1, MVD_CRC_CTL_FIRE);
8542
8543 //Check CRC done
8544 if ( _HAL_MVD_CrcTimeOut(u8Idx) == TRUE )
8545 {
8546 eRet = E_MVD_RET_TIME_OUT;
8547 goto _CRC_DONE;
8548 }
8549
8550 //Get CRC value
8551 pCrcOut->u32YCrc = HAL_MVD_RegReadByte(MVD_CRC_Y_L) |
8552 (HAL_MVD_RegReadByte(MVD_CRC_Y_L+1) << 8) |
8553 (HAL_MVD_RegReadByte(MVD_CRC_Y_H) <<16) |
8554 (HAL_MVD_RegReadByte(MVD_CRC_Y_H+1) <<24);
8555
8556 pCrcOut->u32UVCrc = HAL_MVD_RegReadByte(MVD_CRC_UV_L) |
8557 (HAL_MVD_RegReadByte(MVD_CRC_UV_L+1) << 8) |
8558 (HAL_MVD_RegReadByte(MVD_CRC_UV_H) <<16) |
8559 (HAL_MVD_RegReadByte(MVD_CRC_UV_H+1) <<24);
8560
8561 MVD_DEBUGINFO(printf("%s Y=0x%x, UV=0x%x\n", __FUNCTION__, pCrcOut->u32YCrc, pCrcOut->u32UVCrc));
8562
8563 _CRC_DONE:
8564 OSAL_MVD_UnlockHwMutex();
8565 return eRet;
8566 }
8567
8568
HAL_MVD_SuspendDynamicScale(MS_U8 u8Idx,MS_BOOL bEn)8569 MS_BOOL HAL_MVD_SuspendDynamicScale(MS_U8 u8Idx, MS_BOOL bEn)
8570 {
8571 MVD_CmdArg mvdcmd;
8572
8573 SETUP_CMDARG(mvdcmd);
8574 mvdcmd.Arg0 = bEn;
8575 MVD_DEBUGINFO(printf("%s: bEn=%x\n", __FUNCTION__, bEn));
8576 SET_DECNUM(mvdcmd, u8Idx);
8577 SET_CMD_RET_FALSE(CMD_SUSPEND_DS, &mvdcmd);
8578
8579 return TRUE;
8580 }
8581
HAL_MVD_GetSuspendDynamicScale(MS_U8 u8Idx)8582 MS_U8 HAL_MVD_GetSuspendDynamicScale(MS_U8 u8Idx)
8583 {
8584 return (MS_U8)MVD_GetFWBuffData(u8Idx, FW_BUFF_VOLINFO, OFFSET_SUSPEND_DS, sizeof(MS_U8));
8585 }
8586
HAL_MVD_GetStereoType(MS_U8 u8Idx)8587 MS_U8 HAL_MVD_GetStereoType(MS_U8 u8Idx)
8588 {
8589 return (MS_U8)MVD_GetFWBuffData(u8Idx, FW_BUFF_VOLINFO, OFFSET_STEREO_TYPE, sizeof(MS_U8));
8590 }
8591
HAL_MVD_GetDivxVer(MS_U8 u8Idx)8592 MS_U32 HAL_MVD_GetDivxVer(MS_U8 u8Idx)
8593 {
8594 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DIVX_VER_5X, sizeof(MS_U32));
8595 }
8596
HAL_MVD_SetIdctMode(MS_U8 u8Idx,MS_U8 u8Mode)8597 MS_BOOL HAL_MVD_SetIdctMode(MS_U8 u8Idx, MS_U8 u8Mode)
8598 {
8599 MVD_CmdArg mvdcmd;
8600
8601 SETUP_CMDARG(mvdcmd);
8602 mvdcmd.Arg0 = u8Mode;
8603 SET_DECNUM(mvdcmd, u8Idx);
8604
8605 MVD_DEBUGINFO(printf("%s CMD_IDCT_SEL arg0=%x)\n", __FUNCTION__, u8Mode));
8606 SET_CMD_RET_FALSE(CMD_IDCT_SEL, &mvdcmd);
8607
8608 return TRUE;
8609 }
8610
HAL_MVD_EX_SetClockSpeed(HAL_MVD_EX_ClockSpeed eClockSpeed)8611 E_MVD_Result HAL_MVD_EX_SetClockSpeed(HAL_MVD_EX_ClockSpeed eClockSpeed)
8612 {
8613 UNUSED(eClockSpeed);
8614 printf("This chip does not support mvd clock presetting~\n");
8615 return E_MVD_RET_FAIL;
8616 }
8617
HAL_MVD_GetIsAVSyncOn(MS_U8 u8Idx)8618 MS_BOOL HAL_MVD_GetIsAVSyncOn(MS_U8 u8Idx)
8619 {
8620 MS_BOOL bAVSyncOn = FALSE;
8621 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
8622 if (pCtrlCfg)
8623 {
8624 bAVSyncOn = pCtrlCfg->bAVSyncOn;
8625 }
8626
8627 return bAVSyncOn;
8628 }
8629
HAL_MVD_SetExternalDSBuff(MS_U8 u8Idx,MS_VIRT u32VPUAddr,MS_VIRT u32DrvAddr)8630 MS_BOOL HAL_MVD_SetExternalDSBuff(MS_U8 u8Idx, MS_VIRT u32VPUAddr, MS_VIRT u32DrvAddr)
8631 {
8632 MS_BOOL bRet = TRUE;
8633 MVD_FWBuff* pBuff = &(pMVDHalContext->stFWBuff[u8Idx]);
8634
8635 pBuff->u32DynScalingAdd = u32DrvAddr;
8636 bRet = HAL_MVD_SetDynamicScaleAddr(u8Idx, u32VPUAddr);
8637 return bRet;
8638 }
8639
HAL_MVD_ShowFirstFrameDirect(MS_U8 u8Idx,MS_U8 bEnable)8640 MS_BOOL HAL_MVD_ShowFirstFrameDirect(MS_U8 u8Idx, MS_U8 bEnable)
8641 {
8642 MVD_CmdArg mvdcmd;
8643
8644 SETUP_CMDARG(mvdcmd);
8645 mvdcmd.Arg0 = bEnable;
8646 SET_DECNUM(mvdcmd, u8Idx);
8647
8648 MVD_DEBUGINFO(printf("%s CMD_PUSH_FIRST_FRAME_DISP arg0=%x)\n", __FUNCTION__, bEnable));
8649 SET_CMD_RET_FALSE(CMD_PUSH_FIRST_FRAME_DISP, &mvdcmd);
8650
8651 return TRUE;
8652 }
8653
HAL_MVD_SetXCLowDelayPara(MS_U8 u8Idx,MS_U32 u32Para)8654 E_MVD_Result HAL_MVD_SetXCLowDelayPara(MS_U8 u8Idx,MS_U32 u32Para)
8655 {
8656 MVD_CmdArg mvdcmd;
8657
8658 SETUP_CMDARG(mvdcmd);
8659 mvdcmd.Arg0 = L_WORD(u32Para); // for set the XC diff_field_number
8660 mvdcmd.Arg1 = H_WORD(u32Para); // for set XC UCNR diff field no
8661 SET_DECNUM(mvdcmd, u8Idx);
8662
8663 SET_CMD_RET_FALSE(CMD_XC_LOW_DELAY_PARA, &mvdcmd);
8664
8665 return TRUE;
8666 }
8667
HAL_MVD_GetESBufferStatus(MS_U8 u8Idx)8668 MS_U8 HAL_MVD_GetESBufferStatus(MS_U8 u8Idx)
8669 {
8670 return (MS_U8)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CURRENT_ES_BUFFER_STATUS, sizeof(MS_U8)));
8671 }
8672
HAL_MVD_Field_Polarity_Display_One_field(MS_U8 u8Idx,MS_BOOL bEn,MS_U8 top_bottom)8673 MS_BOOL HAL_MVD_Field_Polarity_Display_One_field(MS_U8 u8Idx, MS_BOOL bEn,MS_U8 top_bottom)
8674 {
8675 MVD_CmdArg mvdcmd;
8676
8677 SETUP_CMDARG(mvdcmd);
8678 mvdcmd.Arg2 = bEn;
8679 mvdcmd.Arg3 = top_bottom;
8680 MVD_DEBUGINFO(printf("%s: bEn=%x,top_bottom=%x\n", __FUNCTION__, bEn,top_bottom));
8681 SET_DECNUM(mvdcmd, u8Idx);
8682 SET_CMD_RET_FALSE(CMD_FP_FILTER, &mvdcmd);
8683
8684 return TRUE;
8685 }
8686
8687
HAL_MVD_SetShareMemoryBase(MS_U8 u8Idx,MS_VIRT u32base,MS_U8 u8sel)8688 MS_BOOL HAL_MVD_SetShareMemoryBase(MS_U8 u8Idx, MS_VIRT u32base, MS_U8 u8sel)
8689 {
8690 u8SHMMiuSel = u8sel;
8691 u32SharememoryBase[u8Idx] = u32base - MVD_FW_CODE_LEN;
8692 return TRUE;
8693 }
8694
HAL_MVD_GetShareMemoryOffset(MS_U8 u8Idx,MS_VIRT * u32base)8695 MS_BOOL HAL_MVD_GetShareMemoryOffset(MS_U8 u8Idx, MS_VIRT *u32base)
8696 {
8697 *u32base=u32SharememoryBase[u8Idx];
8698 return TRUE;
8699 }
8700
HAL_MVD_Support2ndMVOPInterface(void)8701 MS_BOOL HAL_MVD_Support2ndMVOPInterface(void)
8702 {
8703 return TRUE;
8704 }
8705
HAL_MVD_SetExternal_CC_Buffer(MS_U8 u8Idx,MS_VIRT u32base,MS_U8 u8size,MS_U8 cc_type)8706 MS_BOOL HAL_MVD_SetExternal_CC_Buffer(MS_U8 u8Idx, MS_VIRT u32base, MS_U8 u8size, MS_U8 cc_type)
8707 {
8708 MVD_CmdArg mvdcmd;
8709 MS_U32 u32cc_size=0;
8710 MS_VIRT u32StartOffset;
8711 MS_U8 u8MiuSel;
8712
8713 SETUP_CMDARG(mvdcmd);
8714 if (u8size !=0)
8715 {
8716 mvdcmd.Arg0 = TRUE; //enable
8717 }
8718 else
8719 {
8720 mvdcmd.Arg0 = FALSE; //disable
8721 }
8722 mvdcmd.Arg1 = cc_type; //608->1,708->0
8723
8724 SET_DECNUM(mvdcmd, u8Idx);
8725 SET_CMD_RET_FALSE(CMD_CC_ENABLE_EXTERNAL_BUFFER, &mvdcmd);
8726
8727 if (u8size ==0)
8728 {
8729 SET_CMD_RET_FALSE(CMD_CLOSE_CC, &mvdcmd);
8730 return E_MVD_RET_OK;
8731 }
8732
8733 u32base *= (1<<10); //unit is bytes
8734 u32cc_size = u8size * (1<<10); //unit is bytes
8735
8736
8737 MS_U32 *pu32ReadPtr = (MS_U32 *)(HAL_MVD_PA2NonCacheSeg(u32base));
8738 MS_U32 *pu32WritePtr = (MS_U32 *)(HAL_MVD_PA2NonCacheSeg(u32base+sizeof(MS_U32)));
8739 MS_U32 *pu32LatchOverflow = (MS_U32 *)(HAL_MVD_PA2NonCacheSeg(u32base+sizeof(MS_U32)*2));
8740 MS_U32 *pu32CpuBaseAddr = (MS_U32 *)(HAL_MVD_PA2NonCacheSeg(u32base+sizeof(MS_U32)*3));
8741
8742 //rptr,wptr,overflow,latch 16 bytes
8743 if(cc_type==1)
8744 {
8745 u32base += (4*sizeof(MS_U32));
8746 u32cc_size -= (4*sizeof(MS_U32));
8747 }
8748
8749 if(cc_type==0) // 708: start from 128 bytes
8750 {
8751 u32base += 128;
8752 u32cc_size -= 128;
8753 }
8754
8755 *pu32ReadPtr = *pu32WritePtr = u32base;
8756 *pu32LatchOverflow = 0;
8757 *pu32CpuBaseAddr = HAL_MVD_GetMEMCfg(u8Idx)->u32FWBinAddr;
8758
8759 _phy_to_miu_offset(u8MiuSel, u32StartOffset, u32base);
8760 _MVD_SetUserDataBufStart(u8Idx,u32StartOffset,cc_type);
8761 _MVD_SetUserDataBufSize(u8Idx,u32cc_size,cc_type);
8762 //MVD_DEBUGINFO(printf("%s: u32base=%x,u32size=%x,cc_type=%x\n", __FUNCTION__,u32base,u32cc_size,cc_type));
8763
8764 return E_MVD_RET_OK;
8765 }
8766
HAL_MVD_GetPVRSeamlessInfo(MS_U8 u8Idx,void * param)8767 MS_BOOL HAL_MVD_GetPVRSeamlessInfo(MS_U8 u8Idx,void* param)
8768 {
8769
8770 MVD_PVR_Seamless_Info* temp = (MVD_PVR_Seamless_Info*)param;
8771
8772 temp->u64PTS = ((MS_U64)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PVRSEAMLESSTARGETPTS, sizeof(MS_U32))) |
8773 (((MS_U64)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PVRSEAMLESSTARGETPTSHIGH, sizeof(MS_U8)))<<32);
8774
8775 temp->u32POC = 0xFF; // not support in mvd
8776 temp->u8FrameType = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PVRSEAMLESSTARGETFRAMETYPE, sizeof(MS_U8));
8777
8778 return TRUE;
8779 }
8780
HAL_MVD_HWBuffer_ReMappingMode(MS_U8 u8Idx,MS_BOOL bEnable)8781 E_MVD_Result HAL_MVD_HWBuffer_ReMappingMode(MS_U8 u8Idx,MS_BOOL bEnable)
8782 {
8783 pMVDHalContext->gMVDPreCtrl[u8Idx].bHWBufferReMapping = bEnable;
8784 return E_MVD_RET_OK;
8785 }
8786
HAL_MVD_SetPrebufferSize(MS_U8 u8Idx,MS_U32 size)8787 MS_BOOL HAL_MVD_SetPrebufferSize(MS_U8 u8Idx, MS_U32 size)
8788 {
8789 MVD_CmdArg mvdcmd;
8790
8791 SETUP_CMDARG(mvdcmd);
8792 mvdcmd.Arg0 = size&0xff;
8793 mvdcmd.Arg1 = (size>>8)&0xff;
8794 mvdcmd.Arg2 = (size>>16)&0xff;
8795 mvdcmd.Arg3 = (size>>24)&0xff;
8796 SET_DECNUM(mvdcmd, u8Idx);
8797 if (HAL_MVD_MVDCommand( CMD_PREBUFFER_SIZE, &mvdcmd ) == FALSE)
8798 {
8799 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PREBUFFER_SIZE ) );
8800 return FALSE;
8801 }
8802 return TRUE;
8803 }
8804
HAL_MVD_GetVsyncAddrOffset(void)8805 MS_VIRT HAL_MVD_GetVsyncAddrOffset(void)
8806 {
8807 MS_VIRT VPUSHMAddr = HAL_VPU_EX_GetSHMAddr();
8808 MS_VIRT VsyncBridgeOffset = 0;
8809
8810 if(VPUSHMAddr != 0) // TEE project
8811 {
8812 VsyncBridgeOffset = VSYNC_BRIDGE_OFFSET;
8813 }
8814 else // normal project
8815 {
8816 VsyncBridgeOffset = COMMON_AREA_START + VSYNC_BRIDGE_OFFSET;
8817 }
8818
8819 return VsyncBridgeOffset;
8820 }
8821
HAL_MVD_GetVsyncExtAddrOffset(void)8822 MS_VIRT HAL_MVD_GetVsyncExtAddrOffset(void)
8823 {
8824 MS_VIRT VsyncBridgeExtOffset = 0;
8825 MS_VIRT VPUSHMAddr = HAL_VPU_EX_GetSHMAddr();
8826
8827 if(VPUSHMAddr != 0) // TEE project
8828 {
8829 VsyncBridgeExtOffset = VSYNC_BRIDGE_EXT_OFFSET;
8830 }
8831 else // normal project
8832 {
8833 VsyncBridgeExtOffset = COMMON_AREA_START + VSYNC_BRIDGE_EXT_OFFSET;
8834 }
8835
8836 return VsyncBridgeExtOffset;
8837 }
8838
HAL_MVD_SetTimeIncPredictParam(MS_U8 u8Idx,MS_U32 u32time)8839 E_MVD_Result HAL_MVD_SetTimeIncPredictParam(MS_U8 u8Idx, MS_U32 u32time)
8840 {
8841 MVD_CmdArg mvdcmd;
8842 SETUP_CMDARG(mvdcmd);
8843
8844 mvdcmd.Arg0 = L_WORD(u32time); // Arg0(enable), 1 for enable, default is 0...
8845 mvdcmd.Arg1 = H_WORD(u32time); // Arg1(vop_time_incr_predict_count), 1 for predict once, 2 for twice...0xff for always guess the vop_time_incr even with the vol_header, default is 0...
8846 mvdcmd.Arg2 = L_DWORD(u32time);// Arg2(vop_time_incr_follow_vol_header), // 0 for follow vol_header...1 for bypass vol_header, default is 0...
8847 mvdcmd.Arg3 = H_DWORD(u32time);// Arg3, reserve...
8848 MVD_DEBUGINFO(printf("CMD_TIME_INCR_PREDICT=%x\n",u32time));
8849 if (HAL_MVD_MVDCommand(CMD_TIME_INCR_PREDICT, &mvdcmd) == FALSE)
8850 {
8851 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_TIME_INCR_PREDICT ) );
8852 return E_MVD_RET_FAIL;
8853 }
8854 return E_MVD_RET_OK;
8855
8856 }
8857
HAL_MVD_SetDecodeTimeoutParam(MS_U8 u8Idx,MS_BOOL enable,MS_U32 u32timeout)8858 MS_BOOL HAL_MVD_SetDecodeTimeoutParam(MS_U8 u8Idx, MS_BOOL enable,MS_U32 u32timeout)
8859 {
8860 MVD_CmdArg mvdcmd;
8861
8862 SETUP_CMDARG(mvdcmd);
8863
8864 if(enable == TRUE)
8865 {
8866 mvdcmd.Arg0 = 2; //0:disable, 2: enable decode timeout
8867 mvdcmd.Arg1 = u32timeout&0xff;
8868 mvdcmd.Arg2 = (u32timeout>>8)&0xff;
8869 mvdcmd.Arg3 = (u32timeout>>16)&0xff;
8870 }
8871 else
8872 {
8873 mvdcmd.Arg0 = 0; //0:disable, 2: enable decode timeout
8874 }
8875
8876 SET_DECNUM(mvdcmd, u8Idx);
8877
8878 if (HAL_MVD_MVDCommand( CMD_ENABLE_VLD_TIMEOUT, &mvdcmd ) == FALSE)
8879 {
8880 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_ENABLE_VLD_TIMEOUT ) );
8881 return FALSE;
8882 }
8883
8884 return TRUE;
8885 }
8886
HAL_MVD_Set_Smooth_Rewind(MS_U8 u8Idx,MS_U8 btype)8887 E_MVD_Result HAL_MVD_Set_Smooth_Rewind(MS_U8 u8Idx, MS_U8 btype)
8888 {
8889 MVD_CmdArg mvdcmd;
8890 SETUP_CMDARG(mvdcmd);
8891 mvdcmd.Arg0 = btype;
8892 MVD_DEBUGINFO(printf("%s: btype=%x\n", __FUNCTION__, btype));
8893 SET_DECNUM(mvdcmd, u8Idx);
8894 if (HAL_MVD_MVDCommand(CMD_SMOOTH_REWIND, &mvdcmd) == FALSE)
8895 {
8896 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SMOOTH_REWIND ) );
8897 return E_MVD_RET_FAIL;
8898 }
8899 return E_MVD_RET_OK;
8900 }
8901
HAL_MVD_IsAlive(MS_U8 u8Idx)8902 E_MVD_Result HAL_MVD_IsAlive(MS_U8 u8Idx)
8903 {
8904 MVD_ALIVEInfo* pAliveInfo = &(pMVDHalContext->aliveInfo[u8Idx]);
8905 MVD_SrcMode curSrcMode = HAL_MVD_GetSrcMode(u8Idx);
8906
8907 if (E_MVD_SLQ_TBL_MODE == curSrcMode || E_MVD_TS_FILE_MODE == curSrcMode)
8908 {
8909 if(pMVDHalContext->u32LastAliveTime[u8Idx] == 0 || ((MsOS_GetSystemTime()-pMVDHalContext->u32LastAliveTime[u8Idx]) < 500))
8910 {
8911
8912 if(pMVDHalContext->u32LastAliveTime[u8Idx] == 0 )
8913 {
8914 pMVDHalContext->u32LastAliveTime[u8Idx] = MsOS_GetSystemTime();
8915 }
8916 return E_MVD_RET_OK;
8917 }
8918 }
8919
8920 #if 0
8921 printf("[%d]%d,%d,%d,%d,%d,%d,%d,%d\n",__FUNCTION__,
8922 (MS_U32)MsOS_GetSystemTime(),
8923 (MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DECODEDONE_COUNT, sizeof(MS_U32))),
8924 (MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHBUF_COUNT, sizeof(MS_U32))),
8925 (MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHCODE_COUNT, sizeof(MS_U32))),
8926 (MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PREBUF_COUNT, sizeof(MS_U32))),
8927 (MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_VFIFOBUF_COUNT, sizeof(MS_U32))),
8928 (MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHHEADER_COUNT, sizeof(MS_U32))),
8929 (MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_FLASHPATTERN_COUNT, sizeof(MS_U32))));
8930 #endif
8931
8932 //check count to vertify alive
8933 if((pAliveInfo->u32decode_count!=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DECODEDONE_COUNT, sizeof(MS_U32))))||
8934 (pAliveInfo->u32searchbuf_count!=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHBUF_COUNT, sizeof(MS_U32))))||
8935 (pAliveInfo->u32searchcode_count!=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHCODE_COUNT, sizeof(MS_U32))))||
8936 (pAliveInfo->u32prebuf_count!=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PREBUF_COUNT, sizeof(MS_U32))))||
8937 (pAliveInfo->u32vfifobuf_count!=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_VFIFOBUF_COUNT, sizeof(MS_U32))))||
8938 (pAliveInfo->u32searchheader_count!=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHHEADER_COUNT, sizeof(MS_U32))))||
8939 (pAliveInfo->u32flashpattern_count!=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_FLASHPATTERN_COUNT, sizeof(MS_U32))))||
8940 (pAliveInfo->u32IdleCount!=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_IDLE_COUNT, sizeof(MS_U32)))))
8941
8942 {
8943 pAliveInfo->u32decode_count=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DECODEDONE_COUNT, sizeof(MS_U32)));
8944 pAliveInfo->u32searchbuf_count=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHBUF_COUNT, sizeof(MS_U32)));
8945 pAliveInfo->u32searchcode_count=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHCODE_COUNT, sizeof(MS_U32)));
8946 pAliveInfo->u32prebuf_count=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PREBUF_COUNT, sizeof(MS_U32)));
8947 pAliveInfo->u32vfifobuf_count=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_VFIFOBUF_COUNT, sizeof(MS_U32)));
8948 pAliveInfo->u32searchheader_count=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHHEADER_COUNT, sizeof(MS_U32)));
8949 pAliveInfo->u32flashpattern_count=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_FLASHPATTERN_COUNT, sizeof(MS_U32)));
8950 pAliveInfo->u32IdleCount=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_IDLE_COUNT, sizeof(MS_U32)));
8951 pMVDHalContext->u32LastAliveTime[u8Idx] = MsOS_GetSystemTime();
8952 return E_MVD_RET_OK;
8953 }
8954 else
8955 {
8956 pMVDHalContext->u32LastAliveTime[u8Idx] = MsOS_GetSystemTime();
8957 return E_MVD_RET_FAIL;
8958 }
8959
8960 }
8961
HAL_MVD_Set_Err_Tolerance(MS_U8 u8Idx,MS_U16 u16Para)8962 E_MVD_Result HAL_MVD_Set_Err_Tolerance(MS_U8 u8Idx, MS_U16 u16Para)
8963 {
8964 MVD_CmdArg mvdcmd;
8965 SETUP_CMDARG(mvdcmd);
8966 mvdcmd.Arg0 = u16Para & 0xFF; //enable or disable
8967 mvdcmd.Arg1 = u16Para >> 8; // err rate 0~100%
8968 if(mvdcmd.Arg1 >= 100)
8969 mvdcmd.Arg1 = 100;
8970
8971 SET_DECNUM(mvdcmd, u8Idx);
8972 if (HAL_MVD_MVDCommand(CMD_DECODE_ERROR_TOLERANCE, &mvdcmd) == FALSE)
8973 {
8974 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DECODE_ERROR_TOLERANCE ) );
8975 return E_MVD_RET_FAIL;
8976 }
8977 return E_MVD_RET_OK;
8978
8979 }
8980
HAL_MVD_EnableAutoInsertDummyPattern(MS_U8 u8Idx,MS_BOOL bEnable)8981 void HAL_MVD_EnableAutoInsertDummyPattern(MS_U8 u8Idx, MS_BOOL bEnable)
8982 {
8983 pMVDHalContext->bAutoInsertDummyPattern[u8Idx] = bEnable;
8984 }
8985
HAL_MVD_Drop_One_PTS(MS_U8 u8Idx)8986 void HAL_MVD_Drop_One_PTS(MS_U8 u8Idx)
8987 {
8988 pMVDHalContext->bDropOnePTS[u8Idx] = TRUE;
8989 }
8990
HAL_MVD_PVR_Seamless_mode(MS_U8 u8Idx,MS_U8 u8Arg)8991 E_MVD_Result HAL_MVD_PVR_Seamless_mode(MS_U8 u8Idx, MS_U8 u8Arg)
8992 {
8993 #define STOP_TIMEOUT 500 //ms
8994 MVD_CmdArg mvdcmd;
8995 E_MVD_Result ret = E_MVD_RET_OK;
8996 MS_U32 u32StartTime;
8997 MS_U32 u32SeamlessStatus = 0;
8998 MS_U32 u32BufStart = 0;
8999 MS_U32* temp = 0;
9000
9001 if(u8Arg != 2)
9002 {
9003 // clear handshake dram
9004 u32BufStart = GET_FRMINFO_BUFFADD(u8Idx);
9005 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,u32BufStart,u32BufStart);
9006 temp = (MS_U32*)MsOS_PA2KSEG1(u32BufStart+OFFSET_PVR_SEAMLESS_STATUS);
9007 *temp = 0;
9008 MsOS_FlushMemory();
9009 }
9010
9011 SETUP_CMDARG(mvdcmd);
9012 mvdcmd.Arg0 = u8Arg;
9013 MVD_DEBUGINFO(printf("%s: arg=%d\n", __FUNCTION__, (unsigned int)u8Arg));
9014 SET_DECNUM(mvdcmd, u8Idx);
9015
9016 if (HAL_MVD_MVDCommand(CMD_PVR_SEAMLESS_MODE, &mvdcmd) == FALSE)
9017 {
9018 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PVR_SEAMLESS_MODE ) );
9019 return E_MVD_RET_FAIL;
9020 }
9021
9022
9023 u32StartTime = HAL_MVD_GetTime();
9024
9025 if(u8Arg == 1)
9026 {
9027 pMVDHalContext->stFwCfg[u8Idx].eSrcMode = E_MVD_TS_FILE_MODE;
9028 while(1)
9029 {
9030 u32SeamlessStatus = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PVR_SEAMLESS_STATUS, sizeof(MS_U32));
9031 if(u32SeamlessStatus&1) // bit0 , pause done
9032 {
9033 break;
9034 }
9035
9036 if((HAL_MVD_GetTime()-u32StartTime)>STOP_TIMEOUT)
9037 {
9038 MVD_DEBUGERROR(printf("PVR seamless pause timeout\n" ) );
9039 ret = E_MVD_RET_FAIL;
9040 break;
9041 }
9042 }
9043 }
9044 else if(u8Arg == 2)
9045 {
9046 while(1)
9047 {
9048 u32SeamlessStatus = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PVR_SEAMLESS_STATUS, sizeof(MS_U32));
9049 if(u32SeamlessStatus&4) // bit2, hw reset done
9050 {
9051 break;
9052 }
9053
9054 if((HAL_MVD_GetTime()-u32StartTime)>STOP_TIMEOUT)
9055 {
9056 MVD_DEBUGERROR(printf("PVR seamless hw reset timeout\n" ) );
9057 ret = E_MVD_RET_FAIL;
9058 break;
9059 }
9060 }
9061 }
9062
9063 return ret;
9064 }
9065
HAL_MVD_SetDVXCShmAddr(MS_U8 u8Idx,MS_PHY u32FWBaseAddr,MS_PHY u32DVXCShmAddr)9066 E_MVD_Result HAL_MVD_SetDVXCShmAddr(MS_U8 u8Idx, MS_PHY u32FWBaseAddr, MS_PHY u32DVXCShmAddr)
9067 {
9068 E_MVD_Result ret = E_MVD_RET_OK;
9069
9070 MS_U8 u8XCShmMiuSel;
9071 MS_U32 u32XCShmStartOffset;
9072 MS_U8 u8FWBaseMiuSel;
9073 MS_U32 u32FWBaseOffset;
9074 MVD_CmdArg mvdcmd;
9075 MS_U32 u32temp = 0;
9076
9077 _phy_to_miu_offset(u8FWBaseMiuSel, u32FWBaseOffset, u32FWBaseAddr);
9078 _phy_to_miu_offset(u8XCShmMiuSel, u32XCShmStartOffset, u32DVXCShmAddr);
9079
9080 if (u8FWBaseMiuSel != u8XCShmMiuSel)
9081 {
9082 MVD_DEBUGERROR(printf("[ERROR] XC share memory and VDEC Code base MIU selections are different\n"));
9083 return E_MVD_RET_FAIL;
9084 }
9085
9086 u32temp = u32XCShmStartOffset - u32FWBaseOffset;
9087
9088 SETUP_CMDARG(mvdcmd);
9089
9090 mvdcmd.Arg0 = L_WORD(u32temp);
9091 mvdcmd.Arg1 = H_WORD(u32temp);
9092 mvdcmd.Arg2 = L_DWORD(u32temp);
9093 mvdcmd.Arg3 = H_DWORD(u32temp);
9094
9095 MVD_DEBUGINFO(printf("%s: arg=%x\n", __FUNCTION__, (unsigned int)u32temp));
9096
9097 SET_DECNUM(mvdcmd, u8Idx);
9098
9099 if (HAL_MVD_MVDCommand(CMD_SET_DV_XC_SHM_ADDR, &mvdcmd) == FALSE)
9100 {
9101 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SET_DV_XC_SHM_ADDR ) );
9102 return E_MVD_RET_FAIL;
9103 }
9104
9105 return ret;
9106 }
9107
9108
HAL_MVD_SetDisplayFinishMode(MS_U8 u8Idx,MS_U8 u8Mode)9109 E_MVD_Result HAL_MVD_SetDisplayFinishMode(MS_U8 u8Idx, MS_U8 u8Mode)
9110 {
9111 MVD_CmdArg mvdcmd;
9112
9113 SETUP_CMDARG(mvdcmd);
9114 mvdcmd.Arg0 = u8Mode;
9115
9116 SET_DECNUM(mvdcmd, u8Idx);
9117
9118 MVD_DEBUGINFO(printf("%s CMD_ENABLE_LAST_FRAME_QUALIFIER arg0=%x\n", __FUNCTION__, u8Mode));
9119 if (HAL_MVD_MVDCommand(CMD_ENABLE_LAST_FRAME_QUALIFIER, &mvdcmd)== FALSE)
9120 {
9121 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_ENABLE_LAST_FRAME_QUALIFIER) );
9122 return E_MVD_RET_FAIL;
9123 }
9124
9125 return E_MVD_RET_OK;
9126 }
HAL_MVD_Set_SlowSyncParam(MS_U8 u8Idx,MS_U8 u8RepeatPeriod,MS_U8 u8DropPeriod)9127 E_MVD_Result HAL_MVD_Set_SlowSyncParam(MS_U8 u8Idx, MS_U8 u8RepeatPeriod,MS_U8 u8DropPeriod)
9128 {
9129 MVD_CmdArg mvdcmd;
9130 SETUP_CMDARG(mvdcmd);
9131
9132 mvdcmd.Arg0 = u8RepeatPeriod;
9133
9134 SET_DECNUM(mvdcmd, u8Idx);
9135 if (HAL_MVD_MVDCommand(CMD_SLOW_SYNC_REPEAT, &mvdcmd) == FALSE)
9136 {
9137 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLOW_SYNC_REPEAT ) );
9138 return E_MVD_RET_FAIL;
9139 }
9140
9141
9142 mvdcmd.Arg0 = u8DropPeriod;
9143
9144 SET_DECNUM(mvdcmd, u8Idx);
9145 if (HAL_MVD_MVDCommand(CMD_SLOW_SYNC_SKIP, &mvdcmd) == FALSE)
9146 {
9147 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLOW_SYNC_SKIP ) );
9148 return E_MVD_RET_FAIL;
9149 }
9150
9151
9152 return E_MVD_RET_OK;
9153
9154 }
9155
HAL_MVD_VariableFrameRate(MS_U8 u8Idx)9156 MS_BOOL HAL_MVD_VariableFrameRate(MS_U8 u8Idx)
9157 {
9158 MVD_CmdArg mvdcmd;
9159 SETUP_CMDARG(mvdcmd);
9160 mvdcmd.Arg0 = 1;
9161 SET_DECNUM(mvdcmd, u8Idx);
9162 if (HAL_MVD_MVDCommand(CMD_VARIABLE_FRAMERATE, &mvdcmd)== FALSE)
9163 {
9164 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_VARIABLE_FRAMERATE) );
9165 return FALSE;
9166 }
9167 return TRUE;
9168 }
9169
9170 //------------------------------------------------------------------------------
9171 /// Set FRC Only Show TopField
9172 /// @return -TRUE for success; FALSE for failure.
9173 //------------------------------------------------------------------------------
HAL_MVD_FRC_OnlyShowTopField(MS_U8 u8Idx,MS_BOOL bEnable)9174 MS_BOOL HAL_MVD_FRC_OnlyShowTopField(MS_U8 u8Idx, MS_BOOL bEnable)
9175 {
9176 MVD_CmdArg mvdcmd;
9177
9178 SETUP_CMDARG(mvdcmd);
9179 mvdcmd.Arg0 = bEnable; //1 -> show Only Show TopField. 0 -> normal case.
9180 SET_DECNUM(mvdcmd, u8Idx);
9181 SET_CMD_RET_FALSE(CMD_FRC_ONLY_SHOW_TOP_FIELD, &mvdcmd);
9182 return TRUE;
9183 }
9184
HAL_MVD_DisableESFullStop(MS_U8 u8Idx,MS_BOOL bDisable)9185 MS_BOOL HAL_MVD_DisableESFullStop(MS_U8 u8Idx, MS_BOOL bDisable)
9186 {
9187 MVD_CmdArg mvdcmd;
9188 SETUP_CMDARG(mvdcmd);
9189 mvdcmd.Arg0 = bDisable;
9190 SET_DECNUM(mvdcmd, u8Idx);
9191 if (HAL_MVD_MVDCommand( CMD_ES_FULL_STOP, &mvdcmd ) == FALSE)
9192 {
9193 printf( "Command: 0x%x fail!!\r\n", CMD_ES_FULL_STOP);
9194 return FALSE;
9195 }
9196 return TRUE;
9197 }
9198
HAL_MVD_PUSI_Control(MS_U8 u8Idx,MS_BOOL bEnable)9199 MS_BOOL HAL_MVD_PUSI_Control(MS_U8 u8Idx, MS_BOOL bEnable)
9200 {
9201 MVD_CmdArg mvdcmd;
9202 SETUP_CMDARG(mvdcmd);
9203 mvdcmd.Arg0 = bEnable;
9204 SET_DECNUM(mvdcmd, u8Idx);
9205 if (HAL_MVD_MVDCommand( CMD_PUSI_CONTROL, &mvdcmd ) == FALSE)
9206 {
9207 MVD_PRINT( "Command: 0x%x fail!!\r\n", CMD_PUSI_CONTROL);
9208 return FALSE;
9209 }
9210 return TRUE;
9211 }
9212
9213
HAL_MVD_GetVBBUTableAddr(MS_U8 u8Idx)9214 MS_VIRT HAL_MVD_GetVBBUTableAddr(MS_U8 u8Idx)
9215 {
9216 return pMVDHalContext->stFWBuff[(u8Idx)].u32VBBUTableAdd;
9217 }
9218
HAL_MVD_SetDmxFrameRate(MS_U8 u8HalIdx,MS_U32 u32Value)9219 void HAL_MVD_SetDmxFrameRate(MS_U8 u8HalIdx,MS_U32 u32Value)
9220 {
9221 pMVDHalContext->u32DmxFrameRate[u8HalIdx] = u32Value;
9222 }
9223
HAL_MVD_SetDmxFrameRateBase(MS_U8 u8HalIdx,MS_U32 u32Value)9224 void HAL_MVD_SetDmxFrameRateBase(MS_U8 u8HalIdx,MS_U32 u32Value)
9225 {
9226 pMVDHalContext->u32DmxFrameRateBase[u8HalIdx] = u32Value;
9227 }
9228
HAL_MVD_TrickPlay2xAVSync(MS_U8 u8Idx,MS_BOOL bEnable)9229 void HAL_MVD_TrickPlay2xAVSync(MS_U8 u8Idx,MS_BOOL bEnable)
9230 {
9231 pMVDHalContext->bTrickPlay2xAVSync[u8Idx] = bEnable;
9232 }
9233
HAL_MVD_SetAVSyncDispAutoDrop(MS_U8 u8Idx,MS_BOOL bEnable)9234 MS_BOOL HAL_MVD_SetAVSyncDispAutoDrop(MS_U8 u8Idx, MS_BOOL bEnable)
9235 {
9236 MVD_CmdArg mvdcmd;
9237
9238 SETUP_CMDARG(mvdcmd);
9239 mvdcmd.Arg0 = bEnable;
9240
9241 SET_DECNUM(mvdcmd, u8Idx);
9242
9243 MVD_DEBUGINFO(printf("%s CMD_AUTO_DROP_FRAME_IN_DECODE arg0=%x\n", __FUNCTION__, bEnable));
9244 if (HAL_MVD_MVDCommand(CMD_AUTO_DROP_FRAME_IN_DECODE, &mvdcmd)== FALSE)
9245 {
9246 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_AUTO_DROP_FRAME_IN_DECODE) );
9247 return FALSE;
9248 }
9249
9250 return TRUE;
9251 }
9252
HAL_MVD_SetDynmcDispPath(MS_U8 u8Idx,MS_BOOL bConnect,MVD_DISPLAY_PATH eValue,MS_BOOL bPreSet)9253 MS_BOOL HAL_MVD_SetDynmcDispPath(MS_U8 u8Idx,MS_BOOL bConnect,MVD_DISPLAY_PATH eValue,MS_BOOL bPreSet)
9254 {
9255 MS_U32 u32TimeCnt = 0;
9256 MVD_CmdArg mvdcmd;
9257
9258 HAL_MVD_ResetHandShake(u8Idx, MVD_HANDSHAKE_VSYNC_CONTROL);
9259
9260 SETUP_CMDARG(mvdcmd);
9261 mvdcmd.Arg0 = bConnect;
9262 mvdcmd.Arg1 = eValue;
9263 mvdcmd.Arg2 = bPreSet;
9264
9265 SET_DECNUM(mvdcmd, u8Idx);
9266
9267 MVD_DEBUGINFO(printf("%s CMD_DYNAMIC_MVOP_CONNECT arg0=%x, arg1=%x\n", __FUNCTION__, bConnect,eValue));
9268 if (HAL_MVD_MVDCommand(CMD_DYNAMIC_MVOP_CONNECT, &mvdcmd)== FALSE)
9269 {
9270 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DYNAMIC_MVOP_CONNECT) );
9271 return FALSE;
9272 }
9273
9274 if(bConnect == FALSE) // disconnect, need to do handshake with fw
9275 {
9276 u32TimeCnt = HAL_MVD_GetTime();
9277 while ((HAL_MVD_GetTime() - u32TimeCnt) < CMD_TIMEOUT_MS)
9278 {
9279 if (HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_VSYNC_CONTROL))
9280 {
9281 MVD_DEBUGINFO(printf("\n vsync control finished!\n"));
9282 break;
9283 }
9284 }
9285
9286 MVD_DEBUGINFO(printf("====> %s (t1=%u t2=%u diff=%u)\n", __FUNCTION__,u32TimeCnt, HAL_MVD_GetTime(), (HAL_MVD_GetTime() - u32TimeCnt)));
9287
9288 if (TRUE != HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_VSYNC_CONTROL))
9289 {
9290 MVD_DEBUGINFO(printf("\n***** vsync control timeout *****\n\n"));
9291 return FALSE;
9292 }
9293 }
9294
9295 return TRUE;
9296 }
9297
HAL_MVD_PreConnectInputTsp(MS_U8 u8Idx,MS_BOOL bEnable,MVD_INPUT_TSP eInputTsp,MVD_Original_Stream eStream)9298 MS_BOOL HAL_MVD_PreConnectInputTsp(MS_U8 u8Idx, MS_BOOL bEnable, MVD_INPUT_TSP eInputTsp, MVD_Original_Stream eStream)
9299 {
9300 #ifdef CMD_PRESET_CONNET_INPUT_TSP
9301
9302 MVD_SrcMode curSrcMode = HAL_MVD_GetSrcMode(u8Idx);
9303
9304 if (curSrcMode == E_MVD_TS_MODE)
9305 {
9306 MVD_CmdArg mvdcmd;
9307 MS_U8 u8Input = E_CTL_INPUT_TSP_NONE;
9308
9309 if (bEnable)
9310 {
9311 u8Input = (MS_U8)eInputTsp;
9312 VPRINTF("[NDec][%d] MVD preset tsp, eInputTsp %d\n", u8Idx, eInputTsp);
9313 }
9314 else
9315 {
9316 switch (eStream)
9317 {
9318 case E_MVD_ORIGINAL_MAIN_STREAM:
9319 u8Input = E_CTL_INPUT_TSP_0;
9320 break;
9321 case E_MVD_ORIGINAL_SUB_STREAM:
9322 u8Input = E_CTL_INPUT_TSP_1;
9323 break;
9324 case E_MVD_ORIGINAL_N_STREAM:
9325 default:
9326 u8Input = E_CTL_INPUT_TSP_NONE;
9327 break;
9328 }
9329 VPRINTF("[NDec][%d] MVD no preset tsp, input %d\n", u8Idx, u8Input);
9330 }
9331
9332 SETUP_CMDARG(mvdcmd);
9333 mvdcmd.Arg0 = u8Input;
9334 SET_DECNUM(mvdcmd, u8Idx);
9335
9336 MVD_DEBUGINFO(printf("%s CMD_PRESET_CONNET_INPUT_TSP arg0=%x\n", __FUNCTION__, u8Input));
9337 if (HAL_MVD_MVDCommand(CMD_PRESET_CONNET_INPUT_TSP, &mvdcmd)== FALSE)
9338 {
9339 MVD_DEBUGERROR(printf("Command: 0x%x fail!!\r\n", CMD_PRESET_CONNET_INPUT_TSP));
9340 return FALSE;
9341 }
9342 }
9343 else
9344 {
9345 VPRINTF("[NDec][%d] MVD not TSP input, ignore PRESET_CONNECT_INPUT_TSP\n", u8Idx);
9346 }
9347
9348 return TRUE;
9349
9350 #else
9351
9352 return FALSE;
9353
9354 #endif
9355 }
9356
HAL_MVD_SetCMAInformation(void * cmaInitParam)9357 void HAL_MVD_SetCMAInformation(void* cmaInitParam)
9358 {
9359 pMVDHalContext->bCMAUsed = TRUE;
9360 memcpy((void*)(&pMVDHalContext->cmaInitParam),cmaInitParam,sizeof(struct CMA_Pool_Init_Param));
9361 }
9362
HAL_MVD_GetCMAInformation(MS_U8 u8HalIdx,MS_U64 * u64Addr,MS_SIZE * u64Size,MS_BOOL * bAllocDone)9363 void HAL_MVD_GetCMAInformation(MS_U8 u8HalIdx,MS_U64* u64Addr,MS_SIZE* u64Size,MS_BOOL* bAllocDone)
9364 {
9365 FW_VOL_INFO gvolInfo;
9366 MS_U32 u32VolAddr;
9367
9368 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,GET_VOL_BUFFADD(u8HalIdx),u32VolAddr);
9369
9370 gvolInfo = (*(volatile FW_VOL_INFO*)(MsOS_PA2KSEG1(u32VolAddr)));
9371
9372 *u64Addr = (MS_U64)gvolInfo.CMA_FB_Address;
9373 *u64Size = (MS_SIZE)gvolInfo.CMA_FB_Size;
9374 *bAllocDone = gvolInfo.CMA_AllocDone;
9375
9376 MsOS_ReadMemory();
9377 MsOS_FlushMemory();
9378 }
9379
HAL_MVD_SetCMAAllocateDone(MS_U8 u8HalIdx)9380 void HAL_MVD_SetCMAAllocateDone(MS_U8 u8HalIdx)
9381 {
9382 MS_U8* temp;
9383 MS_VIRT u32VolAddr;
9384
9385 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,GET_VOL_BUFFADD(u8HalIdx),u32VolAddr);
9386
9387 temp = (MS_U8*)(MsOS_PA2KSEG1(u32VolAddr+OFFSET_CMA_ALLOCDONE));
9388
9389 *temp = 1;
9390
9391 MsOS_ReadMemory();
9392 MsOS_FlushMemory();
9393 }
9394
HAL_MVD_SetFrameBufferMiu(MS_U8 u8HalIdx,MS_U8 u8MiuIdx)9395 void HAL_MVD_SetFrameBufferMiu(MS_U8 u8HalIdx,MS_U8 u8MiuIdx)
9396 {
9397 //to do....
9398 }
9399
9400
9401 #ifdef VDEC3
HAL_MVD_IsDisplayCommand(MS_U8 u8Cmd)9402 MS_BOOL HAL_MVD_IsDisplayCommand(MS_U8 u8Cmd)
9403 {
9404
9405 #if 1 // to do.
9406 UNUSED(u8Cmd);
9407 return TRUE;
9408 #else
9409 MS_BOOL ret;
9410 switch(u8Cmd)
9411 {
9412 case CMD_PLAY:
9413 case CMD_STOP:
9414 case CMD_DISPLAY_PAUSE:
9415 case CMD_PAUSE:
9416 case CMD_FLUSH_DISP_QUEUE:
9417 case CMD_VC1_HW_SLQ_RESET:
9418 case CMD_FAST_SLOW:
9419 case CMD_FLIP_RELEASE_FRAME:
9420 case CMD_FD_MASK_DELAY_CNT:
9421 case CMD_PVR_SEAMLESS_MODE:
9422 case CMD_SW_RESET:
9423 case CMD_CODEC_INFO:
9424 case CMD_CODE_OFFSET:
9425 case CMD_VOL_INFO_BUF:
9426 case CMD_FRAME_INFO_BUF:
9427 case CMD_HEADER_INFO_BUF:
9428 case CMD_USER_BUF_START:
9429 case CMD_USER_BUF_SIZE:
9430 case CMD_PTS_TBL_START:
9431 case CMD_DEC_FRAME_INFO_BUF:
9432 case CMD_SLQ_TBL_BUF_END:
9433 case CMD_SLQ_TBL_BUF_START:
9434 case CMD_STREAM_BUF_START:
9435 case CMD_STREAM_BUF_END:
9436 case CMD_FB_BASE:
9437 case CMD_IAP_BUF_START:
9438 case CMD_DP_BUF_START:
9439 case CMD_MV_BUF_START:
9440 case CMD_FB_NUM:
9441 case CMD_DISPLAY_CTL:
9442 case CMD_REPEAT_MODE:
9443 case CMD_DS_VIRTUAL_BOX:
9444 case CMD_ENABLE_FILE_SYNC:
9445 case CMD_RVU_EN:
9446 case CMD_START_DEC_STRICT:
9447 case CMD_SYNC_ON:
9448 case CMD_SET_MST_MODE:
9449 case CMD_SET_MCU_MODE:
9450 ret = TRUE;
9451 break;
9452 default:
9453 ret = FALSE;
9454 break;
9455 }
9456
9457 return ret;
9458 #endif
9459 }
9460
HAL_MVD_IsNormalCommand(MS_U8 u8Cmd)9461 MS_BOOL HAL_MVD_IsNormalCommand(MS_U8 u8Cmd)
9462 {
9463 MS_BOOL ret;
9464
9465 switch(u8Cmd)
9466 {
9467
9468 case CMD_DISP_SPEED_CTRL:
9469 case CMD_STEP_DISP_DECODE_ONE:
9470 case CMD_ENABLE_LAST_FRAME_SHOW:
9471 case CMD_STEP_TO_PTS:
9472 case CMD_SKIP_DATA:
9473 case CMD_DIU_WIDTH_ALIGN:
9474 case CMD_SCALER_INFO_BASE:
9475 case CMD_DYNAMIC_SCALE_BASE:
9476 case CMD_ENABLE_DYNAMIC_SCALE:
9477 case CMD_FORCE_BLUE_SCREEN:
9478 case CMD_FREEZE_DISP:
9479 case CMD_FIXED_FRAME_BUFFER:
9480 case CMD_SEND_UNI_PTS:
9481 case CMD_ENABLE_FREEZE_PIC:
9482 case CMD_PTS_BASE:
9483 case CMD_SINGLE_STEP:
9484 case CMD_PARSE_M4V_PACKMD:
9485 case CMD_SLQ_END:
9486 case CMD_SLQ_START:
9487 case CMD_ENABLE_INT_STAT:
9488 case CMD_SHOW_ONE_FIELD:
9489 case CMD_FRC_OUPUT:
9490 case CMD_FRC_DROP_BEHAVIOR:
9491 case CMD_FORBID_RESOLUTION_CHANGE:
9492 case CMD_DUMP_BITSTREAM_BASE:
9493 case CMD_DUMP_BITSTREAM_LENGTH:
9494 case CMD_SYNC_OFFSET:
9495 case CMD_SYN_THRESHOLD:
9496 case CMD_AVSYNC_FREERUN_THRESHOLD:
9497 case CMD_MVD_FAST_INT:
9498 case CMD_DIVX_PATCH:
9499 case CMD_IDCT_SEL:
9500 case CMD_SLQ_UPDATE_TBL_WPTR:
9501 case CMD_DMA_OVFTH:
9502 case CMD_DMA_UNFTH:
9503 case CMD_UPDATE_FRAME:
9504 case CMD_PTS_TBL_RESET:
9505 case CMD_ENABLE_AUTO_MUTE:
9506 case CMD_FORCE_ALIGN_VSIZE:
9507 case CMD_SUSPEND_DS:
9508 case CMD_PUSH_FIRST_FRAME_DISP:
9509 case CMD_XC_LOW_DELAY_PARA:
9510 case CMD_FP_FILTER:
9511 case CMD_CC_ENABLE_EXTERNAL_BUFFER:
9512 case CMD_CLOSE_CC:
9513 case CMD_PREBUFFER_SIZE:
9514 case CMD_TIME_INCR_PREDICT:
9515 case CMD_ENABLE_VLD_TIMEOUT:
9516 case CMD_SMOOTH_REWIND:
9517 case CMD_DECODE_ERROR_TOLERANCE:
9518 case CMD_MVD_IDLE:
9519 case CMD_PARSER_READ_POSITION:
9520 case CMD_SLQ_GET_TBL_RPTR:
9521 case CMD_DECODE_STATUS:
9522 case CMD_GET_AFD:
9523 case CMD_GET_SYNC_STAT:
9524 case CMD_RD_USER_WP:
9525 case CMD_ENABLE_LAST_FRAME_QUALIFIER:
9526 //case CMD_RD_IO: // no need in V3
9527 //case CMD_WR_IO: // no need in V3
9528 ret = TRUE;
9529 break;
9530 default:
9531 ret = FALSE;
9532 break;
9533 }
9534
9535 return ret;
9536 }
9537
HAL_MVD_IsNeedResponseCommand(MS_U8 u8Cmd)9538 MS_BOOL HAL_MVD_IsNeedResponseCommand(MS_U8 u8Cmd)
9539 {
9540 MS_BOOL ret;
9541
9542 switch(u8Cmd)
9543 {
9544 case CMD_GET_AFD:
9545 case CMD_GET_SYNC_STAT:
9546 case CMD_RD_USER_WP:
9547 case CMD_DECODE_STATUS:
9548 case CMD_PARSER_READ_POSITION:
9549 case CMD_MVD_IDLE:
9550 ret = TRUE;
9551 break;
9552 default:
9553 ret = FALSE;
9554 break;
9555 }
9556
9557 return ret;
9558 }
9559 #endif
9560 #endif
9561