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