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