xref: /utopia/UTPA2-700.0.x/modules/vdec_v3/drv/mvd_v3/drvMVD_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 /// file  drvMVD.c
94 /// @brief MPEG-2/4 Video Decoder Driver
95 /// @author MStar Semiconductor Inc.
96 ///
97 ////////////////////////////////////////////////////////////////////////////////
98 
99 //-------------------------------------------------------------------------------------------------
100 //  Include Files
101 //-------------------------------------------------------------------------------------------------
102 // Common Definition
103 #ifdef MSOS_TYPE_LINUX_KERNEL
104 #include <linux/string.h>
105 #else
106 #include <string.h>
107 #endif
108 #include "MsCommon.h"
109 #include "MsVersion.h"
110 #include "halCHIP.h"
111 #include "drvMMIO.h"
112 #include "drvMIU.h"
113 #include "drvMVD_EX.h"
114 
115 // Internal Definition
116 #include "halMVD_EX.h"
117 #include "asmCPU.h"
118 #include "controller.h"
119 #include "osalMVD_EX.h"
120 #include "drvmvd_cc.h"      //ATSC Closed Caption
121 //#include "drvCMAPool.h" // TODO: wait for system to merge CMA kernel mode
122 #include "drvCMAPool_v2.h"
123 #if defined(MSOS_TYPE_LINUX)
124 #include "msos/linux/mdrv_cma_pool_st.h"
125 #endif
126 #include "mvd4_interface.h" //firmware header
127 #include "MVD_EX_Common.h"
128 
129 #if (!defined(MSOS_TYPE_NUTTX) && !defined(MSOS_TYPE_OPTEE)) || defined(SUPPORT_X_MODEL_FEATURE)
130 #include "ULog.h"
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 // Local defines & local structures
134 ////////////////////////////////////////////////////////////////////////////////
135 //Different level debug message
136 #if ((defined(CHIP_A1) || defined(CHIP_A7) || defined(CHIP_AMETHYST)) && defined (__aeon__))
137 #define MVD_DEBUGVERBAL(x)
138 #define MVD_DEBUGINFO(x)
139 #else
140 #define MVD_DEBUGVERBAL(x)    if (_u8DbgLevel>4)  { (x); }
141 #define MVD_DEBUGINFO(x)      if (_u8DbgLevel>1)  { (x); }
142 #endif
143 #define MVD_DEBUGERROR(x)     if (_u8DbgLevel>0)  { (x); }
144 #define MVD_FUNC_ENTRY()      {}//MVD_PRINT(" $$$ drvMVD::%s\n", __FUNCTION__)
145 
146 
147 
148 
149 
150 #define DISABLE_ISR_DETACH
151 
152 #define _DUMP_FRMINFO         FALSE
153 
154 #define _MS_TO_90K(x)         (x*90)  //ms ==> 90k counter
155 #define _90K_TO_MS(x)         (x/90)  //90k counter ==> ms
156 
157 #define _MVD_GET_IDX(x)       (MS_U8)(((x) >>16) & 0xff)
158 #define _MVD_GET_HAL_SID(x)   (HAL_MVD_StreamId)(((x) >>8) & 0xff)
159 #define _MVD_GET_VPU_SID(x)   (HAL_VPU_StreamId)((x) & 0xff)
160 
161 #define MVD_U32_MAX                 0xffffffffUL
162 #define MVD_U32_MASK               0xf0000000UL
163 #define PB_ONLY_UNMUTE_VSYNC_COUNT          30
164 
165 #ifdef VDEC3
166 #define MVD_MAX_STREAMS         16
167 #else
168 #define MVD_MAX_STREAMS         2
169 #endif
170 
171 #ifdef VDEC3
172 #define v3_temp 1
173 #define v3_thinplayer 0
174 #else
175 #define v3_temp 0
176 #define v3_thinplayer 0
177 #endif
178 ////////////////////////////////////////////////////////////////////////////////
179 // Local Global Variables
180 ////////////////////////////////////////////////////////////////////////////////
181 #if 0
182 /// Version string
183 static MSIF_Version _drv_mvd_version = {
184     .DDI = { MVD_DRV_VERSION, },
185 };
186 
187 static MVD_DrvInfo _stDrvInfo = {
188                                     1,      //1 MVD HW
189                                     0,      //Device#   fixme
190                                     MVD_U32_MAX,        //firmware version
191                                     { FALSE, FALSE, FALSE } //capability
192                                 };
193 
194 static MS_U8 _u8DbgLevel = 0;
195 
196 static MS_BOOL bFrmRateSupported[MVD_MAX_STREAMS];
197 static MVD_FrameInfo stPreFrmInfo[MVD_MAX_STREAMS];
198 static MVD_AVSyncCfg stNFPSyncCfg[MVD_MAX_STREAMS];
199 static MVD_AVSyncCfg stSyncCfg[MVD_MAX_STREAMS];
200 
201 #ifdef MVD_ENABLE_ISR
202 static MVD_InterruptCb _pfnCallback[MVD_MAX_STREAMS];
203 static MS_U32 _eEventFlag[MVD_MAX_STREAMS];
204 static MS_U32 _eCurEvent[MVD_MAX_STREAMS];
205 static MS_U32 _u32CallbackPara[MVD_MAX_STREAMS];
206 #endif
207 
208 static MS_U32 u32SyncDoneCnt = 0;
209 static MS_U32 u32VSyncCnt = 0;
210 static MS_BOOL bMVDIsrAttached = FALSE;
211 static MS_BOOL bSuspendDS_Ftime=TRUE; //to check 3d<->2d mode first time
212 
213 typedef struct
214 {
215     MS_BOOL bUsed;      //updated when init/exit
216     MS_U8   u8HalIdx;   //index used by HAL. use it to communicate with HAL.
217     MS_U16  u16Rsvd;    //reserved bytes
218 
219     MS_U32  u32VpuSid;  //StreamID obtained from VPU by HAL_VPU_GetFreeStream()
220     MS_U32  u32MvdSid;  //StreamID obtained from VPU by HAL_MVD_GetFreeStream()
221 } MVD_Drv_Ctrl;
222 static MVD_Drv_Ctrl gMVDCtrl_EX[MVD_MAX_STREAMS]
223     = { { FALSE, 0, 0, 0, 0},
224         { FALSE, 0, 0, 0, 0},
225       };//ToDo: check when to init/reset!
226 #endif
227 typedef struct
228 {
229     MS_BOOL bUsed;      //updated when init/exit
230     MS_U8   u8HalIdx;   //index used by HAL. use it to communicate with HAL.
231     MS_U16  u16Rsvd;    //reserved bytes
232 
233     MS_U32  u32VpuSid;  //StreamID obtained from VPU by HAL_VPU_GetFreeStream()
234     MS_U32  u32MvdSid;  //StreamID obtained from VPU by HAL_MVD_GetFreeStream()
235 } MVD_Drv_Ctrl;
236 
237 typedef struct
238 {
239     MS_BOOL bFrmRateSupported[MVD_MAX_STREAMS];
240     MVD_FrameInfo stPreFrmInfo[MVD_MAX_STREAMS];
241     MVD_AVSyncCfg stNFPSyncCfg[MVD_MAX_STREAMS];
242     MVD_AVSyncCfg stSyncCfg[MVD_MAX_STREAMS];
243 
244 #ifdef MVD_ENABLE_ISR
245     MVD_InterruptCb _pfnCallback[MVD_MAX_STREAMS];
246     MS_U32 _eEventFlag[MVD_MAX_STREAMS];
247     MS_U32 _eCurEvent[MVD_MAX_STREAMS];
248     MS_U32 _u32CallbackPara[MVD_MAX_STREAMS];
249 #endif
250 
251     MS_U32 u32SyncDoneCnt[MVD_MAX_STREAMS];
252     MS_U32 u32VSyncCnt[MVD_MAX_STREAMS];
253     MS_BOOL bSuspendDS_Ftime[MVD_MAX_STREAMS];
254 
255     MVD_Drv_Ctrl gMVDCtrl_EX[MVD_MAX_STREAMS];//ToDo: check when to init/reset!
256 
257     MS_U8 u8Afd[MVD_MAX_STREAMS];//MDrv_MVD_GetActiveFormat()
258 #if (MVD_TURBO_INIT)
259     MS_U32 u32FrmCnt[MVD_MAX_STREAMS];//MDrv_MVD_GetActiveFormat()
260 #endif
261     MS_BOOL bSelf_SeqChange[MVD_MAX_STREAMS];
262     //pre_set
263     MVD_Pre_Ctrl gMVDPreCtrl[MVD_MAX_STREAMS];
264 
265     MS_U32 u32Id[MVD_MAX_STREAMS];
266 
267 #ifdef VDEC3
268     MS_U32 u32FrameBaseMode[MVD_MAX_STREAMS];
269 #endif
270     MS_BOOL bCMAUsed;
271     MS_BOOL bCMAAllocDone;
272     struct CMA_Pool_Init_Param cmaInitParam; // support two MIU
273     struct CMA_Pool_Free_Param cmaFreeParam[MVD_MAX_STREAMS];
274     MS_BOOL bCMATwoMIU[MVD_MAX_STREAMS];
275     MS_BOOL bTrickPlay2xAVSync[MVD_MAX_STREAMS];
276 } MVD_Drv_CTX;
277 
278 // global variables
279 MVD_Drv_CTX* pMVDDrvContext = NULL;
280 MVD_Drv_CTX gMVDDrvContext;
281 MSIF_Version _drv_mvd_version = {
282                                   .DDI = { MVD_DRV_VERSION, },
283                                 };
284 MVD_DrvInfo _stDrvInfo = {
285                            1,      //1 MVD HW
286                            0,      //Device#   fixme
287                            MVD_U32_MAX,        //firmware version
288                            {FALSE, FALSE, FALSE} //capability
289                          };
290 MS_U8 _u8DbgLevel = 0;
291 MS_BOOL bMVDIsrAttached = FALSE;
292 MS_BOOL _bDisableFlag = TRUE;
293 
294 
295 ////////////////////////////////////////////////////////////////////////////////
296 // Local functions
297 ////////////////////////////////////////////////////////////////////////////////
298 
MVD_Context_Init(void)299 static void MVD_Context_Init(void)
300 {
301     pMVDDrvContext->bSuspendDS_Ftime[0] = TRUE;
302     pMVDDrvContext->bSuspendDS_Ftime[1] = TRUE;
303     pMVDDrvContext->u8Afd[0] = 0xff;
304     pMVDDrvContext->u8Afd[1] = 0xff;
305 }
306 
307 
308 static void MVD_InitVar(MS_U8 u8DrvIdx,MS_U8 u8HalIdx);
309 
MVD_SaveStreamId(MS_U8 u8DrvIdx,MS_U32 u32MvdSid,MS_U32 u32VpuSid)310 static MS_BOOL MVD_SaveStreamId(MS_U8 u8DrvIdx, MS_U32 u32MvdSid, MS_U32 u32VpuSid)
311 {
312     if (pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].bUsed)
313     {
314         MVD_ERR("%s err IsUsed: drv=%x mvd=%x vpu=%x\n", __FUNCTION__,
315             u8DrvIdx, u32MvdSid, u32VpuSid);
316         return FALSE;
317     }
318     pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].u32MvdSid = u32MvdSid;
319     pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].u32VpuSid = u32VpuSid;
320     pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].u8HalIdx = HAL_MVD_SidToIdx((HAL_MVD_StreamId)u32MvdSid);
321     return TRUE;
322 }
323 
MVD_RecordStreamId(MS_U32 u32Id)324 void MVD_RecordStreamId(MS_U32 u32Id)
325 {
326     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
327     pMVDDrvContext->u32Id[u8DrvIdx] = u32Id;
328 }
329 
MVD_GetStreamId(MS_U8 u8Idx)330 MS_U32 MVD_GetStreamId(MS_U8 u8Idx)
331 {
332     return pMVDDrvContext->u32Id[u8Idx];
333 }
334 
MVD_GetHalIdx(MS_U32 u32Id)335 MS_U8 MVD_GetHalIdx(MS_U32 u32Id)
336 {
337     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
338     MS_U8 u8HalIdx = pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].u8HalIdx;
339     return u8HalIdx;
340 }
341 
MVD_GetVpuStreamId(MS_U32 u32Id)342 MS_U32 MVD_GetVpuStreamId(MS_U32 u32Id)
343 {
344     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
345     MS_U32 u32VpuSid = pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].u32VpuSid;
346     return u32VpuSid;
347 }
348 
MDrv_MVD_GetVpuStreamId(MS_U32 u32Id)349 MS_U32 MDrv_MVD_GetVpuStreamId(MS_U32 u32Id)
350 {
351     return MVD_GetVpuStreamId(u32Id);
352 }
MVD_SetIsUsed(MS_U8 u8DrvIdx,MS_BOOL bUsed)353 static MS_BOOL MVD_SetIsUsed(MS_U8 u8DrvIdx, MS_BOOL bUsed)
354 {
355     pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].bUsed = bUsed;
356     //MVD_PRINT("%s u8DrvIdx=0x%x bUsed=%x\n", __FUNCTION__, u8DrvIdx, bUsed);
357     return TRUE;
358 }
359 
MVD_GetIsUsed(MS_U8 u8DrvIdx)360 static MS_BOOL MVD_GetIsUsed(MS_U8 u8DrvIdx)
361 {
362     MS_BOOL bUsed = pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].bUsed;
363     //MVD_PRINT("%s u8DrvIdx=0x%x bUsed=%x\n", __FUNCTION__, u8DrvIdx, bUsed);
364     return bUsed;
365 }
366 
367 #if _DUMP_FRMINFO
MVD_DumpFrmInfo(MVD_FrmInfo * pInfo)368 static void MVD_DumpFrmInfo(MVD_FrmInfo* pInfo)
369 {
370     if (NULL == pInfo)
371     {
372         MVD_ERR("%s: pInfo invalid!\n", __FUNCTION__);
373         return;
374     }
375 
376     MVD_PRINT("u32LumaAddr  =0x%lx\n", pInfo->u32LumaAddr  );
377     MVD_PRINT("u32ChromaAddr=0x%lx\n", pInfo->u32ChromaAddr);
378     MVD_PRINT("u32TimeStamp =0x%lx\n", pInfo->u32TimeStamp );
379     MVD_PRINT("u32ID_L      =0x%lx\n", pInfo->u32ID_L      );
380     MVD_PRINT("u32ID_H      =0x%lx\n", pInfo->u32ID_H      );
381     MVD_PRINT("u16Pitch     =0x%x\n", pInfo->u16Pitch      );
382     MVD_PRINT("u16Width     =0x%x\n", pInfo->u16Width      );
383     MVD_PRINT("u16Height    =0x%x\n", pInfo->u16Height     );
384     MVD_PRINT("eFrmType     =0x%x\n", pInfo->eFrmType      );
385     return;
386 }
387 #endif
388 
389 
390 //------------------------------------------------------------------------------
391 /// Get MVD driver information
392 /// @return -the pointer to the driver information
393 //------------------------------------------------------------------------------
MDrv_MVD_GetInfo(void)394 const MVD_DrvInfo* MDrv_MVD_GetInfo(void)
395 {
396     MDrv_MVD_GetCaps(&(_stDrvInfo.stCaps));
397     _stDrvInfo.u32FWVersion = HAL_MVD_GetDrvFwVer();
398     return (&_stDrvInfo);
399 }
400 
401 
402 //------------------------------------------------------------------------------
403 /// Get MVD driver version
404 /// @return -the pointer to the driver version
405 //------------------------------------------------------------------------------
MDrv_MVD_GetLibVer(const MSIF_Version ** ppVersion)406 E_MVD_Result MDrv_MVD_GetLibVer(const MSIF_Version **ppVersion)
407 {
408     if (!ppVersion)
409         return E_MVD_RET_FAIL;
410 
411     *ppVersion = &_drv_mvd_version;
412     return E_MVD_RET_OK;
413 }
414 
415 
416 //------------------------------------------------------------------------------
417 /// Set detailed level of MVD driver debug message
418 /// 0: None, 1: MVD_DEBUGERROR, 2: MVD_DEBUGINFO
419 /// @param level  \b IN  level from 0 to 2
420 //------------------------------------------------------------------------------
MDrv_MVD_SetDbgLevel(MS_U8 level)421 void MDrv_MVD_SetDbgLevel(MS_U8 level)
422 {
423     _u8DbgLevel = level;
424     VPU_EX_UartLevel eVpuDbgLevel[6] =
425     {
426         E_VPU_EX_UART_LEVEL_NONE,
427         E_VPU_EX_UART_LEVEL_ERR,
428         E_VPU_EX_UART_LEVEL_INFO,
429         E_VPU_EX_UART_LEVEL_DBG,
430         E_VPU_EX_UART_LEVEL_TRACE,
431         E_VPU_EX_UART_LEVEL_FW,
432     };
433 
434     if (level >= 1)
435     {
436         HAL_MVD_SetDbgLevel(level);
437     }
438     if (level<6) HAL_VPU_EX_SetDbgLevel(eVpuDbgLevel[level]);
439 
440     return;
441 }
442 
443 
444 //------------------------------------------------------------------------------
445 /// Get MVD firmware version
446 /// @return -firmware version
447 //------------------------------------------------------------------------------
MDrv_MVD_GetFWVer(MS_U32 u32Id)448 MS_U32 MDrv_MVD_GetFWVer(MS_U32 u32Id)
449 {
450     MS_U32 u32VpuSid = MVD_GetVpuStreamId(u32Id);
451     return HAL_MVD_GetFWVer(u32VpuSid);
452 }
453 
454 //------------------------------------------------------------------------------
455 /// Initialize variables for MVD driver
456 //------------------------------------------------------------------------------
MVD_InitVar(MS_U8 u8DrvIdx,MS_U8 u8HalIdx)457 static void MVD_InitVar(MS_U8 u8DrvIdx,MS_U8 u8HalIdx)
458 {
459     MVD_FrameInfo* pPreInfo = &(pMVDDrvContext->stPreFrmInfo[u8DrvIdx]);
460     HAL_MVD_InitVar(u8HalIdx);
461 
462     pPreInfo->u16HorSize   = 0;
463     pPreInfo->u16VerSize   = 0;
464     pPreInfo->u8AspectRate = 0;
465     pPreInfo->u32FrameRate = 0;
466     pPreInfo->u8Interlace  = 0;
467 
468     memset(&(pMVDDrvContext->stSyncCfg[u8DrvIdx]), 0, sizeof(MVD_AVSyncCfg));
469 
470     pMVDDrvContext->bFrmRateSupported[u8DrvIdx] = TRUE;
471 
472     pMVDDrvContext->u32SyncDoneCnt[0] = 0;
473     pMVDDrvContext->u32SyncDoneCnt[1] = 0;
474     pMVDDrvContext->u32VSyncCnt[0] = 0;
475     pMVDDrvContext->u32VSyncCnt[1] = 0;
476     pMVDDrvContext->u32FrameBaseMode[u8DrvIdx] = FALSE;
477     pMVDDrvContext->bTrickPlay2xAVSync[u8DrvIdx] = FALSE;
478     return;
479 }
480 
481 #if 0
482 static void MVD_DumpMemCfg(MVD_MEMCfg* pCfg)
483 {
484     if (pCfg)
485     {
486         MVD_PRINT("u32FWBinAddr          = 0x%lx\n", pCfg->u32FWBinAddr);
487         MVD_PRINT("u32FWBinSize          = 0x%lx\n", pCfg->u32FWBinSize);
488         MVD_PRINT("u32FWCodeAddr         = 0x%lx\n", pCfg->u32FWCodeAddr);
489         MVD_PRINT("u32FWCodeSize         = 0x%lx\n", pCfg->u32FWCodeSize);
490         MVD_PRINT("u32FBAddr             = 0x%lx\n", pCfg->u32FBAddr);
491         MVD_PRINT("u32FBSize             = 0x%lx\n", pCfg->u32FBSize);
492         MVD_PRINT("u32BSAddr             = 0x%lx\n", pCfg->u32BSAddr);
493         MVD_PRINT("u32BSSize             = 0x%lx\n", pCfg->u32BSSize);
494         MVD_PRINT("u32DrvBufAddr         = 0x%lx\n", pCfg->u32DrvBufAddr);
495         MVD_PRINT("u32DrvBufSize         = 0x%lx\n", pCfg->u32DrvBufSize);
496         MVD_PRINT("u32DynSacalingBufAddr = 0x%lx\n", pCfg->u32DynSacalingBufAddr);
497         MVD_PRINT("u32DynSacalingBufSize = 0x%lx\n", pCfg->u32DynSacalingBufSize);
498         MVD_PRINT("u32Miu1BaseAddr       = 0x%lx\n", pCfg->u32Miu1BaseAddr);
499         MVD_PRINT("bFWMiuSel             = 0x%x\n", pCfg->bFWMiuSel);
500         MVD_PRINT("bHWMiuSel             = 0x%x\n", pCfg->bHWMiuSel);
501     }
502 }
503 #endif
504 
505 //------------------------------------------------------------------------------
506 /// Configure MVD for memory and firmware and info.
507 /// Notice:
508 ///     (1) u32FWAddr & u32DrvBufAddr should be on the same MIU
509 ///     (2) u32FBAddr & u32BSAddr should be on the same MIU
510 /// @param -fwCfg  \b IN : pointer to firmware configuration
511 /// @param -memCfg \b IN : pointer to memory configuration
512 /// @param -InfoCfg \b IN : pointer to mvd info configuration
513 //------------------------------------------------------------------------------
MDrv_MVD_SetCfg(MS_U32 u32Id,MVD_FWCfg * fwCfg,MVD_MEMCfg * memCfg)514 E_MVD_Result MDrv_MVD_SetCfg(MS_U32 u32Id, MVD_FWCfg* fwCfg, MVD_MEMCfg* memCfg)
515 {
516     MS_U8 u8DrvBuffMiuSel = 0;
517     MS_U8  u8HalIdx = MVD_GetHalIdx(u32Id);
518 
519     MVD_FUNC_ENTRY();
520     if (!fwCfg || !memCfg)
521     {
522         return E_MVD_RET_INVALID_PARAM;
523     }
524 
525     MVD_DEBUGINFO(MVD_PRINT("%s u32Id=0x%x, u8HalIdx=0x%x\n", __FUNCTION__, u32Id, u8HalIdx));
526     //1.1 Determine framebuffer mode, frame number, used size.
527     if(pMVDDrvContext->bCMAUsed == FALSE)
528     {
529         if (TRUE != HAL_MVD_CheckFrmBuffSize(u8HalIdx, fwCfg, memCfg))
530         {
531             return E_MVD_RET_INVALID_PARAM;
532         }
533     }
534 
535     MVD_DEBUGINFO(MVD_PRINT("bNotReload=0x%x\n", fwCfg->bNotReload));
536     //1.2 Save the FWCfg in hal
537     HAL_MVD_SetFWCfg(u8HalIdx, fwCfg);
538 
539     MS_U32 u32StartOffset;
540     MS_U8  u8MiuSel;
541 
542     _phy_to_miu_offset(u8MiuSel, u32StartOffset, memCfg->u32FWCodeAddr);
543 
544     memCfg->u8FWMiuSel = u8MiuSel;
545 
546     if(u8MiuSel >= 1)
547     {
548         memCfg->bFWMiuSel = 1;
549     }
550     else
551     {
552         memCfg->bFWMiuSel = 0;
553     }
554 
555     _phy_to_miu_offset(u8MiuSel, u32StartOffset, memCfg->u32BSAddr);
556 
557     memCfg->u8HWMiuSel = u8MiuSel;
558     if(u8MiuSel >= 1)
559     {
560         memCfg->bHWMiuSel = 1;
561     }
562     else
563     {
564         memCfg->bHWMiuSel = 0;
565     }
566 
567     _phy_to_miu_offset(memCfg->u8FBMiuSel, u32StartOffset, memCfg->u32FBAddr);
568 
569     _phy_to_miu_offset(u8MiuSel, u32StartOffset, memCfg->u32DrvBufAddr);
570 
571     u8DrvBuffMiuSel = u8MiuSel;
572 
573     _miu_offset_to_phy(E_CHIP_MIU_1,0,memCfg->u32Miu1BaseAddr);
574     _miu_offset_to_phy(E_CHIP_MIU_2,0,memCfg->u32Miu2BaseAddr);
575     _miu_offset_to_phy(E_CHIP_MIU_3,0,memCfg->u32Miu3BaseAddr);
576 
577     MVD_DEBUGINFO(MVD_PRINT("MIUSEL:: FW=%x HW=%x, miu1base=0x%lx,miu2base=0x%lx,miu3base=0x%lx\n",
578                   memCfg->u8FWMiuSel, memCfg->u8HWMiuSel, (unsigned long)memCfg->u32Miu1BaseAddr,(unsigned long)memCfg->u32Miu2BaseAddr,(unsigned long)memCfg->u32Miu3BaseAddr));
579     MVD_DEBUGINFO(MVD_PRINT("bDrvBuffMiuSel = %x\n", u8DrvBuffMiuSel));
580 
581     if(fwCfg->eSrcMode == E_MVD_SLQ_TBL_MODE)
582     {
583         MS_ASSERT(u8DrvBuffMiuSel == memCfg->u8FWMiuSel);
584     }
585 
586     //addr of memCfg are physical addr, except field u32FWSrcVAddr
587     if (memCfg->eFWSrcType == E_MVD_FW_SOURCE_DRAM)
588     {
589         memCfg->u32FWSrcVAddr = HAL_MVD_PA2NonCacheSeg(memCfg->u32FWBinAddr);
590     }
591     else
592     {
593         memCfg->u32FWSrcVAddr = NULL;
594     }
595     //2.2 Save the memory config in hal
596     HAL_MVD_SetMEMCfg(u8HalIdx, memCfg);
597 
598     return E_MVD_RET_OK;
599 }
600 
MDrv_MVD_RegSetBase(MS_VIRT u32RegBaseAddr)601 void MDrv_MVD_RegSetBase(MS_VIRT u32RegBaseAddr)
602 {
603     HAL_MVD_RegSetBase(u32RegBaseAddr);
604 }
605 
606 //------------------------------------------------------------------------------
607 /// MVD driver initialization
608 /// @return TRUE or FALSE
609 ///     - TRUE, Success
610 ///     - FALSE, Failed
611 //------------------------------------------------------------------------------
MDrv_MVD_Init(MS_U32 u32Id,MVD_CodecType eCodecType,MS_BOOL bShareBBU)612 MS_BOOL MDrv_MVD_Init(MS_U32 u32Id, MVD_CodecType eCodecType, MS_BOOL bShareBBU)
613 {
614     MS_U8  u8DrvIdx = _MVD_GET_IDX(u32Id);
615     MS_U8  u8HalIdx = MVD_GetHalIdx(u32Id);
616     MS_U32 u32VpuSid = MVD_GetVpuStreamId(u32Id);
617     MS_VIRT u32ShmAddr;
618 
619     MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_Init:start u32Id=0x%x, sid=0x%x, halIdx=0x%x, bShareBBU=0x%x\n",
620         u32Id, _MVD_GET_HAL_SID(u32Id), u8HalIdx, bShareBBU));
621 
622     MVD_InitVar(u8DrvIdx,u8HalIdx);
623 
624     u32ShmAddr = HAL_VPU_EX_GetSHMAddr();
625 
626         HAL_VPU_EX_SetShareInfoAddr(u32Id, u32ShmAddr);
627 
628     if (!HAL_MVD_Init(u8HalIdx, eCodecType, u32VpuSid, bShareBBU))
629     {
630         MVD_DEBUGERROR(MVD_ERR("MDrv_MVD_Init:_MVD_Init failed\n"));
631         return FALSE;
632     }
633     else
634     {
635         MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_Init:_MVD_Init success\n"));
636     }
637 
638     MVD_SetIsUsed(u8DrvIdx, TRUE);
639 
640     return TRUE;
641 }
642 
643 
644 //------------------------------------------------------------------------------
645 /// MVD driver exit
646 /// @return TRUE or FALSE
647 ///     - TRUE, Success
648 ///     - FALSE, Failed
649 //------------------------------------------------------------------------------
MDrv_MVD_Exit(MS_U32 u32Id)650 MS_BOOL MDrv_MVD_Exit(MS_U32 u32Id)
651 {
652     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
653     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
654     MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_Exit:start\n"));
655     MVD_DEBUGINFO(MVD_PRINT("%s u8DrvIdx=0x%x u8HalIdx=0x%x u32Id=0x%x\n",__FUNCTION__, u8DrvIdx, u8HalIdx, u32Id));
656 
657     //do nothing if driver is not initialized
658     if (FALSE == MVD_GetIsUsed(u8DrvIdx))
659     {
660         HAL_VPU_EX_ReleaseFreeStream(u8HalIdx);
661         MVD_DEBUGERROR(MVD_ERR("MDrv_MVD_Exit: not-init yet\n"));
662         goto _HW_TILE_DOWN;
663         //HAL_MVD_PowerCtrl(DISABLE);
664         //HAL_VPU_EX_PowerCtrl(DISABLE);
665         return FALSE;
666     }
667 
668     //stop and reset FW/HW
669     if (HAL_MVD_Stop(u8HalIdx) != TRUE)
670     {
671         MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_Exit: stop fail\n"));
672     }
673 
674 #if 0
675     if (pMVDDrvContext->bCMAUsed == TRUE && pMVDDrvContext->bCMAAllocDone == TRUE)
676     {
677         if (MApi_CMA_Pool_PutMem(&pMVDDrvContext->cmaFreeParam[u8DrvIdx]) == FALSE)
678         {
679             return FALSE;
680         }
681         else
682         {
683             pMVDDrvContext->bCMAAllocDone = FALSE;
684         }
685     }
686 #endif
687 #ifdef MVD_ENABLE_ISR
688     //dettach isr
689     if (pMVDDrvContext->_eEventFlag[u8DrvIdx])
690     {
691         if(E_MVD_RET_OK != MDrv_MVD_SetIsrEvent(u32Id, E_MVD_EVENT_DISABLE_ALL, (MVD_InterruptCb)NULL)) //FIXME!
692         {
693             MVD_DEBUGERROR(MVD_ERR("MDrv_MVD_Exit: dettach isr fail\n"));
694         }
695     }
696 #endif
697 
698     if (!HAL_MVD_DeleteTask(u8HalIdx, (HAL_VPU_StreamId)MVD_GetVpuStreamId(u32Id)))
699     {
700         MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_Exit: fail to delete task\n"));
701     }
702 
703 _HW_TILE_DOWN:
704     if (HAL_MVD_Exit(u8HalIdx) != TRUE)
705     {
706         MVD_DEBUGERROR(MVD_ERR("MDrv_MVD_Exit: fail\n"));
707         //return FALSE;
708     }
709 
710     //reset internal variables.
711     MVD_InitVar(u8DrvIdx,u8HalIdx);
712 
713     MVD_DEBUGINFO(MVD_PRINT("%s i=0x%x u32Id=0x%x\n", __FUNCTION__, u8DrvIdx, u32Id));
714     MVD_SetIsUsed(u8DrvIdx, FALSE);
715 
716     return TRUE;
717 }
718 
719 //------------------------------------------------------------------------------
720 /// Reset MVD
721 //------------------------------------------------------------------------------
MDrv_MVD_Rst(MS_U32 u32Id,MVD_CodecType eCodecType,MS_BOOL bShareBBU)722 E_MVD_Result MDrv_MVD_Rst(MS_U32 u32Id, MVD_CodecType eCodecType, MS_BOOL bShareBBU)
723 {
724     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
725     MVD_SrcMode eSrcMode = HAL_MVD_GetSrcMode(u8HalIdx);
726     MVD_FUNC_ENTRY();
727     //stop and reset FW/HW
728     if (HAL_MVD_Stop(u8HalIdx) != TRUE)
729     {
730         MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_Exit: stop fail\n"));
731     }
732 
733     if (!HAL_MVD_DeleteTask(u8HalIdx, (HAL_VPU_StreamId)MVD_GetVpuStreamId(u32Id)))
734     {
735         MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_Rst: fail to delete task\n"));
736     }
737 
738     //For T3&Euclid MVD4, do re-init only when SoftRst does not work.
739     if (FALSE == MDrv_MVD_Init(u32Id, eCodecType, bShareBBU))
740     {
741         MVD_DEBUGERROR(MVD_ERR("MDrv_MVD_Rst:_MVD_Init failed\n"));
742         return E_MVD_RET_FAIL;
743     }
744     else
745     {
746         MVD_DEBUGERROR(MVD_ERR("MDrv_MVD_Rst:_MVD_Init success\n"));
747     }
748 
749     extern const MS_U8 bMvdParserDisable[5];
750     if(MDrv_MVD_SetCodecInfo(u32Id, eCodecType, eSrcMode, bMvdParserDisable[eSrcMode]) == FALSE)
751     {
752         return E_MVD_RET_FAIL;
753     }
754 
755     MDrv_MVD_Play(u32Id);
756 
757     return E_MVD_RET_OK;
758 }
759 
760 //------------------------------------------------------------------------------
761 /// Issue Play command to MVD
762 //------------------------------------------------------------------------------
MDrv_MVD_Play(MS_U32 u32Id)763 void MDrv_MVD_Play(MS_U32 u32Id)
764 {
765     MVD_FUNC_ENTRY();
766     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
767     if (TRUE != HAL_MVD_Play(u8HalIdx))
768     {
769         MVD_DEBUGERROR(MVD_ERR("%s fail\n", __FUNCTION__));
770     }
771     return;
772 }
773 
774 //------------------------------------------------------------------------------
775 /// Set frame buffer address to MVD
776 /// @param -u32addr \b IN : start address
777 //------------------------------------------------------------------------------
MDrv_MVD_SetFrameBuffAddr(MS_U32 u32Id,MS_VIRT u32addr)778 void MDrv_MVD_SetFrameBuffAddr(MS_U32 u32Id, MS_VIRT u32addr)
779 {
780     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
781 
782     HAL_MVD_SetFrameBuffAddr(u8HalIdx, u32addr, HAL_MVD_GetFBMode(u8HalIdx));
783 }
784 
785 //------------------------------------------------------------------------------
786 /// Set codec type.
787 /// @param -u8CodecType \b IN : 0: mpeg4, 1: mpeg4 with short_video_header, 2: DivX311
788 /// @param -u8BSProviderMode \b IN : TS live stream, file, SLQ, SLQ table link and TS file mode.
789 //------------------------------------------------------------------------------
MDrv_MVD_SetCodecInfo(MS_U32 u32Id,MVD_CodecType u8CodecType,MVD_SrcMode u8BSProviderMode,MS_U8 bDisablePESParsing)790 MS_BOOL MDrv_MVD_SetCodecInfo(MS_U32 u32Id, MVD_CodecType u8CodecType, MVD_SrcMode u8BSProviderMode, MS_U8 bDisablePESParsing)
791 {
792     return _MVD_Init(u32Id,u8CodecType,u8BSProviderMode,bDisablePESParsing);
793 }
794 
795 //------------------------------------------------------------------------------
796 /// Set DivX patch.
797 /// @param -u8MvAdjust \b IN : chroma adjustment
798 /// @param -u8IdctSel \b IN : idct algorithm selection
799 //------------------------------------------------------------------------------
MDrv_MVD_SetDivXCfg(MS_U32 u32Id,MS_U8 u8MvAdjust,MS_U8 u8IdctSel)800 void MDrv_MVD_SetDivXCfg(MS_U32 u32Id, MS_U8 u8MvAdjust, MS_U8 u8IdctSel)
801 {
802     MVD_FUNC_ENTRY();
803     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
804     HAL_MVD_SetDivXCfg(u8HalIdx, u8MvAdjust, u8IdctSel);
805     return;
806 }
807 
808 
809 //------------------------------------------------------------------------------
810 /// Get MVD decoded picture counter
811 /// @return -decoded picture counter
812 //------------------------------------------------------------------------------
MDrv_MVD_GetPicCounter(MS_U32 u32Id)813 MS_U32 MDrv_MVD_GetPicCounter(MS_U32 u32Id)
814 {
815     MVD_FUNC_ENTRY();
816     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
817     return HAL_MVD_GetPicCounter(u8HalIdx);
818 }
819 
820 
821 //------------------------------------------------------------------------------
822 /// Get MVD skipped picture counter
823 /// @return -skipped picture counter
824 //------------------------------------------------------------------------------
MDrv_MVD_GetSkipPicCounter(MS_U32 u32Id)825 MS_U32 MDrv_MVD_GetSkipPicCounter(MS_U32 u32Id)
826 {
827     MVD_FUNC_ENTRY();
828     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
829     return HAL_MVD_GetSkipPicCounter(u8HalIdx);
830 }
831 
832 //------------------------------------------------------------------------------
833 /// Get MVD picture type
834 /// @return - picture type
835 //------------------------------------------------------------------------------
MDrv_MVD_GetPicType(MS_U32 u32Id)836 MVD_PicType MDrv_MVD_GetPicType(MS_U32 u32Id)
837 {
838     MVD_FUNC_ENTRY();
839     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
840     return HAL_MVD_GetPicType(u8HalIdx);
841 }
842 
843 //------------------------------------------------------------------------------
844 /// Get MVD bit rate (bits/sec)
845 /// @return -bit rate
846 //------------------------------------------------------------------------------
MDrv_MVD_GetBitsRate(MS_U32 u32Id)847 MS_U32 MDrv_MVD_GetBitsRate(MS_U32 u32Id)
848 {
849     MVD_FUNC_ENTRY();
850     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
851     return HAL_MVD_GetBitsRate(u8HalIdx);
852 }
853 
854 
855 //------------------------------------------------------------------------------
856 /// Get video_range flag.
857 /// Supported after MVD FW release v00720390
858 /// Color team need this information for better color quality.
859 /// When video_range = 0  gives a range of Y from 16 to 235 and Cb , Cr from 16 to 240
860 /// When video_range = 1  gives a range of Y from  0 to 255 and Cb , Cr from  0 to 255
861 /// @return -video_range
862 //------------------------------------------------------------------------------
MDrv_MVD_GetVideoRange(MS_U32 u32Id)863 MS_U8 MDrv_MVD_GetVideoRange(MS_U32 u32Id)
864 {
865     MVD_FUNC_ENTRY();
866     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
867     return HAL_MVD_GetVideoRange(u8HalIdx);
868 }
869 
870 //------------------------------------------------------------------------------
871 /// Get LowDelay flag
872 /// @return -True/False
873 //------------------------------------------------------------------------------
MDrv_MVD_GetLowDelayFlag(MS_U32 u32Id)874 MS_BOOL MDrv_MVD_GetLowDelayFlag(MS_U32 u32Id)
875 {
876     MVD_FUNC_ENTRY();
877     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
878     return HAL_MVD_GetLowDelayFlag(u8HalIdx);
879 }
880 
881 //------------------------------------------------------------------------------
882 /// Get MPEG 3:2 pull down flag
883 /// @return -TRUE or FALSE
884 //------------------------------------------------------------------------------
MDrv_MVD_GetIs32PullDown(MS_U32 u32Id)885 MS_BOOL MDrv_MVD_GetIs32PullDown(MS_U32 u32Id)
886 {
887     MVD_FUNC_ENTRY();
888     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
889     return HAL_MVD_GetIs32PullDown(u8HalIdx);
890 }
891 
892 //------------------------------------------------------------------------------
893 /// Get if Dynamic Scaling is enabled (reported by firmware)
894 /// @return -TRUE or FALSE
895 //------------------------------------------------------------------------------
MDrv_MVD_GetIsDynScalingEnabled(MS_U32 u32Id)896 MS_BOOL MDrv_MVD_GetIsDynScalingEnabled(MS_U32 u32Id)
897 {
898     MVD_FUNC_ENTRY();
899     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
900     MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8HalIdx);
901     MS_BOOL bEnDynScale = FALSE;
902 
903     bEnDynScale = (MS_BOOL)HAL_MVD_GetIsDynScalingEnabled(u8HalIdx);
904     if ((FALSE == pstMemCfg->bEnableDynScale) && (bEnDynScale))
905     {
906         MVD_DEBUGERROR(MVD_ERR("bEnDynScale err: %x\n", bEnDynScale));
907     }
908 
909     //MVD_PRINT("%s bEnDS: %x, %x\n", __FUNCTION__, bEnDynScale, pstMemCfg->bEnableDynScale);
910     return bEnDynScale;
911 }
912 
913 //------------------------------------------------------------------------------
914 /// Get the difference of PTS and STC
915 /// @return -(PTS-STC)
916 //------------------------------------------------------------------------------
MDrv_MVD_GetPtsStcDiff(MS_U32 u32Id)917 MS_S32 MDrv_MVD_GetPtsStcDiff(MS_U32 u32Id)
918 {
919     MVD_FUNC_ENTRY();
920     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
921     return HAL_MVD_GetPtsStcDiff(u8HalIdx);
922 }
923 
924 //------------------------------------------------------------------------------
925 /// Get MVD SLQ read pointer
926 /// @return -SLQ read pointer
927 //------------------------------------------------------------------------------
MDrv_MVD_GetSLQReadPtr(MS_U32 u32Id)928 MS_U32 MDrv_MVD_GetSLQReadPtr(MS_U32 u32Id)
929 {
930     MVD_FUNC_ENTRY();
931     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
932     return HAL_MVD_GetSLQReadPtr(u8HalIdx);
933 }
934 //------------------------------------------------------------------------------
935 /// Get MVD SLQ write pointer
936 /// @return -SLQ write pointer
937 //------------------------------------------------------------------------------
938 
MDrv_MVD_SetSLQWritePtr(MS_U32 u32Id,MS_BOOL bCheckData)939 void MDrv_MVD_SetSLQWritePtr(MS_U32 u32Id, MS_BOOL bCheckData)
940 {
941     MVD_FUNC_ENTRY();
942     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
943     HAL_MVD_SetSLQWritePtr(u8HalIdx, bCheckData);
944     return;
945 }
946 //------------------------------------------------------------------------------
947 /// Get MVD decoded frame index.  For debug.
948 /// @return -frame index of the decoded frame
949 //------------------------------------------------------------------------------
MDrv_MVD_GetDecodedFrameIdx(MS_U32 u32Id)950 MS_U8 MDrv_MVD_GetDecodedFrameIdx(MS_U32 u32Id)
951 {
952     MVD_FUNC_ENTRY();
953     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
954     return HAL_MVD_GetDecodedFrameIdx(u8HalIdx);
955 }
956 
957 //------------------------------------------------------------------------------
958 /// Get MVD VLD error count
959 /// @return -VLD error count
960 //------------------------------------------------------------------------------
MDrv_MVD_GetVldErrCount(MS_U32 u32Id)961 MS_U32 MDrv_MVD_GetVldErrCount(MS_U32 u32Id)
962 {
963     MVD_FUNC_ENTRY();
964     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
965     return HAL_MVD_GetVldErrCount(u8HalIdx);
966 }
967 
968 
969 //------------------------------------------------------------------------------
970 /// Get MVD error info.
971 /// This function can be used to diagnosis when the 1st DispReady doesn't occur.
972 ///
973 /// @param - errorCode \b OUT : error code
974 /// @param - errorStatus \b OUT : error status
975 //------------------------------------------------------------------------------
MDrv_MVD_GetErrInfo(MS_U32 u32Id,MVD_ErrCode * errCode,MVD_ErrStatus * errStatus)976 void MDrv_MVD_GetErrInfo(MS_U32 u32Id, MVD_ErrCode *errCode, MVD_ErrStatus *errStatus)
977 {
978     MVD_FUNC_ENTRY();
979     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
980     HAL_MVD_GetErrInfo(u8HalIdx, errCode, errStatus);
981     return;
982 }
983 
984 //------------------------------------------------------------------------------
985 /// Get valid MVD stream detected flag
986 /// For MPEG2/4,
987 ///     1. width<16(1 macroblock), height<16, width>1920, or height>1080
988 ///     2. next start code not found
989 /// the stream would be considered as invalid.
990 /// For VC1/RCV, not impelment, default: valid
991 /// @return -decoded flag
992 //------------------------------------------------------------------------------
MDrv_MVD_GetValidStreamFlag(MS_U32 u32Id)993 MS_BOOL MDrv_MVD_GetValidStreamFlag(MS_U32 u32Id)
994 {
995     MVD_FUNC_ENTRY();
996     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
997     return HAL_MVD_GetValidStreamFlag(u8HalIdx);
998 }
999 
1000 //------------------------------------------------------------------------------
1001 /// Get video frame information from MVD
1002 /// (SourceW * ParH) : (SourceH * ParW) = DarW : DarH
1003 /// E.g. Source PAL 704x576, Par(Pixel aspect ratio)=12/11,
1004 ///      Dar(Display AR) = (704x12):(576x11) = 4:3
1005 /// @param -pinfo \b IN : pointer to video frame information
1006 //------------------------------------------------------------------------------
MDrv_MVD_GetFrameInfo(MS_U32 u32Id,MVD_FrameInfo * pinfo)1007 void MDrv_MVD_GetFrameInfo(MS_U32 u32Id, MVD_FrameInfo *pinfo)
1008 {
1009     MVD_FUNC_ENTRY();
1010     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1011     HAL_MVD_GetFrameInfo(u8HalIdx, pinfo);
1012 }
1013 
1014 //------------------------------------------------------------------------------
1015 /// Set video frame information from MVD
1016 /// @param -pinfo \b IN : pointer to video frame information
1017 //------------------------------------------------------------------------------
MDrv_MVD_SetFrameInfo(MS_U32 u32Id,MVD_FrameInfo * pinfo)1018 void MDrv_MVD_SetFrameInfo(MS_U32 u32Id, MVD_FrameInfo *pinfo )
1019 {
1020     MVD_FUNC_ENTRY();
1021     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1022     HAL_MVD_SetFrameInfo(u8HalIdx, pinfo);
1023     return;
1024 }
1025 
1026 //------------------------------------------------------------------------------
1027 /// Reset for I-frame decoding
1028 /// @return -none
1029 //------------------------------------------------------------------------------
MDrv_MVD_RstIFrameDec(MS_U32 u32Id,MVD_CodecType eCodecType,MS_BOOL bShareBBU)1030 void MDrv_MVD_RstIFrameDec(MS_U32 u32Id, MVD_CodecType eCodecType, MS_BOOL bShareBBU)
1031 {
1032     MVD_FUNC_ENTRY();
1033     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1034     if (HAL_MVD_Stop(u8HalIdx) == FALSE)
1035     {
1036         MVD_DEBUGERROR(MVD_ERR("%s fail!!\n", __FUNCTION__));
1037     }
1038 
1039     MDrv_MVD_Rst(u32Id, eCodecType, bShareBBU);
1040     return;
1041 }
1042 
1043 //------------------------------------------------------------------------------
1044 /// Decode I-frame
1045 /// @param -u32FrameBufAddr \b IN : start address of frame buffer
1046 /// @param -u32StreamBufAddr \b IN : start address of stream buffer
1047 /// @return -return decode I-frame success or not
1048 //------------------------------------------------------------------------------
MDrv_MVD_DecodeIFrame(MS_U32 u32Id,MS_PHY u32FrameBufAddr,MS_PHY u32StreamBufAddr,MS_PHY u32StreamBufEndAddr)1049 MS_BOOL MDrv_MVD_DecodeIFrame(MS_U32 u32Id, MS_PHY u32FrameBufAddr, MS_PHY u32StreamBufAddr, MS_PHY u32StreamBufEndAddr )
1050 {
1051     MS_BOOL bRet = FALSE;
1052     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1053     MVD_DEBUGINFO(MVD_PRINT("%s input  FBAdd=0x%lx streamStart=0x%lx streamEnd=0x%lx\n",
1054             __FUNCTION__, (unsigned long)u32FrameBufAddr, (unsigned long)u32StreamBufAddr, (unsigned long)u32StreamBufEndAddr));
1055     u32FrameBufAddr     = HAL_MVD_GetMemOffset(u32FrameBufAddr);
1056     u32StreamBufAddr    = HAL_MVD_GetMemOffset(u32StreamBufAddr);
1057     u32StreamBufEndAddr = HAL_MVD_GetMemOffset(u32StreamBufEndAddr);
1058     MVD_DEBUGINFO(MVD_PRINT("%s offset FBAdd=0x%lx streamStart=0x%lx streamEnd=0x%lx\n",
1059             __FUNCTION__, (unsigned long)u32FrameBufAddr, (unsigned long)u32StreamBufAddr, (unsigned long)u32StreamBufEndAddr));
1060 
1061     bRet = HAL_MVD_DecodeIFrame(u8HalIdx, u32FrameBufAddr, u32StreamBufAddr, u32StreamBufEndAddr);
1062     return bRet;
1063 }
1064 
1065 //------------------------------------------------------------------------------
1066 /// Query if MVD is decoding frame
1067 /// @return -MVD is decoding frame or not
1068 //------------------------------------------------------------------------------
MDrv_MVD_GetIsIFrameDecoding(MS_U32 u32Id)1069 MS_BOOL MDrv_MVD_GetIsIFrameDecoding(MS_U32 u32Id)
1070 {
1071     MS_BOOL bDecodeIFrame = FALSE;
1072     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1073     MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1074     if (pCtrlCfg)
1075     {
1076         bDecodeIFrame = pCtrlCfg->bDecodeIFrame;
1077     }
1078     return bDecodeIFrame;
1079 }
1080 
1081 //------------------------------------------------------------------------------
1082 /// Get MVD active format
1083 /// @return -active format
1084 //------------------------------------------------------------------------------
MDrv_MVD_GetActiveFormat(MS_U32 u32Id)1085 MS_U8 MDrv_MVD_GetActiveFormat(MS_U32 u32Id)
1086 {
1087     MVD_FUNC_ENTRY();
1088     //set default as invalid AFD that is ignored by AP.
1089     //static MS_U8 u8Afd[MVD_MAX_STREAMS] = { 0xff, 0xff};
1090     MS_U8  u8DrvIdx = _MVD_GET_IDX(u32Id);
1091     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1092 #if (MVD_TURBO_INIT)
1093     //static MS_U32 u32FrmCnt[MVD_MAX_STREAMS] = { 0, 0};
1094 
1095     if (pMVDDrvContext->u32FrmCnt[u8DrvIdx] == HAL_MVD_GetPicCounter(u8HalIdx))
1096     {
1097         return pMVDDrvContext->u8Afd[u8DrvIdx];
1098     }
1099     pMVDDrvContext->u32FrmCnt[u8DrvIdx] = HAL_MVD_GetPicCounter(u8HalIdx);
1100 #endif
1101     pMVDDrvContext->u8Afd[u8DrvIdx] = HAL_MVD_GetActiveFormat(u8HalIdx);
1102     return pMVDDrvContext->u8Afd[u8DrvIdx];
1103 }
1104 
1105 //------------------------------------------------------------------------------
1106 /// Enable or disable AV synchronization.
1107 /// Delay u32Delay ms if AVSync is enabled.
1108 /// @return -none
1109 //------------------------------------------------------------------------------
MDrv_MVD_SetAVSync(MS_U32 u32Id,MS_BOOL bEnable,MS_U32 u32Delay)1110 void MDrv_MVD_SetAVSync(MS_U32 u32Id, MS_BOOL bEnable, MS_U32 u32Delay)
1111 {
1112     //MVD_PRINT("%s bEnable=%d u32Delay=%ld\n",__FUNCTION__,bEnable,u32Delay);
1113     MVD_FUNC_ENTRY();
1114     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
1115     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1116     if (TRUE != HAL_MVD_EnableAVSync(u8HalIdx, bEnable))
1117     {
1118         MVD_DEBUGERROR(MVD_ERR("%s: fail to set avsync on\n", __FUNCTION__));
1119         return;
1120     }
1121     //bAVSyncOn = bEnable;    //for IsAVSyncOn
1122 
1123     if (bEnable && (u32Delay != 0))
1124     {
1125         if (TRUE != HAL_MVD_SetAVSyncDelay(u8HalIdx, u32Delay))
1126         {
1127             MVD_DEBUGERROR(MVD_ERR("%s: fail to set avsync delay\n", __FUNCTION__));
1128             return;
1129         }
1130     }
1131 
1132     pMVDDrvContext->stSyncCfg[u8DrvIdx].bEnable = bEnable;
1133     pMVDDrvContext->stSyncCfg[u8DrvIdx].u32Delay = u32Delay;
1134     return;
1135 }
1136 
1137 //------------------------------------------------------------------------------
1138 /// Set the maximum repeat times for one frame when av is not sync.
1139 /// E.g. Arg5=0x01 mean that frame will be repeated once if av is not sync.
1140 ///      Arg5=0xff mean that frame will be always repeated when av is not sync.
1141 /// And customer can re-define the avsync skip behavior,
1142 /// i.e., Arg4 = 1 for skip-b-frame only and 0 for skip display(default)
1143 /// @return -none
1144 //------------------------------------------------------------------------------
MDrv_MVD_SetAVSyncThreshold(MS_U32 u32Id,MS_U32 u32Th)1145 void MDrv_MVD_SetAVSyncThreshold(MS_U32 u32Id, MS_U32 u32Th)
1146 {
1147     MVD_FUNC_ENTRY();
1148     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1149     HAL_MVD_SetAVSyncThreshold(u8HalIdx, u32Th);
1150     return;
1151 }
1152 
1153 //------------------------------------------------------------------------------
1154 /// Set the threshold for VC1 avsync (live mode & file mode). Unit: 90K
1155 /// @return -none
1156 //------------------------------------------------------------------------------
MDrv_MVD_SetAVSyncFreerunThreshold(MS_U32 u32Id,MS_U32 u32Th)1157 void MDrv_MVD_SetAVSyncFreerunThreshold(MS_U32 u32Id, MS_U32 u32Th)
1158 {
1159     MVD_FUNC_ENTRY();
1160     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1161     HAL_MVD_SetAVSyncFreerunThreshold(u8HalIdx, u32Th);
1162     return;
1163 }
1164 
1165 //------------------------------------------------------------------------------
1166 /// Get MVD AVSync delay (ms)
1167 /// @return -avsync delay
1168 //------------------------------------------------------------------------------
MDrv_MVD_GetAVSyncDelay(MS_U32 u32Id)1169 MS_U32 MDrv_MVD_GetAVSyncDelay(MS_U32 u32Id)
1170 {
1171     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
1172     return (pMVDDrvContext->stSyncCfg[u8DrvIdx].u32Delay);
1173 }
1174 
1175 //------------------------------------------------------------------------------
1176 /// Get if AVSync is turned on
1177 /// @return -TRUE for yes or FALSE for no
1178 //------------------------------------------------------------------------------
MDrv_MVD_GetIsAVSyncOn(MS_U32 u32Id)1179 MS_BOOL MDrv_MVD_GetIsAVSyncOn(MS_U32 u32Id)
1180 {
1181     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1182     return HAL_MVD_GetIsAVSyncOn(u8HalIdx);
1183 }
1184 
1185 //------------------------------------------------------------------------------
1186 /// Get if firmware is repeating frame for AVSync.
1187 /// @return -TRUE for yes or FALSE for no
1188 //------------------------------------------------------------------------------
MDrv_MVD_GetIsSyncRep(MS_U32 u32Id)1189 MS_BOOL MDrv_MVD_GetIsSyncRep(MS_U32 u32Id)
1190 {
1191     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1192     return HAL_MVD_GetIsSyncRep(u8HalIdx);
1193 }
1194 
1195 //------------------------------------------------------------------------------
1196 /// Get if firmware is skipping frame for AVSync.
1197 /// @return -TRUE for yes or FALSE for no
1198 //------------------------------------------------------------------------------
MDrv_MVD_GetIsSyncSkip(MS_U32 u32Id)1199 MS_BOOL MDrv_MVD_GetIsSyncSkip(MS_U32 u32Id)
1200 {
1201     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1202     return HAL_MVD_GetIsSyncSkip(u8HalIdx);
1203 }
1204 
1205 //------------------------------------------------------------------------------
1206 /// Change PTS threshold for doing AVSync.
1207 /// Scenario: When disable black screen earlier than normal case, use this function
1208 /// to avoid frame skip too fast or video lag.
1209 /// @param -bEnable \b IN : enable this configuration
1210 /// @param -u16PTS \b IN : PTS threshold (unit: 90k counter, i.e. x/90 ms, max 728ms)
1211 /// @return -TRUE for success or FALSE for failure.
1212 //------------------------------------------------------------------------------
MDrv_MVD_ChangeAVsync(MS_U32 u32Id,MS_BOOL bEnable,MS_U16 u16PTS)1213 MS_BOOL MDrv_MVD_ChangeAVsync(MS_U32 u32Id, MS_BOOL bEnable, MS_U16 u16PTS)
1214 {
1215     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
1216     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1217     if (HAL_MVD_ChangeAVsync(u8HalIdx, bEnable, u16PTS) == TRUE)
1218     {
1219         pMVDDrvContext->stSyncCfg[u8DrvIdx].u16Tolerance = u16PTS;
1220         return TRUE;
1221     }
1222     return FALSE;
1223 }
1224 
1225 //------------------------------------------------------------------------------
1226 /// Get address of the first I-frame.
1227 /// @return -address of the first I-frame
1228 //------------------------------------------------------------------------------
MDrv_MVD_GetIsIPicFound(MS_U32 u32Id)1229 MS_U8 MDrv_MVD_GetIsIPicFound(MS_U32 u32Id)
1230 {
1231     MVD_FUNC_ENTRY();
1232     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1233     return HAL_MVD_GetIsIPicFound(u8HalIdx);
1234 }
1235 
1236 //------------------------------------------------------------------------------
1237 /// Get sync status to know whether sync is complete or not
1238 /// @return - 1        : sync complete
1239 ////        - otherwise: sync not complete
1240 //------------------------------------------------------------------------------
MDrv_MVD_GetSyncStatus(MS_U32 u32Id)1241 MS_U8 MDrv_MVD_GetSyncStatus(MS_U32 u32Id)
1242 {
1243     MVD_FUNC_ENTRY();
1244     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1245     return HAL_MVD_GetIsSyncReach(u8HalIdx);
1246 }
1247 
1248 //------------------------------------------------------------------------------
1249 /// Report if decoder is freerun or not
1250 /// @return - TRUE  : freerun
1251 ////        - FALSE : not freerun
1252 //------------------------------------------------------------------------------
MDrv_MVD_GetIsFreerun(MS_U32 u32Id)1253 MS_BOOL MDrv_MVD_GetIsFreerun(MS_U32 u32Id)
1254 {
1255     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1256     return (HAL_MVD_GetAVSyncStatus(u8HalIdx) == 0);
1257 }
1258 
1259 //------------------------------------------------------------------------------
1260 /// Get PTS (Presentation Time Stamp)
1261 /// @return -PTS (unit: ms)
1262 //------------------------------------------------------------------------------
MDrv_MVD_GetPTS(MS_U32 u32Id)1263 MS_U32 MDrv_MVD_GetPTS(MS_U32 u32Id)
1264 {
1265     MVD_FUNC_ENTRY();
1266     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1267     return HAL_MVD_GetPTS(u8HalIdx);
1268 }
1269 
1270 //------------------------------------------------------------------------------
1271 /// Get 33 bits PTS (Presentation Time Stamp)
1272 /// @return -PTS (unit: ms)
1273 //------------------------------------------------------------------------------
MDrv_MVD_GetU64PTS(MS_U32 u32Id,MVD_PtsType eType)1274 MS_U64 MDrv_MVD_GetU64PTS(MS_U32 u32Id,MVD_PtsType eType)
1275 {
1276     MVD_FUNC_ENTRY();
1277     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1278     return HAL_MVD_GetU64PTS(u8HalIdx,eType);
1279 }
1280 
1281 //------------------------------------------------------------------------------
1282 /// Get Next PTS (Presentation Time Stamp)
1283 /// @return -Next PTS (unit: ms)
1284 //------------------------------------------------------------------------------
MDrv_MVD_GetNextPTS(MS_U32 u32Id)1285 MS_U32 MDrv_MVD_GetNextPTS(MS_U32 u32Id)
1286 {
1287     MVD_FUNC_ENTRY();
1288     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1289     return HAL_MVD_GetNextPTS(u8HalIdx);
1290 }
1291 
1292 //------------------------------------------------------------------------------
1293 /// Get Chroma format (MDrv_MVD_GetChromaFormat)
1294 /// @return -Chroma format ()
1295 //------------------------------------------------------------------------------
MDrv_MVD_GetChromaFormat(MS_U32 u32Id)1296 MS_U32 MDrv_MVD_GetChromaFormat(MS_U32 u32Id)
1297 {
1298     MVD_FUNC_ENTRY();
1299     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1300     return HAL_MVD_GetChromaFormat(u8HalIdx);
1301 }
1302 
1303 //------------------------------------------------------------------------------
1304 /// Query if MVD is ready to display
1305 /// @return -MS_U8  0: not ready, !0: ready.
1306 //------------------------------------------------------------------------------
MDrv_MVD_GetDispRdy(MS_U32 u32Id)1307 MS_U8 MDrv_MVD_GetDispRdy(MS_U32 u32Id)
1308 {
1309     MVD_FUNC_ENTRY();
1310     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1311     MS_BOOL bDispRdy = HAL_MVD_GetDispRdy(u8HalIdx);
1312     MS_BOOL bIFound = HAL_MVD_GetIsIPicFound(u8HalIdx);
1313 
1314 #ifndef DONT_USE_CMA
1315     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
1316     if(pMVDDrvContext->bCMAUsed == TRUE && pMVDDrvContext->bCMAAllocDone == FALSE)
1317     {
1318         MS_U64 u64Addr;
1319         MS_SIZE u64Size;
1320         MS_BOOL bAllocateDone;
1321         struct CMA_Pool_Alloc_Param alloc_param;
1322         HAL_MVD_GetCMAInformation(u8HalIdx,&u64Addr,&u64Size,&bAllocateDone);
1323 
1324         if(u64Addr == 0 || u64Size == 0)
1325         {
1326             return FALSE;
1327         }
1328         else
1329         {
1330             alloc_param.pool_handle_id = pMVDDrvContext->cmaInitParam.pool_handle_id;
1331             alloc_param.offset_in_pool = u64Addr - pMVDDrvContext->cmaInitParam.heap_miu_start_offset;
1332             alloc_param.length = u64Size;
1333             alloc_param.flags = CMA_FLAG_VIRT_ADDR;
1334 
1335             if (MApi_CMA_Pool_GetMem(&alloc_param) == FALSE)
1336             {
1337                 return FALSE;
1338             }
1339 
1340             VPRINTF("[VDEC][%d]MApi_CMA_Pool_GetMem in mvd: alloc_param.pool_handle_id=%x, alloc_param.flags=%x, alloc_param.offset_in_pool=%llx, alloc_param.length=%x\n",
1341                                 (unsigned int)u8DrvIdx,
1342                                 (unsigned int)alloc_param.pool_handle_id,
1343                                 (unsigned int)alloc_param.flags,
1344                                 (unsigned long long int)alloc_param.offset_in_pool,
1345                                 (unsigned int)alloc_param.length);
1346 
1347             pMVDDrvContext->cmaFreeParam[u8DrvIdx].pool_handle_id = alloc_param.pool_handle_id;
1348             pMVDDrvContext->cmaFreeParam[u8DrvIdx].offset_in_pool = alloc_param.offset_in_pool;
1349             pMVDDrvContext->cmaFreeParam[u8DrvIdx].length = alloc_param.length;
1350 
1351             //Run time set frame buffer miu client
1352             HAL_MVD_SetFrameBufferMiu(u8HalIdx,pMVDDrvContext->cmaInitParam.miu);
1353 
1354             HAL_MVD_SetCMAAllocateDone(u8HalIdx);
1355 
1356             pMVDDrvContext->bCMAAllocDone = TRUE;
1357         }
1358     }
1359 #endif
1360     return (bDispRdy || bIFound);
1361 }
1362 
1363 //------------------------------------------------------------------------------
1364 /// Query if the first frame is showed after play function is called.
1365 /// Whenever the first display frame is displayed, f/w will set this flag to 1.
1366 /// @return VDEC_Result
1367 //------------------------------------------------------------------------------
MDrv_MVD_Is1stFrmRdy(MS_U32 u32Id)1368 MS_BOOL MDrv_MVD_Is1stFrmRdy(MS_U32 u32Id)
1369 {
1370     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1371     return HAL_MVD_Is1stFrmRdy(u8HalIdx);
1372 }
1373 
1374 //------------------------------------------------------------------------------
1375 /// Get picture count of current GOP (Group of Picture)
1376 /// @return -picture count of GOP
1377 //------------------------------------------------------------------------------
MDrv_MVD_GetGOPCount(MS_U32 u32Id)1378 MS_U32 MDrv_MVD_GetGOPCount(MS_U32 u32Id)
1379 {
1380     MVD_FUNC_ENTRY();
1381     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1382     return HAL_MVD_GetGOPCount(u8HalIdx);
1383 }
1384 
1385 //------------------------------------------------------------------------------
1386 /// Enable or disable dropping error frames
1387 /// @return -command is set successfully or not
1388 //------------------------------------------------------------------------------
MDrv_MVD_DropErrorFrame(MS_U32 u32Id,MS_BOOL bDrop)1389 MS_BOOL MDrv_MVD_DropErrorFrame(MS_U32 u32Id, MS_BOOL bDrop)
1390 {
1391     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1392     MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1393     if (HAL_MVD_DropErrorFrame(u8HalIdx, bDrop) == FALSE)
1394     {
1395         MVD_DEBUGERROR( MVD_ERR( "%s fail!!\n", __FUNCTION__));
1396         return FALSE;
1397     }
1398     pstCtrlCfg->bDropErrFrm = bDrop;
1399     return TRUE;
1400 }
1401 
1402 //------------------------------------------------------------------------------
1403 /// Get byte count of parser.
1404 /// @return -byte count of parser
1405 //------------------------------------------------------------------------------
MDrv_MVD_GetParserByteCnt(MS_U32 u32Id)1406 MS_U32 MDrv_MVD_GetParserByteCnt(MS_U32 u32Id)
1407 {
1408     MVD_FUNC_ENTRY();
1409     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1410     return HAL_MVD_GetParserByteCnt(u8HalIdx);
1411 }
1412 
1413 //------------------------------------------------------------------------------
1414 /// Get the decode status.
1415 /// @return -the decode status
1416 //------------------------------------------------------------------------------
MDrv_MVD_GetDecodeStatus(MS_U32 u32Id)1417 MVD_DecStat MDrv_MVD_GetDecodeStatus(MS_U32 u32Id)
1418 {
1419     MVD_FUNC_ENTRY();
1420     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1421     return HAL_MVD_GetDecodeStatus(u8HalIdx);
1422 }
1423 
1424 //------------------------------------------------------------------------------
1425 /// Get the last command to firmware.
1426 /// @return -the last command
1427 //------------------------------------------------------------------------------
MDrv_MVD_GetLastCmd(MS_U32 u32Id)1428 MS_U8 MDrv_MVD_GetLastCmd(MS_U32 u32Id)
1429 {
1430     MVD_FUNC_ENTRY();
1431     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1432     return HAL_MVD_GetLastCmd(u8HalIdx);
1433 }
1434 
1435 //------------------------------------------------------------------------------
1436 /// Skip data in ES buffer.  It is used for flushing ES buffer.
1437 /// @return -TRUE for success; FALSE for failure.
1438 //------------------------------------------------------------------------------
MDrv_MVD_SkipData(MS_U32 u32Id)1439 MS_BOOL MDrv_MVD_SkipData(MS_U32 u32Id)
1440 {
1441     MVD_FUNC_ENTRY();
1442     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1443     return HAL_MVD_SkipData(u8HalIdx);
1444 }
1445 
1446 //------------------------------------------------------------------------------
1447 /// Skip to I frame.
1448 /// Used for MediaCodec when input data is not continuous or in the beginning of
1449 /// streams.
1450 /// @return -TRUE for success; FALSE for failure.
1451 //------------------------------------------------------------------------------
MDrv_MVD_SkipToIFrame(MS_U32 u32Id)1452 MS_BOOL MDrv_MVD_SkipToIFrame(MS_U32 u32Id)
1453 {
1454     MVD_FUNC_ENTRY();
1455     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1456     return HAL_MVD_SkipToIFrame(u8HalIdx);
1457 }
1458 
1459 //------------------------------------------------------------------------------
1460 /// Display control for decoding order, enabling drop error frame, dropping
1461 /// display and setting FRC (frame rate conversion) mode.
1462 /// @return -TRUE for success; FALSE for failure.
1463 //------------------------------------------------------------------------------
MDrv_MVD_DispCtrl(MS_U32 u32Id,MS_BOOL bDecOrder,MS_BOOL bDropErr,MS_BOOL bDropDisp,MVD_FrcMode eFrcMode)1464 MS_BOOL MDrv_MVD_DispCtrl(MS_U32 u32Id, MS_BOOL bDecOrder, MS_BOOL bDropErr, MS_BOOL bDropDisp, MVD_FrcMode eFrcMode)
1465 {
1466     MVD_FUNC_ENTRY();
1467     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1468     return HAL_MVD_DispCtrl(u8HalIdx, bDecOrder, bDropErr, bDropDisp, eFrcMode);
1469 }
1470 
1471 //------------------------------------------------------------------------------
1472 /// Enable/Disable to repeat the last field when repeat for avsync or display pause.
1473 /// E.g. Top field first: T-B-B-B-...; Bottom field first: B-T-T-T-...
1474 /// Usage scenario: scaler framebufferless mode to avoid frame flicker
1475 /// @return -TRUE for success; FALSE for failure.
1476 //------------------------------------------------------------------------------
MDrv_MVD_DispRepeatField(MS_U32 u32Id,MS_BOOL bEnable)1477 MS_BOOL MDrv_MVD_DispRepeatField(MS_U32 u32Id, MS_BOOL bEnable)
1478 {
1479     MVD_FUNC_ENTRY();
1480     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1481     return HAL_MVD_DispRepeatField(u8HalIdx, bEnable);
1482 }
1483 
1484 //------------------------------------------------------------------------------
1485 /// Get color format.
1486 /// @return - value (0~8)
1487 //------------------------------------------------------------------------------
MDrv_MVD_GetColorFormat(MS_U32 u32Id)1488 MS_U8 MDrv_MVD_GetColorFormat(MS_U32 u32Id)
1489 {
1490     MVD_FUNC_ENTRY();
1491     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1492     return HAL_MVD_GetColorFormat(u8HalIdx);
1493 }
1494 
1495 //------------------------------------------------------------------------------
1496 /// Get matrix coefficients in 13818-2 sequence_display_extension().
1497 /// @return - value (0~255)
1498 //------------------------------------------------------------------------------
MDrv_MVD_GetMatrixCoef(MS_U32 u32Id)1499 MS_U8 MDrv_MVD_GetMatrixCoef(MS_U32 u32Id)
1500 {
1501     MVD_FUNC_ENTRY();
1502     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1503     return HAL_MVD_GetMatrixCoef(u8HalIdx);
1504 }
1505 
1506 //------------------------------------------------------------------------------
1507 /// Issue PauseDisplay command.
1508 //------------------------------------------------------------------------------
MDrv_MVD_Pause(MS_U32 u32Id)1509 void MDrv_MVD_Pause(MS_U32 u32Id)
1510 {
1511     MVD_FUNC_ENTRY();
1512     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1513     HAL_MVD_PauseDisp(u8HalIdx);
1514     return;
1515 }
1516 
1517 //------------------------------------------------------------------------------
1518 /// Issue Resume command.
1519 //------------------------------------------------------------------------------
MDrv_MVD_Resume(MS_U32 u32Id)1520 void MDrv_MVD_Resume(MS_U32 u32Id)
1521 {
1522     MVD_FUNC_ENTRY();
1523     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1524     if (HAL_MVD_Resume(u8HalIdx) == FALSE)
1525     {
1526         MVD_DEBUGERROR( MVD_ERR( "Command: HAL_MVD_Resume fail!!\r\n" ) );
1527     }
1528 
1529     return;
1530 }
1531 
1532 //-----------------------------------------------------------------------------
1533 /// Is MVD step decode done after step decode command.
1534 /// @return - TRUE/FALSE
1535 /// @retval     -FALSE(0): decoding, or user did not send step decode command.
1536 /// @retval     -TRUE(1): decode done
1537 //-----------------------------------------------------------------------------
MDrv_MVD_IsStepDecodeDone(MS_U32 u32Id)1538 MS_BOOL MDrv_MVD_IsStepDecodeDone(MS_U32 u32Id)
1539 {
1540     MS_BOOL bRet = FALSE;
1541     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1542 
1543     MVD_FUNC_ENTRY();
1544     MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1545     if (pCtrlCfg->bStepDecode)
1546     {
1547         if (HAL_MVD_IsCmdFinished(u8HalIdx, MVD_HANDSHAKE_SINGLE_STEP))
1548         {
1549             MVD_PRINT( "MVD_HANDSHAKE_SINGLE_STEP -------: 0x%x \n", HAL_MVD_IsCmdFinished(u8HalIdx, MVD_HANDSHAKE_SINGLE_STEP));
1550             pCtrlCfg->bStepDecode = FALSE;
1551             bRet = TRUE;
1552         }
1553     }
1554     return bRet;
1555 }
1556 
1557 //------------------------------------------------------------------------------
1558 /// Issue StepPlay command.
1559 /// @return -TRUE for success; FALSE for failure.
1560 //------------------------------------------------------------------------------
MDrv_MVD_StepDecode(MS_U32 u32Id)1561 MS_BOOL MDrv_MVD_StepDecode(MS_U32 u32Id)
1562 {
1563     MVD_FUNC_ENTRY();
1564     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1565     HAL_MVD_ResetHandShake(u8HalIdx, MVD_HANDSHAKE_SINGLE_STEP);
1566     if (HAL_MVD_StepDecode(u8HalIdx) == FALSE)
1567     {
1568         MVD_DEBUGERROR(MVD_ERR("Command: HAL_MVD_StepDecode fail!!\r\n"));
1569         return FALSE;
1570     }
1571 
1572     if (HAL_MVD_Resume(u8HalIdx) == FALSE)
1573     {
1574         MVD_DEBUGERROR(MVD_ERR("Command: HAL_MVD_Resume fail!!\r\n"));
1575         return FALSE;
1576     }
1577 
1578     MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1579     if (pCtrlCfg)
1580     {
1581         pCtrlCfg->bStepDecode = TRUE;
1582     }
1583     return TRUE;
1584 }
1585 
1586 //-----------------------------------------------------------------------------
1587 /// Is MVD step display done after step display command.
1588 /// @return - TRUE/FALSE
1589 /// @retval     -FALSE(0): decoding, or user did not send step decode command.
1590 /// @retval     -TRUE(1): decode done
1591 //-----------------------------------------------------------------------------
MDrv_MVD_IsStepDispDone(MS_U32 u32Id)1592 MS_BOOL MDrv_MVD_IsStepDispDone(MS_U32 u32Id)
1593 {
1594     MVD_FUNC_ENTRY();
1595     MS_BOOL bRet = FALSE;
1596     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1597     MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1598 
1599     if (FALSE == pCtrlCfg->bStepDisp)
1600     {
1601         MVD_DEBUGERROR(MVD_ERR("%s err: hasn't issue StepDisp\n", __FUNCTION__));
1602         return FALSE;
1603     }
1604 
1605     bRet = HAL_MVD_IsStepDispDone(u8HalIdx);
1606     if (bRet)
1607     {
1608         pCtrlCfg->bStepDisp = FALSE;
1609     }
1610     return bRet;
1611 }
1612 
1613 //------------------------------------------------------------------------------
1614 /// Issue StepDisplay command.
1615 /// @return -TRUE for success; FALSE for failure.
1616 //------------------------------------------------------------------------------
MDrv_MVD_StepDisp(MS_U32 u32Id)1617 MS_BOOL MDrv_MVD_StepDisp(MS_U32 u32Id)
1618 {
1619     MVD_FUNC_ENTRY();
1620     MDrv_MVD_SetSpeed(u32Id, E_MVD_SPEED_DEFAULT, 1);
1621     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1622     if (HAL_MVD_StepDisp(u8HalIdx) == FALSE)
1623     {
1624         MVD_DEBUGERROR( MVD_ERR( "%s fail!!\n", __FUNCTION__ ) );
1625         return FALSE;
1626     }
1627 
1628     MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1629     if (pCtrlCfg)
1630     {
1631         pCtrlCfg->bStepDisp = TRUE;
1632     }
1633     return TRUE;
1634 }
1635 
1636 //-----------------------------------------------------------------------------
1637 /// Is MVD step display done after step display command.
1638 /// @return - TRUE/FALSE
1639 /// @retval     -FALSE(0): decoding, or user did not send step decode command.
1640 /// @retval     -TRUE(1): decode done
1641 //-----------------------------------------------------------------------------
MDrv_MVD_IsStep2PtsDone(MS_U32 u32Id)1642 MS_BOOL MDrv_MVD_IsStep2PtsDone(MS_U32 u32Id)
1643 {
1644     MVD_FUNC_ENTRY();
1645     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1646     return HAL_MVD_IsStep2PtsDone(u8HalIdx);
1647 }
1648 
1649 //------------------------------------------------------------------------------
1650 /// Step to the specific PTS (u32Pts ms)
1651 /// @return -TRUE for success; FALSE for failure.
1652 //------------------------------------------------------------------------------
MDrv_MVD_SeekToPTS(MS_U32 u32Id,MS_U32 u32Pts)1653 MS_BOOL MDrv_MVD_SeekToPTS(MS_U32 u32Id, MS_U32 u32Pts)
1654 {
1655     MVD_FUNC_ENTRY();
1656     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1657     MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1658 
1659     MDrv_MVD_SetSpeed(u32Id, E_MVD_SPEED_DEFAULT, 1);
1660     pCtrlCfg->bStep2Pts = HAL_MVD_SeekToPTS(u8HalIdx, _MS_TO_90K(u32Pts));
1661     return (pCtrlCfg->bStep2Pts);
1662 }
1663 
1664 //------------------------------------------------------------------------------
1665 /// Skip to the specific PTS (u32Pts ms)
1666 /// @return -TRUE for success; FALSE for failure.
1667 //------------------------------------------------------------------------------
MDrv_MVD_SkipToPTS(MS_U32 u32Id,MS_U32 u32Pts)1668 MS_BOOL MDrv_MVD_SkipToPTS(MS_U32 u32Id, MS_U32 u32Pts)
1669 {
1670     MVD_FUNC_ENTRY();
1671     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1672     MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1673 
1674     pCtrlCfg->bSkip2Pts = HAL_MVD_SkipToPTS(u8HalIdx, _MS_TO_90K(u32Pts));
1675     return (pCtrlCfg->bSkip2Pts);
1676 }
1677 
1678 //------------------------------------------------------------------------------
1679 /// Issue TrickPlay command.
1680 /// @return -TRUE for success; FALSE for failure.
1681 //------------------------------------------------------------------------------
MDrv_MVD_TrickPlay(MS_U32 u32Id,MVD_TrickDec trickDec,MS_U8 u8DispDuration)1682 MS_BOOL MDrv_MVD_TrickPlay(MS_U32 u32Id, MVD_TrickDec trickDec, MS_U8 u8DispDuration)
1683 {
1684     MVD_FUNC_ENTRY();
1685     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1686     //eTrickMode = trickDec;    //for MDrv_MVD_GetTrickMode
1687     if (HAL_MVD_TrickPlay(u8HalIdx, trickDec, u8DispDuration) == FALSE)
1688     {
1689         MVD_DEBUGERROR(MVD_ERR("HAL_MVD_TrickPlay fail!!\r\n"));
1690         return FALSE;
1691     }
1692 //    MDrv_MVD_SetAVSync(u32Id, FALSE, 0);
1693     return TRUE;
1694 }
1695 
1696 //------------------------------------------------------------------------------
1697 /// Get the trick mode which has been set.
1698 /// @return MVD_TrickDec
1699 //------------------------------------------------------------------------------
MDrv_MVD_GetTrickMode(MS_U32 u32Id)1700 MVD_TrickDec MDrv_MVD_GetTrickMode(MS_U32 u32Id)
1701 {
1702     MVD_TrickDec eTrickMode = E_MVD_TRICK_DEC_UNKNOWN;
1703     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1704     MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1705     if (pCtrlCfg)
1706     {
1707         eTrickMode = pCtrlCfg->eTrickMode;
1708     }
1709 
1710     return eTrickMode;
1711 }
1712 
1713 //------------------------------------------------------------------------------
1714 /// Flush display buffer.
1715 /// @return -TRUE for success; FALSE for failure.
1716 //------------------------------------------------------------------------------
MDrv_MVD_FlushDisplayBuf(MS_U32 u32Id)1717 MS_BOOL MDrv_MVD_FlushDisplayBuf(MS_U32 u32Id)
1718 {
1719     MVD_FUNC_ENTRY();
1720     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1721     return HAL_MVD_FlushDisplayBuf(u8HalIdx);
1722 }
1723 
1724 //------------------------------------------------------------------------------
1725 /// Get capabilities of MPEG Video Decoder.
1726 /// @return -TRUE for success; FALSE for failure.
1727 //------------------------------------------------------------------------------
MDrv_MVD_GetCaps(MVD_Caps * pCaps)1728 MS_BOOL MDrv_MVD_GetCaps(MVD_Caps* pCaps)
1729 {
1730     MS_U8 caps = HAL_MVD_GetCaps();
1731     if (!pCaps)
1732         return FALSE;
1733 
1734     pCaps->bMPEG2 = ((caps & MVD_SUPPORT_MPEG2) == MVD_SUPPORT_MPEG2);
1735     pCaps->bMPEG4 = ((caps & MVD_SUPPORT_MPEG4) == MVD_SUPPORT_MPEG4);
1736     pCaps->bVC1   = ((caps & MVD_SUPPORT_VC1) == MVD_SUPPORT_VC1);
1737 
1738     //MVD_PRINT("MP2=%d, MP4=%d, VC1=%d\n", pCaps->bMPEG2, pCaps->bMPEG4, pCaps->bVC1);
1739     return TRUE;
1740 }
1741 
1742 //------------------------------------------------------------------------------
1743 /// Get max pixels of MPEG Video Decoder.
1744 /// @return -max pixel supportted .
1745 //------------------------------------------------------------------------------
MDrv_MVD_GetMaxPixel(MS_U32 u32Id)1746 MS_U32 MDrv_MVD_GetMaxPixel(MS_U32 u32Id)
1747 {
1748     return (MS_U32)HAL_MVD_GetMaxPixel(u32Id);
1749 }
1750 
1751 
1752 //------------------------------------------------------------------------------
1753 /// Get if MVD decoder is playing.
1754 /// @return TRUE or FALSE
1755 ///     - TRUE, Yes
1756 ///     - FALSE, No
1757 //------------------------------------------------------------------------------
MDrv_MVD_IsPlaying(MS_U32 u32Id)1758 MS_BOOL MDrv_MVD_IsPlaying(MS_U32 u32Id)
1759 {
1760     MS_BOOL bIsPlaying = FALSE;
1761     bIsPlaying = ( MDrv_MVD_GetDecodeStatus(u32Id) == E_MVD_STAT_WAIT_DECODEDONE );
1762 
1763     return bIsPlaying;
1764 }
1765 
1766 //------------------------------------------------------------------------------
1767 /// Get if MVD decoder is in idle state.
1768 /// @return TRUE or FALSE
1769 ///     - TRUE, Yes
1770 ///     - FALSE, No
1771 //------------------------------------------------------------------------------
MDrv_MVD_IsIdle(MS_U32 u32Id)1772 MS_BOOL MDrv_MVD_IsIdle(MS_U32 u32Id)
1773 {
1774     return (MDrv_MVD_GetDecodeStatus(u32Id) == E_MVD_STAT_IDLE);
1775 }
1776 
1777 //------------------------------------------------------------------------------
1778 /// Enable/Disable error concealment function
1779 /// @param -bDisable \b IN : enable/disable this function
1780 /// @return -return E_MVD_Result success/fail to enable/disable
1781 //------------------------------------------------------------------------------
MDrv_MVD_DisableErrConceal(MS_U32 u32Id,MS_BOOL bDisable)1782 E_MVD_Result MDrv_MVD_DisableErrConceal(MS_U32 u32Id, MS_BOOL bDisable)
1783 {
1784     return E_MVD_RET_FAIL;
1785 }
1786 
1787 //------------------------------------------------------------------------------
1788 /// Push queue.
1789 /// @param -u32StAddr \b IN : the start address of the queue
1790 /// @param -u32Size \b IN : the data size to be pushed
1791 /// @param -u32TimeStamp \b IN : the corresponding PTS
1792 /// @return -return E_MVD_Result success/fail to push queue
1793 //------------------------------------------------------------------------------
MDrv_MVD_PushQueue(MS_U32 u32Id,MVD_PacketInfo * pInfo)1794 E_MVD_Result MDrv_MVD_PushQueue(MS_U32 u32Id, MVD_PacketInfo* pInfo)
1795 {
1796     MVD_FUNC_ENTRY();
1797     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1798 
1799     //check input parameters
1800     if (pInfo == NULL)
1801     {
1802         MVD_DEBUGERROR(MVD_ERR("PushQueue NULL pInfo\n"));
1803         return E_MVD_RET_INVALID_PARAM;
1804     }
1805 
1806     return HAL_MVD_PushQueue(u8HalIdx, pInfo);
1807 }
1808 
1809 //------------------------------------------------------------------------------
1810 /// Flush queue: flush ES buffer, reset SLQ TABLE, flush decoded frame, and
1811 ///              keep the display frame.
1812 /// @return -return E_MVD_Result success/fail to flush queue
1813 //------------------------------------------------------------------------------
MDrv_MVD_FlushQueue(MS_U32 u32Id)1814 E_MVD_Result MDrv_MVD_FlushQueue(MS_U32 u32Id)
1815 {
1816     MVD_FUNC_ENTRY();
1817     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1818     return HAL_MVD_FlushQueue(u8HalIdx);
1819 }
1820 
1821 
1822 //------------------------------------------------------------------------------
1823 /// Get the queue vacancy (unit in slq entry).
1824 /// @param -pQueueVacancy \b IN : pointer to the queue vacancy
1825 /// @return -return E_MVD_Result success/fail to get the queue vacancy
1826 //------------------------------------------------------------------------------
MDrv_MVD_GetQueueVacancy(MS_U32 u32Id,MS_BOOL bCached)1827 MS_U32 MDrv_MVD_GetQueueVacancy(MS_U32 u32Id, MS_BOOL bCached)
1828 {
1829     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1830     MS_U8 u8VPUIdx = HAL_VPU_EX_GetTaskId(u32Id);
1831 #ifdef VDEC3
1832     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
1833 
1834     if(pMVDDrvContext->u32FrameBaseMode[u8DrvIdx] == TRUE)
1835     {
1836         MS_VIRT u32VBBUAddr = HAL_MVD_GetVBBUTableAddr(u8VPUIdx);
1837         return HAL_VPU_EX_GetVBBUVacancy(u32VBBUAddr);
1838     }
1839     else
1840 #endif
1841     {
1842         return HAL_MVD_GetQueueVacancy(u8HalIdx, bCached);
1843     }
1844 
1845 }
1846 
1847 //------------------------------------------------------------------------------
1848 /// Get read pointer in ElementaryStream buffer
1849 /// @return -the read pointer
1850 //------------------------------------------------------------------------------
MDrv_MVD_GetESReadPtr(MS_U32 u32Id)1851 MS_VIRT MDrv_MVD_GetESReadPtr(MS_U32 u32Id)
1852 {
1853     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1854     MS_U8 u8VPUIdx = HAL_VPU_EX_GetTaskId(u32Id);
1855 #ifdef VDEC3
1856     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
1857 
1858     if(pMVDDrvContext->u32FrameBaseMode[u8DrvIdx] == TRUE)
1859     {
1860         MS_VIRT u32VBBUAddr = HAL_MVD_GetVBBUTableAddr(u8VPUIdx);
1861         MS_VIRT u32Rptr = HAL_VPU_EX_GetESReadPtr(u32Id, u32VBBUAddr);
1862         return u32Rptr;
1863     }
1864     else
1865 #endif
1866     {
1867     MS_U32 u32ESR = 0;
1868     MVD_SrcMode curSrcMode = HAL_MVD_GetSrcMode(u8HalIdx);
1869 
1870     if (E_MVD_SLQ_TBL_MODE == curSrcMode)
1871     {
1872         u32ESR = MVD_GetSlqTblESReadPtr(u8HalIdx);
1873     }
1874     else if (E_MVD_TS_FILE_MODE == curSrcMode || E_MVD_TS_MODE == curSrcMode)
1875     {
1876         u32ESR = HAL_MVD_GetTsFileESReadPtr(u8HalIdx);
1877     }
1878     return u32ESR;
1879     }
1880 }
1881 
1882 
1883 //------------------------------------------------------------------------------
1884 /// Get write pointer in ElementaryStream buffer
1885 /// @return -the read pointer
1886 //------------------------------------------------------------------------------
MDrv_MVD_GetESWritePtr(MS_U32 u32Id)1887 MS_VIRT MDrv_MVD_GetESWritePtr(MS_U32 u32Id)
1888 {
1889     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1890     MS_U8 u8VPUIdx = HAL_VPU_EX_GetTaskId(u32Id);
1891 #ifdef VDEC3
1892     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
1893 
1894     if(pMVDDrvContext->u32FrameBaseMode[u8DrvIdx] == TRUE)
1895     {
1896         MS_U32 u32VBBUAddr = HAL_MVD_GetVBBUTableAddr(u8VPUIdx);
1897         MS_U32 u32Wptr = HAL_VPU_EX_GetESWritePtr(u32Id, u32VBBUAddr);
1898         return u32Wptr;
1899     }
1900     else
1901 #endif
1902     {
1903     MS_U32 u32ESW = 0;
1904     MVD_SrcMode curSrcMode = HAL_MVD_GetSrcMode(u8HalIdx);
1905 
1906     if (E_MVD_SLQ_TBL_MODE == curSrcMode)
1907     {
1908         u32ESW = MVD_GetSlqTblESWritePtr(u8HalIdx);
1909     }
1910     else if (E_MVD_TS_FILE_MODE == curSrcMode || E_MVD_TS_MODE == curSrcMode)
1911     {
1912         u32ESW = HAL_MVD_GetTsFileESWritePtr(u8HalIdx);
1913     }
1914     return u32ESW;
1915     }
1916 }
1917 
1918 
1919 //------------------------------------------------------------------------------
1920 /// Enable/Disable driver to show the last frame
1921 /// @param -bEnable \b IN : enable/disable this function
1922 /// @return -return E_MVD_Result success/fail to enable/disable
1923 //------------------------------------------------------------------------------
MDrv_MVD_EnableLastFrameShow(MS_U32 u32Id,MS_BOOL bEnable)1924 E_MVD_Result MDrv_MVD_EnableLastFrameShow(MS_U32 u32Id, MS_BOOL bEnable)
1925 {
1926     MVD_FUNC_ENTRY();
1927     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1928     MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1929     if (HAL_MVD_EnableLastFrameShow(u8HalIdx, bEnable) == FALSE)
1930     {
1931         MVD_DEBUGERROR(MVD_ERR("%s fail!!\n", __FUNCTION__));
1932         return E_MVD_RET_FAIL;
1933     }
1934     pCtrlCfg->bEnableLastFrmShow = bEnable;
1935     return E_MVD_RET_OK;
1936 }
1937 
1938 //------------------------------------------------------------------------------
1939 /// Get if MVD decoder finish display.
1940 /// @return TRUE or FALSE
1941 ///     - TRUE, Yes
1942 ///     - FALSE, No
1943 //------------------------------------------------------------------------------
MDrv_MVD_IsDispFinish(MS_U32 u32Id)1944 E_MVD_Result MDrv_MVD_IsDispFinish(MS_U32 u32Id)
1945 {
1946     MVD_FUNC_ENTRY();
1947     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1948     MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1949     if (pCtrlCfg->bEnableLastFrmShow != TRUE)
1950     {
1951         MVD_DEBUGINFO(MVD_PRINT("%s: bEnableLastFrmShow!=TRUE\n", __FUNCTION__));
1952         return E_MVD_RET_FAIL;
1953     }
1954     return HAL_MVD_IsDispFinish(u8HalIdx);
1955 }
1956 
1957 //------------------------------------------------------------------------------
1958 /// Set speed.
1959 /// @param -eSpeedType \b IN : specify the speed
1960 /// @param -u8Multiple \b IN :
1961 /// @return -return E_MVD_Result success/fail to set the speed
1962 //------------------------------------------------------------------------------
MDrv_MVD_SetSpeed(MS_U32 u32Id,MVD_SpeedType eSpeedType,MS_U8 u8Multiple)1963 E_MVD_Result MDrv_MVD_SetSpeed(MS_U32 u32Id, MVD_SpeedType eSpeedType, MS_U8 u8Multiple)
1964 {
1965     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
1966     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
1967     MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
1968     MVD_AVSyncCfg* pstNFPSyncCfg = &(pMVDDrvContext->stNFPSyncCfg[u8DrvIdx]);
1969 
1970     if ((u8Multiple > 32) || (eSpeedType==E_MVD_SPEED_TYPE_UNKNOWN))
1971     {
1972         MVD_DEBUGINFO(MVD_PRINT("%s: invalid para!\n", __FUNCTION__));
1973         return E_MVD_RET_INVALID_PARAM;
1974     }
1975 
1976     if (pstCtrlCfg->ePreSpeedType == E_MVD_SPEED_DEFAULT)
1977     {   //save avsync config when normal play for restoring it later
1978         memcpy(pstNFPSyncCfg, &(pMVDDrvContext->stSyncCfg[u8DrvIdx]), sizeof(MVD_AVSyncCfg));
1979         MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_SetSpeed save avsync: bEnable=0x%x u32Delay=0x%x u16Tolerance=0x%x\n",
1980                   pstNFPSyncCfg->bEnable, pstNFPSyncCfg->u32Delay, pstNFPSyncCfg->u16Tolerance));
1981     }
1982 
1983     if((eSpeedType == E_MVD_SPEED_FAST && u8Multiple == 2 && pMVDDrvContext->bTrickPlay2xAVSync[u8DrvIdx] == TRUE) == FALSE && E_MVD_SPEED_DEFAULT != eSpeedType)
1984     {
1985         //disable avsyn when fast/slow forward
1986         MDrv_MVD_SetAVSync(u32Id, FALSE, 0);
1987     }
1988 
1989     if (HAL_MVD_SetSpeed(u8HalIdx, eSpeedType, u8Multiple) == TRUE)
1990     {
1991         if ((E_MVD_SPEED_DEFAULT == eSpeedType) || (eSpeedType == E_MVD_SPEED_FAST && u8Multiple == 2 && pMVDDrvContext->bTrickPlay2xAVSync[u8DrvIdx] == TRUE))
1992         {
1993             if (pstCtrlCfg->ePreSpeedType != E_MVD_SPEED_DEFAULT)
1994             {
1995                 //set AVSync again for firmware doesn't remember AVSync settings after FF
1996                 MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_SetSpeed reset avsync: bEnable=0x%x u32Delay=0x%x u16Tolerance=0x%x\n",
1997                               pstNFPSyncCfg->bEnable, pstNFPSyncCfg->u32Delay, pstNFPSyncCfg->u16Tolerance));
1998 
1999                 MDrv_MVD_SetAVSync(u32Id, pstNFPSyncCfg->bEnable, pstNFPSyncCfg->u32Delay);
2000                 if ((pstNFPSyncCfg->u16Tolerance!=0) &&
2001                     (FALSE == MDrv_MVD_ChangeAVsync(u32Id, pstNFPSyncCfg->bEnable, pstNFPSyncCfg->u16Tolerance)))
2002                 {
2003                     return E_MVD_RET_FAIL;
2004                 }
2005             }
2006         }
2007 
2008         pstCtrlCfg->ePreSpeedType = eSpeedType;
2009         return E_MVD_RET_OK;
2010     }
2011     else
2012     {
2013         return E_MVD_RET_FAIL;
2014    }
2015 }
2016 
2017 //------------------------------------------------------------------------------
2018 /// Reset Presentation Time Stamp according to u32PtsBase
2019 /// @param -u32PtsBase \b IN : the PTS base specified by user
2020 /// @return -return E_MVD_Result success/fail to reset PTS base
2021 //------------------------------------------------------------------------------
MDrv_MVD_ResetPTS(MS_U32 u32Id,MS_U32 u32PtsBase)2022 E_MVD_Result MDrv_MVD_ResetPTS(MS_U32 u32Id, MS_U32 u32PtsBase)
2023 {
2024     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2025     MS_U32 u32PtsBaseIn90K = 0;
2026     u32PtsBaseIn90K = _MS_TO_90K(u32PtsBase);
2027     HAL_MVD_SetPTSBase(u8HalIdx, u32PtsBaseIn90K);
2028     return E_MVD_RET_OK;
2029 }
2030 
2031 //------------------------------------------------------------------------------
2032 /// Get if sequence change (width/height/framerate/interlace) occurs.
2033 /// @return TRUE or FALSE
2034 ///     - TRUE, Yes
2035 ///     - FALSE, No
2036 //------------------------------------------------------------------------------
MDrv_MVD_IsSeqChg(MS_U32 u32Id)2037 MS_BOOL MDrv_MVD_IsSeqChg(MS_U32 u32Id)
2038 {
2039     MVD_FrameInfo stFrmInfo;
2040     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
2041     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2042     MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8HalIdx);
2043     MVD_FrameInfo* pPreInfo = &(pMVDDrvContext->stPreFrmInfo[u8DrvIdx]);
2044     MS_BOOL bRet = FALSE;
2045     MS_BOOL bResolutionChange = FALSE;
2046     memset(&stFrmInfo, 0, sizeof(stFrmInfo));
2047 
2048     if (
2049 #ifdef MVD_ENABLE_ISR
2050         (MDrv_MVD_GetIsrEvent(u32Id) & E_MVD_EVENT_SEQ_FOUND) ||
2051 #endif
2052         (MDrv_MVD_GetDispRdy(u32Id))
2053         )
2054     {
2055         MDrv_MVD_GetFrameInfo(u32Id, &stFrmInfo);
2056 
2057         if(pMVDDrvContext->bSelf_SeqChange[u8DrvIdx]==FALSE)
2058         {
2059             if (FALSE == pstMemCfg->bEnableDynScale)
2060             {
2061                 if((pPreInfo->u16HorSize   != stFrmInfo.u16HorSize) ||
2062                    (pPreInfo->u16VerSize   != stFrmInfo.u16VerSize) ||
2063                    (pPreInfo->u32FrameRate != stFrmInfo.u32FrameRate) ||
2064                    (pPreInfo->u8Interlace  != stFrmInfo.u8Interlace))
2065                 {
2066 #if 0
2067                     (MVD_PRINT( "MDrv_MVD_IsSeqChg::Previous\n" ));
2068                     (MVD_PRINT( "H=%u\n", pPreInfo->u16HorSize ));
2069                     (MVD_PRINT( "V=%u\n", pPreInfo->u16VerSize ));
2070                     (MVD_PRINT( "F=%lu\n", pPreInfo->u32FrameRate ));
2071                     (MVD_PRINT( "A=%u\n", pPreInfo->u8AspectRate ));
2072                     (MVD_PRINT( "I=%u\n", pPreInfo->u8Interlace ));
2073 #endif
2074 #if 0
2075                     (MVD_PRINT( "MDrv_MVD_IsSeqChg\n" ));
2076                     (MVD_PRINT( "H=%u\n", stFrmInfo.u16HorSize ));
2077                     (MVD_PRINT( "V=%u\n", stFrmInfo.u16VerSize ));
2078                     (MVD_PRINT( "F=%lu\n", stFrmInfo.u32FrameRate ));
2079                     (MVD_PRINT( "A=%u\n", stFrmInfo.u8AspectRate ));
2080                     (MVD_PRINT( "I=%u\n", stFrmInfo.u8Interlace ));
2081 #endif
2082 
2083                     //memcpy(&(pMVDDrvContext->stPreFrmInfo), &stFrmInfo, sizeof(MVD_FrameInfo));
2084                     pPreInfo->u16HorSize   = stFrmInfo.u16HorSize;
2085                     pPreInfo->u16VerSize   = stFrmInfo.u16VerSize;
2086                     pPreInfo->u8AspectRate = stFrmInfo.u8AspectRate;
2087                     pPreInfo->u32FrameRate = stFrmInfo.u32FrameRate;
2088                     pPreInfo->u8Interlace  = stFrmInfo.u8Interlace;
2089 #if 0
2090                     (MVD_PRINT( "MDrv_MVD_IsSeqChg===>\n" ));
2091                     (MVD_PRINT( "H=%u\n", stFrmInfo.u16HorSize ));
2092                     (MVD_PRINT( "V=%u\n", stFrmInfo.u16VerSize ));
2093                     (MVD_PRINT( "F=%u\n", stFrmInfo.u32FrameRate ));
2094                     (MVD_PRINT( "A=%u\n", stFrmInfo.u8AspectRate ));
2095                     (MVD_PRINT( "I=%u\n", stFrmInfo.u8Interlace ));
2096 #endif
2097                     bRet = TRUE;
2098                 }
2099             }
2100             else
2101             {
2102                 //When dynamic scaling is enabled, f/w will handle the width/height change.
2103                 //Therefore, only report SeqChg if framerate or interlace flag changes.
2104                 if((pPreInfo->u32FrameRate != stFrmInfo.u32FrameRate) ||
2105                    (pPreInfo->u8Interlace  != stFrmInfo.u8Interlace))
2106                 {
2107                     pPreInfo->u8AspectRate = stFrmInfo.u8AspectRate;
2108                     pPreInfo->u32FrameRate = stFrmInfo.u32FrameRate;
2109                     pPreInfo->u8Interlace  = stFrmInfo.u8Interlace;
2110                     bRet = TRUE;
2111                 }
2112             }
2113         }
2114         else
2115         {
2116 
2117             if((pPreInfo->u16HorSize   != stFrmInfo.u16HorSize) ||
2118                (pPreInfo->u16VerSize   != stFrmInfo.u16VerSize) ||
2119                (pPreInfo->u32FrameRate != stFrmInfo.u32FrameRate) ||
2120                (pPreInfo->u8Interlace  != stFrmInfo.u8Interlace) )
2121             {
2122                 pPreInfo->u16HorSize   = stFrmInfo.u16HorSize;
2123                 pPreInfo->u16VerSize   = stFrmInfo.u16VerSize;
2124                 pPreInfo->u8AspectRate = stFrmInfo.u8AspectRate;
2125                 pPreInfo->u32FrameRate = stFrmInfo.u32FrameRate;
2126                 pPreInfo->u8Interlace  = stFrmInfo.u8Interlace;
2127                 bRet = TRUE;
2128             }
2129         }
2130     }
2131 
2132     bResolutionChange = bRet;
2133 
2134     if(HAL_MVD_GetSuspendDynamicScale(u8HalIdx) == TRUE)
2135     {
2136         if(pMVDDrvContext->bSuspendDS_Ftime[u8DrvIdx] ==TRUE) //happen in first time suspend ds
2137         {
2138             pMVDDrvContext->bSuspendDS_Ftime[u8DrvIdx] = FALSE;
2139             if(pMVDDrvContext->bSelf_SeqChange[u8DrvIdx]==TRUE)
2140             {
2141                bRet = bResolutionChange;
2142             }
2143             else
2144             {
2145                bRet = TRUE;
2146             }
2147         }
2148         else
2149         {
2150             if(bResolutionChange == TRUE) //happen in suspend ds and resolution change
2151             {
2152                 bRet = TRUE;
2153             }
2154             else
2155             {
2156                 bRet = FALSE;
2157             }
2158         }
2159     }
2160     else //normal case
2161     {
2162         if(pMVDDrvContext->bSuspendDS_Ftime[u8DrvIdx] == FALSE)//happen in close suspend ds,it will reset bSuspendDS_Ftime flag
2163         {
2164             pMVDDrvContext->bSuspendDS_Ftime[u8DrvIdx] = TRUE;
2165             bRet = TRUE;
2166         }
2167         else
2168         {
2169             bRet = bResolutionChange;
2170         }
2171     }
2172 
2173     if (TRUE == bRet)
2174     {
2175         //Update bFrmRateSupported when IsSeqChg
2176         pMVDDrvContext->bFrmRateSupported[u8DrvIdx] = HAL_MVD_GetFrmRateIsSupported(stFrmInfo.u16HorSize, stFrmInfo.u16VerSize, stFrmInfo.u32FrameRate);
2177         MVD_DEBUGINFO(MVD_PRINT("%s bFrmRateSupported[0x%x]=%x\n", __FUNCTION__, u8DrvIdx, pMVDDrvContext->bFrmRateSupported[u8DrvIdx]));
2178     }
2179 
2180     return bRet;
2181 }
2182 
2183 //------------------------------------------------------------------------------
2184 /// Set Debug Data which will be queried by MDrv_MVD_DbgGetData()
2185 /// @param -u32Addr \b IN : address of debug data
2186 /// @param -u32Data \b IN : the debug data
2187 /// @return -return E_MVD_Result success/fail to set debug data
2188 //------------------------------------------------------------------------------
MDrv_MVD_DbgSetData(MS_U32 u32Id,MS_VIRT u32Addr,MS_U32 u32Data)2189 E_MVD_Result MDrv_MVD_DbgSetData(MS_U32 u32Id, MS_VIRT u32Addr, MS_U32 u32Data)
2190 {
2191     return E_MVD_RET_FAIL;
2192 }
2193 
2194 //------------------------------------------------------------------------------
2195 /// Get Debug Data
2196 /// @param -u32Addr \b IN : address of debug data
2197 /// @param -u32Data \b IN : pointer to the debug data
2198 /// @return -return E_MVD_Result success/fail to get debug data
2199 //------------------------------------------------------------------------------
MDrv_MVD_DbgGetData(MS_U32 u32Id,MS_VIRT u32Addr,MS_U32 * u32Data)2200 E_MVD_Result MDrv_MVD_DbgGetData(MS_U32 u32Id, MS_VIRT u32Addr, MS_U32* u32Data)
2201 {
2202     if (!u32Data)
2203     {
2204         return E_MVD_RET_INVALID_PARAM;
2205     }
2206     return HAL_MVD_DbgGetData(u32Addr, u32Data);
2207 }
2208 
2209 
2210 //------------------------------------------------------------------------------
2211 /// Set MVD firmware command
2212 /// @param -u8cmd \b IN : MVD command
2213 /// @param -pstCmdArg \b IN : pointer to command argument
2214 //------------------------------------------------------------------------------
MDrv_MVD_MVDCommand(MS_U8 u8cmd,MVD_CmdArg * pstCmdArg)2215 MS_BOOL MDrv_MVD_MVDCommand ( MS_U8 u8cmd, MVD_CmdArg *pstCmdArg )
2216 {
2217     return HAL_MVD_MVDCommand(u8cmd, pstCmdArg);
2218 }
2219 
2220 
2221 #ifdef MVD_ENABLE_ISR
2222 ///Notice: This function only works when being called by fnHandler, which was
2223 ///registered by AP using MDrv_MVD_SetIsrEvent()
MDrv_MVD_GetIsrEvent(MS_U32 u32Id)2224 MS_U32 MDrv_MVD_GetIsrEvent(MS_U32 u32Id)
2225 {
2226     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
2227     return pMVDDrvContext->_eCurEvent[u8DrvIdx];
2228 }
2229 
MVD_IsrProc(void)2230 void MVD_IsrProc(void)
2231 {
2232     MS_U32 u32IntStat = 0;
2233     MS_U8  u8DrvIdx = 0xff;
2234     MS_U8  u8HalIdx = 0;
2235     MS_U32* pu32EventFlag;
2236     MS_U32* pu32CurEvent;
2237     MVD_InterruptCb pfnCb = NULL;
2238     MS_U32 u32CbData = MVD_U32_MAX;
2239     MS_U32 u32Id = 0;
2240 
2241     //we can attach only one ISR, so we need to check the INT is from which decoder.
2242     for (u8DrvIdx=0; u8DrvIdx<MVD_MAX_STREAMS; u8DrvIdx++)
2243     {
2244         if(MVD_GetIsUsed(u8DrvIdx) == FALSE)
2245         {
2246             continue;
2247         }
2248 
2249         pu32EventFlag = &(pMVDDrvContext->_eEventFlag[u8DrvIdx]);
2250         if (*pu32EventFlag == E_MVD_EVENT_DISABLE_ALL)
2251         {
2252             MVD_DEBUGINFO(MVD_PRINT("%s skip 0x%x for no registered events.\n", __FUNCTION__, u8DrvIdx));
2253             continue;
2254         }
2255 
2256         u8HalIdx = pMVDDrvContext->gMVDCtrl_EX[u8DrvIdx].u8HalIdx;
2257 
2258         if (FALSE == HAL_MVD_GetHasInt(u8HalIdx))
2259         {
2260             MVD_DEBUGINFO(MVD_PRINT("%s no INT for %x\n", __FUNCTION__, u8DrvIdx));
2261             continue;
2262         }
2263 
2264         pu32CurEvent = &(pMVDDrvContext->_eCurEvent[u8DrvIdx]);
2265         pfnCb = pMVDDrvContext->_pfnCallback[u8DrvIdx];
2266         u32CbData = pMVDDrvContext->_u32CallbackPara[u8DrvIdx];
2267 
2268         u32IntStat = HAL_MVD_GetIntState(u8HalIdx);
2269 
2270         u32Id = MVD_GetStreamId(u8DrvIdx);
2271 
2272         if (u32IntStat != 0)
2273         {
2274             //MVD_DEBUGINFO(MVD_PRINT("MVD_IsrProc u32IntStat=%lx\n", u32IntStat));
2275             *pu32CurEvent = E_MVD_EVENT_DISABLE_ALL;
2276 
2277             if ((*pu32EventFlag & E_MVD_EVENT_USER_DATA) == E_MVD_EVENT_USER_DATA)
2278             {
2279                 if (MVD_IntHasUsrData(u32IntStat))
2280                 {
2281                     *pu32CurEvent |= E_MVD_EVENT_USER_DATA;
2282                     MVD_DEBUGINFO(MVD_PRINT("===> UsrData!!!\n"));
2283                 }
2284             }
2285             if ((*pu32EventFlag & E_MVD_EVENT_USER_DATA_DISP) == E_MVD_EVENT_USER_DATA_DISP)
2286             {
2287                 if (MVD_IntHasUsrDataDisp(u32IntStat))
2288                 {
2289                     *pu32CurEvent |= E_MVD_EVENT_USER_DATA_DISP;
2290                     MVD_DEBUGINFO(MVD_PRINT("===> DispUsrData!!!\n"));
2291                 }
2292             }
2293             if ((*pu32EventFlag & E_MVD_EVENT_DISP_RDY) == E_MVD_EVENT_DISP_RDY)
2294             {
2295                 if (MVD_IntIsDispRdy(u32IntStat))
2296                 {
2297                     *pu32CurEvent |= E_MVD_EVENT_DISP_RDY;
2298                     MVD_DEBUGINFO(MVD_PRINT("===> DispRdy!!!\n"));
2299                 }
2300             }
2301             if ((*pu32EventFlag & E_MVD_EVENT_SEQ_FOUND) == E_MVD_EVENT_SEQ_FOUND)
2302             {
2303                 if (MVD_IntHasSeqHdr(u32IntStat))
2304                 {
2305                     *pu32CurEvent |= E_MVD_EVENT_SEQ_FOUND;
2306                     MVD_DEBUGINFO(MVD_PRINT("===> SeqHdrFound!!!\n"));
2307                 }
2308             }
2309             if ((*pu32EventFlag & E_MVD_EVENT_FIRST_FRAME) == E_MVD_EVENT_FIRST_FRAME)
2310             {
2311                 if (MVD_IntHas1stFrame(u32IntStat))
2312                 {
2313                     *pu32CurEvent |= E_MVD_EVENT_FIRST_FRAME;
2314                     MVD_DEBUGINFO(MVD_PRINT("===> 1stFrame!!!\n"));
2315                 }
2316             }
2317             if ((*pu32EventFlag & E_MVD_EVENT_XC_LOW_DEALY) == E_MVD_EVENT_XC_LOW_DEALY)
2318             {
2319                 if (MVD_IntHasXcLowDelay(u32IntStat))
2320                 {
2321                     *pu32CurEvent |= E_MVD_EVENT_XC_LOW_DEALY;
2322                     MVD_DEBUGINFO(MVD_PRINT("===> E_MVD_EVENT_XC_LOW_DEALY!!!\n"));
2323                 }
2324             }
2325             if ((*pu32EventFlag & E_MVD_EVENT_DEC_I) == E_MVD_EVENT_DEC_I)
2326             {
2327                 if (MVD_IntHasDecodeIframe(u32IntStat))
2328                 {
2329                     *pu32CurEvent |= E_MVD_EVENT_DEC_I;
2330                     MVD_DEBUGINFO(MVD_PRINT("===> E_MVD_EVENT_DEC_I!!!\n"));
2331                 }
2332             }
2333             if ((*pu32EventFlag & E_MVD_EVENT_DISP_VSYNC) == E_MVD_EVENT_DISP_VSYNC)
2334             {
2335                 if (MVD_IntVSyncInt(u32IntStat))
2336                 {
2337                     *pu32CurEvent |= E_MVD_EVENT_DISP_VSYNC;
2338                     MVD_DEBUGINFO(MVD_PRINT("===> VSyncInt!!!\n"));
2339                 }
2340             }
2341 
2342             if ((*pu32EventFlag & E_MVD_EVENT_DEC_ONE_FRAME) == E_MVD_EVENT_DEC_ONE_FRAME)
2343             {
2344                 if (MVD_IntDecOneFrmInt(u32IntStat))
2345                 {
2346                     *pu32CurEvent |= E_MVD_EVENT_DEC_ONE_FRAME;
2347                     MVD_DEBUGINFO(MVD_PRINT("===> DecOneFrameInt!!!\n"));
2348                 }
2349             }
2350 
2351 
2352             if ((*pu32EventFlag & E_MVD_EVENT_UNMUTE) == E_MVD_EVENT_UNMUTE)
2353             {
2354                 MVD_DEBUGINFO(MVD_PRINT("E_MVD_EVENT_UNMUTE...\n"));
2355                 if (MVD_IntVSyncInt(u32IntStat))
2356                 {
2357                     MVD_DEBUGINFO(MVD_PRINT("===> UNMUTE?!\n"));
2358                     if (HAL_MVD_GetIsIPicFound(u8HalIdx) != NULL)
2359                     {
2360                         (pMVDDrvContext->u32VSyncCnt[u8DrvIdx])++;
2361                         if ((HAL_MVD_GetIsSyncReach(u8HalIdx)==1) ||
2362                                 (pMVDDrvContext->u32VSyncCnt[u8DrvIdx] > 60) ||
2363                                 (HAL_MVD_GetIsAVSyncOn(u8HalIdx) == FALSE))
2364                         {
2365                             pMVDDrvContext->u32VSyncCnt[u8DrvIdx] = 0;
2366                             *pu32CurEvent |= E_MVD_EVENT_UNMUTE;
2367                             MVD_DEBUGINFO(MVD_PRINT("UnMute!!!\n"));
2368                             *pu32EventFlag &= (~E_MVD_EVENT_UNMUTE);
2369                             HAL_MVD_EnableInt(u8HalIdx, *pu32EventFlag);
2370                         }
2371                     }
2372                     else // for P/B frame only stream
2373                     {
2374                         if (HAL_MVD_GetIsSyncReach(u8HalIdx) == 1) //sync done
2375                         {
2376                             (pMVDDrvContext->u32SyncDoneCnt[u8DrvIdx])++;
2377                         }
2378 
2379                         if (pMVDDrvContext->u32SyncDoneCnt[u8DrvIdx] > PB_ONLY_UNMUTE_VSYNC_COUNT) //sync done
2380                         {
2381                             MVD_DEBUGINFO(MVD_PRINT("UnMute after %d vsync!!!\n", PB_ONLY_UNMUTE_VSYNC_COUNT));
2382                             *pu32CurEvent |= E_MVD_EVENT_UNMUTE;
2383                             *pu32EventFlag &= (~E_MVD_EVENT_UNMUTE);
2384                             HAL_MVD_EnableInt(u8HalIdx, *pu32EventFlag);
2385                             pMVDDrvContext->u32SyncDoneCnt[u8DrvIdx] = 0;
2386                         }
2387                     }
2388                 }
2389             }
2390 
2391             if ((*pu32EventFlag & E_MVD_EVENT_DEC_ERR) == E_MVD_EVENT_DEC_ERR)
2392             {
2393                 if (MVD_IntHasDecodeErr(u32IntStat))
2394                 {
2395                     *pu32CurEvent |= E_MVD_EVENT_DEC_ERR;
2396                     MVD_DEBUGINFO(MVD_PRINT("===> Decode error!!!\n"));
2397                 }
2398             }
2399 
2400             if ((*pu32EventFlag & E_MVD_EVENT_DEC_DATA_ERR) == E_MVD_EVENT_DEC_DATA_ERR)
2401             {
2402                 if (MVD_IntHasESDataInvalid(u32IntStat))
2403                 {
2404                     *pu32CurEvent |= E_MVD_EVENT_DEC_DATA_ERR;
2405                     MVD_DEBUGINFO(MVD_PRINT("===> ES data invaild!!!\n"));
2406                 }
2407             }
2408 
2409             //Events that user registered occurred, call user's callback function
2410             if ((*pu32CurEvent!=E_MVD_EVENT_DISABLE_ALL) && (pfnCb!=NULL))
2411             {
2412                 MVD_DEBUGINFO(MVD_PRINT("%s Callback for *pu32CurEvent=0x%x, cbData=0x%x\n",
2413                     __FUNCTION__, *pu32CurEvent, u32CbData));
2414 #ifdef VDEC3
2415                 pfnCb(u32Id);
2416 #else
2417                 pfnCb(u32CbData);
2418 #endif
2419             }
2420         }
2421 
2422         //clear events
2423         *pu32CurEvent = E_MVD_EVENT_DISABLE_ALL;
2424     }
2425 
2426     HAL_MVD_ClearIRQ(); //clear interrupt
2427     if(TRUE == OSAL_MVD_IntEnable())//enable cpu interrupt mask
2428     {
2429         _bDisableFlag = FALSE;
2430     }
2431 }
2432 
2433 //-----------------------------------------------------------------------------
2434 /// @brief \b Function \b Name: MDrv_HVD_SetISREvent()
2435 /// @brief \b Function \b Description: Set the ISR event type sended by HVD fw.
2436 /// @param -eEvent \b IN : event types
2437 /// @param -fnISRHandler \b IN : function pointer to a interrupt handler.
2438 /// @return -The result of command set ISR event.
2439 //-----------------------------------------------------------------------------
MDrv_MVD_SetIsrEvent(MS_U32 u32Id,MS_U32 eEvent,MVD_InterruptCb fnHandler)2440 E_MVD_Result MDrv_MVD_SetIsrEvent(MS_U32 u32Id, MS_U32 eEvent, MVD_InterruptCb fnHandler)
2441 {
2442     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
2443 
2444     if (FALSE == MVD_GetIsUsed(u8DrvIdx))
2445     {
2446         MVD_DEBUGERROR(MVD_ERR("Call %s before Init\n", __FUNCTION__));
2447         return E_MVD_RET_FAIL;
2448     }
2449 
2450     if (eEvent == E_MVD_EVENT_DISABLE_ALL)
2451     {
2452         MS_U32 i = 0;
2453         MS_BOOL bUsed = FALSE;
2454         for(i = 0; i < MVD_MAX_STREAMS; i++)
2455         {
2456             if((i != u8DrvIdx)
2457             && (TRUE == pMVDDrvContext->gMVDCtrl_EX[i].bUsed))
2458             {
2459                 bUsed = TRUE;
2460                 break;
2461             }
2462         }
2463         // Fix the ISR imbalance of Enable and Disable
2464         // this is the rootcase of MVD ISR fail.
2465         if((_bDisableFlag != TRUE) && (FALSE == bUsed))
2466         {
2467             _bDisableFlag = OSAL_MVD_IntDisable();
2468             if(_bDisableFlag == FALSE)
2469             {
2470                 MVD_DEBUGERROR(VPRINTF("%s Disable Interrupt Fail\n", __FUNCTION__));
2471             }
2472 #if !defined(SUPPORT_X_MODEL_FEATURE) && !defined(DISABLE_ISR_DETACH)
2473         if(TRUE == bMVDIsrAttached)
2474         {
2475             OSAL_MVD_IsrDetach();
2476             bMVDIsrAttached = FALSE;
2477         }
2478 #endif
2479         }
2480         pMVDDrvContext->_pfnCallback[u8DrvIdx] = NULL;
2481         pMVDDrvContext->_u32CallbackPara[u8DrvIdx] = MVD_U32_MAX;
2482         pMVDDrvContext->_eEventFlag[u8DrvIdx] = E_MVD_EVENT_DISABLE_ALL;
2483     }
2484     else
2485     {
2486         if(fnHandler != NULL)
2487         {
2488             //disable int & dettach isr?
2489 
2490             pMVDDrvContext->_pfnCallback[u8DrvIdx] = (MVD_InterruptCb)fnHandler;
2491             pMVDDrvContext->_u32CallbackPara[u8DrvIdx] = u32Id;
2492             MVD_DEBUGINFO(MVD_PRINT("%s Hook callback u32Id=0x%x u8HalIdx=0x%x eEvent=0x%x\n",
2493                 __FUNCTION__, u32Id, u8DrvIdx, eEvent));
2494             pMVDDrvContext->_eEventFlag[u8DrvIdx] = eEvent;
2495 
2496 #if !defined(SUPPORT_X_MODEL_FEATURE) && !defined(DISABLE_ISR_DETACH)
2497             if (FALSE == bMVDIsrAttached)
2498             {
2499                 if (OSAL_MVD_IsrAttach((void*)MVD_IsrProc) != TRUE)
2500                 {
2501                     MVD_DEBUGERROR(MVD_ERR("fail to attach MVD_IsrProc!\n"));
2502                     return E_MVD_RET_FAIL;
2503                 }
2504                 bMVDIsrAttached = TRUE;
2505                 if (OSAL_MVD_IntEnable() != TRUE)
2506                 {
2507                     MVD_DEBUGERROR(MVD_ERR("fail to OSAL_MVD_IntEnable!\n"));
2508                     return E_MVD_RET_FAIL;
2509                 }
2510                 _bDisableFlag = FALSE;
2511             }
2512 #else
2513             if (FALSE == bMVDIsrAttached)
2514             {
2515                 if (OSAL_MVD_IsrAttach((void*)MVD_IsrProc) != TRUE)
2516                 {
2517                     MVD_DEBUGERROR(MVD_ERR("fail to attach MVD_IsrProc!\n"));
2518                     return E_MVD_RET_FAIL;
2519                 }
2520                 bMVDIsrAttached = TRUE;
2521             }
2522 
2523             if (OSAL_MVD_IntEnable() != TRUE)
2524             {
2525                 MVD_DEBUGERROR(MVD_ERR("fail to OSAL_MVD_IntEnable!\n"));
2526                 return E_MVD_RET_FAIL;
2527             }
2528             _bDisableFlag = FALSE;
2529 #endif
2530             MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_SetIsrEvent eEventFlag=0x%x\n", pMVDDrvContext->_eEventFlag[u8DrvIdx]));
2531             MDrv_MVD_EnableInt(u32Id, pMVDDrvContext->_eEventFlag[u8DrvIdx]);
2532             MVD_DEBUGINFO(MVD_PRINT("attach ISR number:%d\n" , E_INT_IRQ_MVD));
2533             return E_MVD_RET_OK;
2534         }
2535         else
2536         {
2537             MVD_DEBUGERROR(MVD_ERR( "SetISREvent with NULL pointer. ISR type:%u\n", (MS_U32)eEvent));
2538             return E_MVD_RET_INVALID_PARAM;
2539         }
2540     }
2541     return E_MVD_RET_OK;
2542 }
2543 
2544 #endif //MVD_ENABLE_ISR
2545 
2546 
2547 //------------------------------------------------------------------------------
2548 /// Set AVSync mode for file mode.
2549 /// @param -eSyncMode: avsync mode for file mode
2550 //------------------------------------------------------------------------------
MDrv_MVD_SetFileModeAVSync(MS_U32 u32Id,MVD_TIMESTAMP_TYPE eSyncMode)2551 MS_BOOL MDrv_MVD_SetFileModeAVSync(MS_U32 u32Id, MVD_TIMESTAMP_TYPE eSyncMode)
2552 {
2553     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2554     return HAL_MVD_SetFileModeAVSync(u8HalIdx, eSyncMode);
2555 }
2556 
2557 //-----------------------------------------------------------------------------
2558 /// @brief Check if all of the buffers(display, decoded, bitstream) are empty.
2559 /// @return - TRUE / FALSE
2560 /// @retval     -FALSE(0): Not Empty.
2561 /// @retval     -TRUE(1): Empty.
2562 //-----------------------------------------------------------------------------
MDrv_MVD_IsAllBufferEmpty(MS_U32 u32Id)2563 MS_BOOL MDrv_MVD_IsAllBufferEmpty(MS_U32 u32Id)
2564 {
2565     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2566     MVD_DEBUGINFO(MVD_PRINT("%s stat=0x%x, cmd=0x%x\n", __FUNCTION__,
2567                   MDrv_MVD_GetDecodeStatus(u32Id), MDrv_MVD_GetLastCmd(u32Id)));
2568     return HAL_MVD_IsAllBufferEmpty(u8HalIdx);
2569 }
2570 
2571 //-----------------------------------------------------------------------------
2572 /// @brief Generate specific pattern to support some special function.
2573 /// @param -u32VAddr \b IN : the virtual address of specific pattern
2574 /// @param -u32Size \b IN, OUT :
2575 ///                             IN: the input array size.
2576 ///                             OUT: the used array size.
2577 /// @return -The result of command generate specific pattern
2578 //-----------------------------------------------------------------------------
MDrv_MVD_GenPattern(MS_U32 u32Id,MVD_PatternType ePattern,MS_PHY u32PAddr,MS_U32 * pu32Size)2579 MS_BOOL MDrv_MVD_GenPattern(MS_U32 u32Id, MVD_PatternType ePattern, MS_PHY u32PAddr, MS_U32* pu32Size)
2580 {
2581     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2582     if (!pu32Size)
2583     {
2584         return FALSE;
2585     }
2586     return HAL_MVD_GenPattern(u8HalIdx, ePattern, u32PAddr, pu32Size);
2587 }
2588 
2589 //-----------------------------------------------------------------------------
2590 /// @brief Get driver specific data information
2591 /// @return -the information of choosed type
2592 //-----------------------------------------------------------------------------
MDrv_MVD_GetPatternInfo(void)2593 MS_U32 MDrv_MVD_GetPatternInfo(void)
2594 {
2595     return MVD_U32_MAX;
2596 }
2597 
2598 //-----------------------------------------------------------------------------
2599 /// @brief Pass scalar parameters to f/w
2600 /// @return -The result of command.
2601 //-----------------------------------------------------------------------------
MDrv_MVD_SetDynScalingParam(MS_U32 u32Id,MS_PHY u32StAddr,MS_SIZE u32Size)2602 E_MVD_Result MDrv_MVD_SetDynScalingParam(MS_U32 u32Id, MS_PHY u32StAddr, MS_SIZE u32Size)
2603 {
2604     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2605     if ((u32StAddr==NULL) || (u32Size==0))
2606     {
2607         MVD_DEBUGERROR(MVD_ERR("%s invalid para u32StAddr=0x%lx, u32Size=0x%lx\n",
2608                        __FUNCTION__, (unsigned long)u32StAddr, (unsigned long)u32Size));
2609         return E_MVD_RET_INVALID_PARAM;
2610     }
2611     return HAL_MVD_SetDynScalingParam(u8HalIdx, u32StAddr, u32Size);
2612 }
2613 
2614 //------------------------------------------------------------------------------
2615 /// Set virtual box width/height to F/W.
2616 /// F/W will use the same w/h as scaler to calculate scaling factor.
2617 /// @return -TRUE for success; FALSE for failure.
2618 //------------------------------------------------------------------------------
MDrv_MVD_SetVirtualBox(MS_U32 u32Id,MS_U16 u16Width,MS_U16 u16Height)2619 MS_BOOL MDrv_MVD_SetVirtualBox(MS_U32 u32Id, MS_U16 u16Width, MS_U16 u16Height)
2620 {
2621     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2622     MVD_DEBUGINFO(MVD_PRINT("%s: w=0x%x h=0x%x\n", __FUNCTION__, u16Width, u16Height));
2623     return HAL_MVD_SetVirtualBox(u8HalIdx, u16Width, u16Height);
2624 }
2625 
2626 //------------------------------------------------------------------------------
2627 /// Set blue screen
2628 /// @return -TRUE for success; FALSE for failure.
2629 //------------------------------------------------------------------------------
MDrv_MVD_SetBlueScreen(MS_U32 u32Id,MS_BOOL bEn)2630 MS_BOOL MDrv_MVD_SetBlueScreen(MS_U32 u32Id, MS_BOOL bEn)
2631 {
2632     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2633     return HAL_MVD_SetBlueScreen(u8HalIdx, bEn);
2634 }
2635 
MDrv_MVD_TrickPlay2xAVSync(MS_U32 u32Id,MS_BOOL bEnable)2636 void MDrv_MVD_TrickPlay2xAVSync(MS_U32 u32Id,MS_BOOL bEnable)
2637 {
2638     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
2639     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2640     pMVDDrvContext->bTrickPlay2xAVSync[u8DrvIdx] = bEnable;
2641     return HAL_MVD_TrickPlay2xAVSync(u8HalIdx,bEnable);
2642 }
2643 
2644 //------------------------------------------------------------------------------
2645 /// Set FRC Only Show TopField
2646 /// @return -TRUE for success; FALSE for failure.
2647 //------------------------------------------------------------------------------
MDrv_MVD_FRC_OnlyShowTopField(MS_U32 u32Id,MS_BOOL bEnable)2648 MS_BOOL MDrv_MVD_FRC_OnlyShowTopField(MS_U32 u32Id, MS_BOOL bEnable)
2649 {
2650     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2651     return HAL_MVD_FRC_OnlyShowTopField(u8HalIdx, bEnable);
2652 }
2653 
2654 //------------------------------------------------------------------------------
2655 /// Enable/Disable VSync interrupt
2656 /// @return -TRUE for success; FALSE for failure.
2657 //------------------------------------------------------------------------------
MDrv_MVD_EnableInt(MS_U32 u32Id,MS_U32 bEn)2658 MS_BOOL MDrv_MVD_EnableInt(MS_U32 u32Id, MS_U32 bEn)
2659 {
2660     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2661     return HAL_MVD_EnableInt(u8HalIdx, bEn);
2662 }
2663 
2664 //------------------------------------------------------------------------------
2665 /// Enable FW only show one field.
2666 /// @return -TRUE for success; FALSE for failure.
2667 //------------------------------------------------------------------------------
MDrv_MVD_EnableDispOneField(MS_U32 u32Id,MS_BOOL bEn)2668 E_MVD_Result MDrv_MVD_EnableDispOneField(MS_U32 u32Id, MS_BOOL bEn)
2669 {
2670     MVD_FUNC_ENTRY();
2671     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2672     return HAL_MVD_EnableDispOneField(u8HalIdx, bEn);
2673 }
2674 
2675 //------------------------------------------------------------------------------
2676 /// Get extension info of the display .
2677 /// @return -TRUE for success; FALSE for failure.
2678 //------------------------------------------------------------------------------
MDrv_MVD_GetExtDispInfo(MS_U32 u32Id,MVD_ExtDispInfo * pInfo)2679 E_MVD_Result MDrv_MVD_GetExtDispInfo(MS_U32 u32Id, MVD_ExtDispInfo* pInfo)
2680 {
2681     E_MVD_Result eRet = E_MVD_RET_OK;
2682     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2683     if (NULL == pInfo)
2684     {
2685         MVD_DEBUGERROR(MVD_ERR("GetExtDispInfo NULL pInfo!\n"));
2686         return E_MVD_RET_INVALID_PARAM;
2687     }
2688 
2689     HAL_MVD_GetExtDispInfo(u8HalIdx, pInfo);
2690     return eRet;
2691 }
2692 
2693 //------------------------------------------------------------------------------
2694 /// Get info of the decoded/displaying frame.
2695 /// @return -TRUE for success; FALSE for failure.
2696 //------------------------------------------------------------------------------
MDrv_MVD_GetFrmInfo(MS_U32 u32Id,MVD_FrmInfoType eType,MVD_FrmInfo * pInfo)2697 E_MVD_Result MDrv_MVD_GetFrmInfo(MS_U32 u32Id, MVD_FrmInfoType eType, MVD_FrmInfo* pInfo)
2698 {
2699     E_MVD_Result eRet = E_MVD_RET_OK;
2700     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2701     if (NULL == pInfo)
2702     {
2703         MVD_DEBUGERROR(MVD_ERR("GetFrmInfo NULL pInfo!\n"));
2704         return E_MVD_RET_INVALID_PARAM;
2705     }
2706     eRet = HAL_MVD_GetFrmInfo(u8HalIdx, eType, pInfo);
2707     //MVD_DumpFrmInfo(pInfo);
2708     return eRet;
2709 }
2710 
2711 //------------------------------------------------------------------------------
2712 /// Get Color info of the decoded/displaying frame.
2713 /// @return -TRUE for success; FALSE for failure.
2714 //------------------------------------------------------------------------------
MDrv_MVD_GetColorInfo(MS_U32 u32Id,MVD_Color_Info * pstColorInfo)2715 MS_BOOL MDrv_MVD_GetColorInfo(MS_U32 u32Id, MVD_Color_Info* pstColorInfo)
2716 {
2717     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2718     if (NULL == pstColorInfo)
2719     {
2720         MVD_DEBUGERROR(MVD_ERR("GetColorInfo NULL pInfo!\n"));
2721         return FALSE;
2722     }
2723     return HAL_MVD_GetColorInfo(u8HalIdx, pstColorInfo);
2724 }
2725 
2726 
2727 //------------------------------------------------------------------------------
2728 /// Get time_code of the decoded/displaying frame.
2729 /// @return -TRUE for success; FALSE for failure.
2730 //------------------------------------------------------------------------------
MDrv_MVD_GetTimeCode(MS_U32 u32Id,MVD_FrmInfoType eType,MVD_TimeCode * pInfo)2731 E_MVD_Result MDrv_MVD_GetTimeCode(MS_U32 u32Id, MVD_FrmInfoType eType, MVD_TimeCode* pInfo)
2732 {
2733     E_MVD_Result eRet = E_MVD_RET_OK;
2734     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2735     if (NULL == pInfo)
2736     {
2737         return E_MVD_RET_INVALID_PARAM;
2738     }
2739 
2740     if (TRUE != HAL_MVD_GetTimeCode(u8HalIdx, eType, pInfo))
2741     {
2742         MVD_DEBUGERROR(MVD_ERR("MDrv_MVD_GetTimeCode fail\n"));
2743         return E_MVD_RET_FAIL;
2744     }
2745 
2746     if ((E_MVD_FRMINFO_DECODE != eType) || (E_MVD_FRMINFO_DISPLAY == eType))
2747     {
2748         eRet = E_MVD_RET_INVALID_PARAM;
2749     }
2750 
2751     return eRet;
2752 }
2753 
MDrv_MVD_GetUsrDataIsAvailable(MS_U32 u32Id)2754 MS_BOOL MDrv_MVD_GetUsrDataIsAvailable(MS_U32 u32Id)
2755 {
2756     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2757     return HAL_MVD_GetUsrDataIsAvailable(u8HalIdx);
2758 }
2759 
2760 //------------------------------------------------------------------------------
2761 /// Get info of user data
2762 //------------------------------------------------------------------------------
MDrv_MVD_GetUsrDataInfo(MS_U32 u32Id,MVD_UsrDataInfo * pUsrInfo)2763 MS_BOOL MDrv_MVD_GetUsrDataInfo(MS_U32 u32Id, MVD_UsrDataInfo* pUsrInfo)
2764 {
2765     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2766     if (!pUsrInfo)
2767     {
2768         MVD_DEBUGERROR(MVD_ERR("%s: NULL ptr.\n", __FUNCTION__));
2769         return FALSE;
2770     }
2771     return HAL_MVD_GetUsrDataInfo(u8HalIdx, pUsrInfo);
2772 }
2773 
2774 //------------------------------------------------------------------------------
2775 /// Enable/Disable freezing display
2776 /// Once this flag is set, firmware continue decode new frame
2777 /// but not to push this frame into display queue.
2778 /// @return -TRUE for success; FALSE for failure.
2779 //------------------------------------------------------------------------------
MDrv_MVD_SetFreezeDisp(MS_U32 u32Id,MS_BOOL bEn)2780 E_MVD_Result MDrv_MVD_SetFreezeDisp(MS_U32 u32Id, MS_BOOL bEn)
2781 {
2782     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2783 
2784     MDrv_MVD_SetSpeed(u32Id, E_MVD_SPEED_DEFAULT, 1);
2785     if (TRUE == HAL_MVD_SetFreezeDisp(u8HalIdx, bEn))
2786     {
2787         return E_MVD_RET_OK;
2788     }
2789     else
2790     {
2791         return E_MVD_RET_FAIL;
2792     }
2793 }
2794 
2795 //------------------------------------------------------------------------------
2796 /// Get MVD displayed picture counter
2797 /// @return - displayed picture counter
2798 //------------------------------------------------------------------------------
MDrv_MVD_GetDispCount(MS_U32 u32Id)2799 MS_U32 MDrv_MVD_GetDispCount(MS_U32 u32Id)
2800 {
2801     MVD_FUNC_ENTRY();
2802     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2803     return HAL_MVD_GetDispCnt(u8HalIdx);
2804 }
2805 
2806 //------------------------------------------------------------------------------
2807 /// Get MVD displayed picture counter
2808 /// @return - displayed picture counter
2809 //------------------------------------------------------------------------------
MDrv_MVD_GetDropCount(MS_U32 u32Id)2810 MS_U32 MDrv_MVD_GetDropCount(MS_U32 u32Id)
2811 {
2812     MVD_FUNC_ENTRY();
2813     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2814     return HAL_MVD_GetDropCnt(u8HalIdx);
2815 }
2816 
2817 //------------------------------------------------------------------------------
2818 /// Set MVD fd mask delay count
2819 /// 16bits and unit in vsync for mute the fd_mask
2820 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
2821 //------------------------------------------------------------------------------
MDrv_MVD_SetFdMaskDelayCount(MS_U32 u32Id,MS_U16 u16Cnt)2822 E_MVD_Result MDrv_MVD_SetFdMaskDelayCount(MS_U32 u32Id, MS_U16 u16Cnt)
2823 {
2824     MVD_FUNC_ENTRY();
2825     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2826     return HAL_MVD_SetFdMaskDelayCount(u8HalIdx, u16Cnt);
2827 }
2828 
2829 //------------------------------------------------------------------------------
2830 /// Set MVD fd mask delay count
2831 /// 16bits and unit in vsync for mute the fd_mask
2832 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
2833 //------------------------------------------------------------------------------
MDrv_MVD_GetXcLowDelayIntState(MS_U32 u32Id)2834 E_MVD_Result MDrv_MVD_GetXcLowDelayIntState(MS_U32 u32Id)
2835 {
2836     MVD_FUNC_ENTRY();
2837     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2838     return HAL_MVD_GetXcLowDelayIntState(u8HalIdx);
2839 }
2840 
2841 //------------------------------------------------------------------------------
2842 /// Set MVD output frame rate convert
2843 /// @param u8FrameRate \b IN : output frame rate of 8bits and unit in vsync
2844 /// @param u8Interlace \b IN : scan style 0:progress, 1:interlace
2845 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
2846 //------------------------------------------------------------------------------
MDrv_MVD_SetOutputFRCMode(MS_U32 u32Id,MS_U8 u8FrameRate,MS_U8 u8Interlace)2847 E_MVD_Result MDrv_MVD_SetOutputFRCMode(MS_U32 u32Id, MS_U8 u8FrameRate, MS_U8 u8Interlace)
2848 {
2849     MVD_FUNC_ENTRY();
2850     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2851     return HAL_MVD_SetOutputFRCMode(u8HalIdx, u8FrameRate, u8Interlace);
2852 }
2853 
2854 //------------------------------------------------------------------------------
2855 /// Set MVD FRC drop type.
2856 /// @param u8DropType \b IN : drop type. 0:drop frame, 1:drop field. default:0
2857 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
2858 //------------------------------------------------------------------------------
MDrv_MVD_SetFRCDropType(MS_U32 u32Id,MS_U8 u8DropType)2859 E_MVD_Result MDrv_MVD_SetFRCDropType(MS_U32 u32Id, MS_U8 u8DropType)
2860 {
2861     MVD_FUNC_ENTRY();
2862     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2863     return HAL_MVD_SetFRCDropType(u8HalIdx, u8DropType);
2864 }
2865 
2866 //------------------------------------------------------------------------------
2867 /// Set disable resolution change.
2868 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
2869 //------------------------------------------------------------------------------
MDrv_MVD_SetDisableSeqChange(MS_U32 u32Id,MS_BOOL bEnable)2870 E_MVD_Result MDrv_MVD_SetDisableSeqChange(MS_U32 u32Id, MS_BOOL bEnable)
2871 {
2872     MVD_FUNC_ENTRY();
2873     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2874     return HAL_MVD_SetDisableSeqChange(u8HalIdx, bEnable);
2875 }
2876 
2877 //------------------------------------------------------------------------------
2878 /// Force Enable/Disable Es Full stop
2879 /// @param bDisable-  0: force enable es full stop mode in ts/dtv 1:  force disable es full stop mode in ts/dtv
2880 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
2881 //------------------------------------------------------------------------------
MDrv_MVD_DisableEsFullStop(MS_U32 u32Id,MS_BOOL bDisable)2882 MS_BOOL MDrv_MVD_DisableEsFullStop(MS_U32 u32Id, MS_BOOL bDisable)
2883 {
2884     MVD_FUNC_ENTRY();
2885     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2886     return HAL_MVD_DisableESFullStop(u8HalIdx, bDisable);
2887 }
2888 
MDrv_MVD_PUSI_Control(MS_U32 u32Id,MS_BOOL bEnable)2889 MS_BOOL MDrv_MVD_PUSI_Control(MS_U32 u32Id, MS_BOOL bEnable)
2890 {
2891     MVD_FUNC_ENTRY();
2892     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2893     return HAL_MVD_PUSI_Control(u8HalIdx, bEnable);
2894 }
2895 
2896 
2897 //------------------------------------------------------------------------------
2898 /// Debug function to dump useful info.
2899 //------------------------------------------------------------------------------
MDrv_MVD_DbgDump(MS_U32 u32Id)2900 void MDrv_MVD_DbgDump(MS_U32 u32Id)
2901 {
2902     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
2903     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2904     MVD_FrameInfo* pPreInfo = &(pMVDDrvContext->stPreFrmInfo[u8DrvIdx]);
2905     MVD_AVSyncCfg* pAVSyncCfg  = &(pMVDDrvContext->stSyncCfg[u8DrvIdx]);
2906 
2907     if (FALSE == MVD_GetIsUsed(u8DrvIdx))
2908     {
2909         MVD_PRINT("%s: _bDrvInit false!\n", __FUNCTION__);
2910         return;
2911     }
2912 
2913     HAL_MVD_DbgDump(u8HalIdx);
2914     MVD_PRINT("avsync on=%x, delay=%d, tolerance=%d, done=%x, skip=%x, repeat=%x, pts=%dms\n",
2915             pAVSyncCfg->bEnable, pAVSyncCfg->u32Delay, pAVSyncCfg->u16Tolerance, (MDrv_MVD_GetSyncStatus(u32Id)==1),
2916             MDrv_MVD_GetIsSyncSkip(u32Id), MDrv_MVD_GetIsSyncRep(u32Id), MDrv_MVD_GetPTS(u32Id));
2917     MVD_PRINT("seq(%d): w=%d, h=%d, i/p=%x, fps=%d\n", MDrv_MVD_GetDispRdy(u32Id),
2918         pPreInfo->u16HorSize, pPreInfo->u16VerSize,
2919         pPreInfo->u8Interlace, pPreInfo->u32FrameRate);
2920 }
2921 
2922 //------------------------------------------------------------------------------
2923 /// Dump the bitstream to predefined buffer address.
2924 /// Before PLAY command, set the bitstream base & bitstream length, and then
2925 /// CPU would continue to dump bitstream at the base address.
2926 /// @param -u32base \b IN : start address (MIU offset, e.g. 128M==>0MB)
2927 /// @param -u32size \b IN : size (bytes)
2928 //------------------------------------------------------------------------------
MDrv_MVD_DbgDumpBits(MS_U32 u32Id,MS_PHY u32base,MS_U32 u32size)2929 void MDrv_MVD_DbgDumpBits(MS_U32 u32Id, MS_PHY u32base, MS_U32 u32size)
2930 {
2931     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2932     HAL_MVD_DbgDumpBits(u8HalIdx, u32base, u32size);
2933     return;
2934 }
2935 
2936 // only for VDEC internal link patch
MDrv_MVD_LinkWeakSymbolPatch(void)2937 MS_BOOL MDrv_MVD_LinkWeakSymbolPatch(void)
2938 {
2939     return TRUE;
2940 }
2941 
2942 //------------------------------------------------------------------------------
2943 /// Set firmware as MStreamer mode
2944 /// @return -TRUE for success; FALSE for failure.
2945 //------------------------------------------------------------------------------
MDrv_MVD_SetMStreamerMode(MS_U32 u32Id,MS_U8 u8Mode)2946 MS_BOOL MDrv_MVD_SetMStreamerMode(MS_U32 u32Id, MS_U8 u8Mode)
2947 {
2948     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2949     return HAL_MVD_SetMStreamerMode(u8HalIdx, u8Mode);
2950 }
2951 
2952 //-----------------------------------------------------------------------------
2953 /// set firmware as MCU mode
2954 /// @return -TRUE for success; FALSE for failure.
2955 //-----------------------------------------------------------------------------
MDrv_MVD_SetMcuMode(MS_U32 u32Id,MS_U8 u8Mode)2956 MS_BOOL MDrv_MVD_SetMcuMode(MS_U32 u32Id, MS_U8 u8Mode)
2957 {
2958     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2959 #ifdef VDEC3
2960     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
2961     pMVDDrvContext->u32FrameBaseMode[u8DrvIdx] = u8Mode;
2962 #endif
2963     return HAL_MVD_SetMcuMode(u8HalIdx, u8Mode);
2964 }
2965 
2966 //-----------------------------------------------------------------------------
2967 /// set firmware as ForceInterlace mode
2968 /// @return -TRUE for success; FALSE for failure.
2969 //-----------------------------------------------------------------------------
MDrv_MVD_ForceInterlaceMode(MS_U32 u32Id,MS_U8 u8Mode)2970 MS_BOOL MDrv_MVD_ForceInterlaceMode(MS_U32 u32Id, MS_U8 u8Mode)
2971 {
2972     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2973     return HAL_MVD_ForceInterlaceMode(u8HalIdx, u8Mode);
2974 }
2975 
2976 //-----------------------------------------------------------------------------
2977 /// set firmware as Progressive mode
2978 /// @return -TRUE for success; FALSE for failure.
2979 //-----------------------------------------------------------------------------
MDrv_MVD_ForceProgressiveMode(MS_U32 u32Id,MS_U8 u8Mode)2980 MS_BOOL MDrv_MVD_ForceProgressiveMode(MS_U32 u32Id, MS_U8 u8Mode)
2981 {
2982     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2983     return HAL_MVD_ForceProgressiveMode(u8HalIdx, u8Mode);
2984 }
2985 
2986 
2987 //-----------------------------------------------------------------------------
2988 /// set firmware as I/P clip mode mode
2989 /// @return -TRUE for success; FALSE for failure.
2990 //-----------------------------------------------------------------------------
MDrv_MVD_ShowDecodeOrder(MS_U32 u32Id,MS_U8 u8Mode)2991 MS_BOOL MDrv_MVD_ShowDecodeOrder(MS_U32 u32Id, MS_U8 u8Mode)
2992 {
2993     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
2994     return HAL_MVD_ShowDecodeOrder(u8HalIdx, u8Mode);
2995 }
2996 
2997 
2998 
2999 //------------------------------------------------------------------------------
3000 /// Flip the specified frame
3001 /// @return -TRUE for success; FALSE for failure.
3002 //------------------------------------------------------------------------------
MDrv_MVD_FrameFlip(MS_U32 u32Id,MS_U8 u8FrmIdx)3003 MS_BOOL MDrv_MVD_FrameFlip(MS_U32 u32Id, MS_U8 u8FrmIdx)
3004 {
3005     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3006     if (TRUE != HAL_MVD_IsMStreamerMode(u8HalIdx))
3007     {
3008         MVD_DEBUGINFO(MVD_PRINT("Need to SetMStreamerMode before using this function\n"));
3009         return FALSE;
3010     }
3011 
3012     if (TRUE == HAL_MVD_IsMcuMode(u8HalIdx))
3013     {
3014         MVD_DEBUGINFO(MVD_PRINT("It's MCU mode, doesn't need to using this fuction\n"));
3015         return FALSE;
3016     }
3017 
3018     return HAL_MVD_FrameOpt(u8HalIdx, u8FrmIdx, E_MVD_FRAME_FLIP);
3019 }
3020 
3021 //------------------------------------------------------------------------------
3022 /// Release the specified frame
3023 /// @return -TRUE for success; FALSE for failure.
3024 //------------------------------------------------------------------------------
MDrv_MVD_FrameRelease(MS_U32 u32Id,MS_U8 u8FrmIdx)3025 MS_BOOL MDrv_MVD_FrameRelease(MS_U32 u32Id, MS_U8 u8FrmIdx)
3026 {
3027     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3028     if (TRUE != (HAL_MVD_IsMStreamerMode(u8HalIdx) || HAL_MVD_IsMcuMode(u8HalIdx)) )
3029     {
3030         MVD_DEBUGINFO(MVD_PRINT("Need to SetMStreamerMode or SetMcuMode before using this function\n"));
3031         return FALSE;
3032     }
3033     return HAL_MVD_FrameOpt(u8HalIdx, u8FrmIdx, E_MVD_FRAME_RELEASE);
3034 }
3035 
3036 //------------------------------------------------------------------------------
3037 /// Enable/Disable to capture the specified frame
3038 /// @return -TRUE for success; FALSE for failure.
3039 //------------------------------------------------------------------------------
MDrv_MVD_FrameCapture(MS_U32 u32Id,MS_U8 u8FrmIdx,MS_BOOL bEnable)3040 MS_BOOL MDrv_MVD_FrameCapture(MS_U32 u32Id, MS_U8 u8FrmIdx, MS_BOOL bEnable)
3041 {
3042     MS_BOOL ret = FALSE;
3043     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3044 
3045     if (TRUE != HAL_MVD_IsMStreamerMode(u8HalIdx))
3046     {
3047         MVD_DEBUGINFO(MVD_PRINT("Need to SetMStreamerMode before using this function\n"));
3048         return FALSE;
3049     }
3050 
3051     ret = HAL_MVD_FrameCapture(u8HalIdx, u8FrmIdx, bEnable);
3052 
3053     //firmware will keep this frame until we release it.
3054     if (ret && !bEnable)
3055     {
3056         ret = MDrv_MVD_FrameRelease(u32Id, u8FrmIdx);
3057     }
3058 
3059     return ret;
3060 }
3061 
3062 //------------------------------------------------------------------------------
3063 /// Allocate share memory from MSOS for Drv MVD
3064 /// @return -TRUE for success; FALSE for failure.
3065 //------------------------------------------------------------------------------
MDrv_MVD_Init_Share_Mem(void)3066 E_MVD_Result MDrv_MVD_Init_Share_Mem(void)
3067 {
3068 #if ((defined(MSOS_TYPE_LINUX) || defined(MSOS_TYPE_LINUX_KERNEL) || defined(MSOS_TYPE_ECOS)) && (!defined(SUPPORT_X_MODEL_FEATURE)))
3069     MS_U32 u32ShmId;
3070     MS_VIRT u32Addr;
3071     MS_U32 u32BufSize;
3072 
3073 
3074     if (FALSE == MsOS_SHM_GetId( (MS_U8*)"Linux MVD driver",
3075                                   sizeof(MVD_Drv_CTX),
3076                                   &u32ShmId,
3077                                   &u32Addr,
3078                                   &u32BufSize,
3079                                   MSOS_SHM_QUERY))
3080     {
3081         if (FALSE == MsOS_SHM_GetId((MS_U8*)"Linux MVD driver",
3082                                      sizeof(MVD_Drv_CTX),
3083                                      &u32ShmId,
3084                                      &u32Addr,
3085                                      &u32BufSize,
3086                                      MSOS_SHM_CREATE))
3087         {
3088             MVD_DEBUGERROR(MVD_ERR("[%s]SHM allocation failed!!! use global structure instead!!!\n",__FUNCTION__));
3089             if(pMVDDrvContext == NULL)
3090             {
3091                 pMVDDrvContext = &gMVDDrvContext;
3092                 memset(pMVDDrvContext,0,sizeof(MVD_Drv_CTX));
3093                 MVD_Context_Init();
3094                 MVD_PRINT("[%s]Global structure init Success!!!\n",__FUNCTION__);
3095             }
3096             else
3097             {
3098                 MVD_PRINT("[%s]Global structure exists!!!\n",__FUNCTION__);
3099             }
3100             //return E_MVD_RET_FAIL;
3101         }
3102         else
3103         {
3104             memset((MS_U8*)u32Addr,0,sizeof(MVD_Drv_CTX));
3105             pMVDDrvContext = (MVD_Drv_CTX*)u32Addr; // for one process
3106             MVD_Context_Init();
3107         }
3108     }
3109     else
3110     {
3111         pMVDDrvContext = (MVD_Drv_CTX*)u32Addr; // for another process
3112     }
3113 #else
3114     if(pMVDDrvContext == NULL)
3115     {
3116         pMVDDrvContext = &gMVDDrvContext;
3117         memset(pMVDDrvContext,0,sizeof(MVD_Drv_CTX));
3118         MVD_Context_Init();
3119     }
3120 #endif
3121 
3122     if(HAL_MVD_Init_Share_Mem() != TRUE)
3123     {
3124         return E_MVD_RET_FAIL;
3125     }
3126 
3127     if(HAL_VPU_EX_Init_Share_Mem() != TRUE)
3128     {
3129         return E_MVD_RET_FAIL;
3130     }
3131 
3132     return E_MVD_RET_OK;
3133 }
3134 
3135 
3136 //------------------------------------------------------------------------------
3137 /// Get the available streamID for the specified stream type
3138 /// @return u32ID as (drvIdx << 16 | u32MVDStreamId << 8 | u32VPUStreamId)
3139 //------------------------------------------------------------------------------
MDrv_MVD_GetFreeStream(MS_U32 * pu32Id,MVD_DRV_StreamType eStreamType)3140 E_MVD_Result MDrv_MVD_GetFreeStream(MS_U32 *pu32Id, MVD_DRV_StreamType eStreamType)
3141 {
3142     MS_U8 i = 0xff;
3143     MS_U32 u32VPUStreamId = 0;
3144     MS_U32 u32MVDStreamId = 0;
3145     HAL_VPU_StreamType eVpuStreamType = E_HAL_VPU_MAIN_STREAM;
3146     HAL_MVD_StreamType eHalStreamType = E_HAL_MVD_MAIN_STREAM;
3147 
3148     if(pu32Id == NULL)
3149     {
3150         MVD_DEBUGERROR(MVD_ERR("%s err: NULL pu32Id\n", __FUNCTION__));
3151         return E_MVD_RET_INVALID_PARAM;
3152     }
3153     else
3154     {
3155         *pu32Id = 0;
3156     }
3157 
3158 #ifndef VDEC3
3159     switch (eStreamType)
3160     {
3161       case E_MVD_DRV_MAIN_STREAM:
3162           i=0;
3163           break;
3164       case E_MVD_DRV_SUB_STREAM:
3165           i=1;
3166           break;
3167       case E_MVD_DRV_STREAM_NONE:
3168       default:
3169           i=0xff;
3170           break;
3171     }
3172 
3173     if ((i>=MVD_MAX_STREAMS) || (TRUE == MVD_GetIsUsed(i)))
3174     {
3175         MVD_DEBUGERROR(MVD_ERR("eStreamType=%x is used or invalid, i=%x\n", eStreamType, i));
3176         *pu32Id = 0;
3177         return E_MVD_RET_FAIL;
3178     }
3179 #endif
3180 
3181     //Get VPU & HAL stream id
3182     if (E_MVD_DRV_MAIN_STREAM == eStreamType)
3183     {
3184         eVpuStreamType = E_HAL_VPU_MAIN_STREAM;
3185         eHalStreamType = E_HAL_MVD_MAIN_STREAM;
3186         i = 0;
3187     }
3188     else if (E_MVD_DRV_SUB_STREAM == eStreamType)
3189     {
3190         eVpuStreamType = E_HAL_VPU_SUB_STREAM;
3191         eHalStreamType = E_HAL_MVD_SUB_STREAM;
3192         i = 1;
3193     }
3194 #ifdef VDEC3
3195     else if ((eStreamType >= E_MVD_DRV_N_STREAM) && (eStreamType < (E_MVD_DRV_N_STREAM+MVD_MAX_STREAMS)))
3196     {
3197         eVpuStreamType = E_HAL_VPU_N_STREAM + (eStreamType - E_MVD_DRV_N_STREAM);
3198         eHalStreamType = E_HAL_MVD_N_STREAM + (eStreamType - E_MVD_DRV_N_STREAM);
3199         i = eStreamType - E_MVD_DRV_N_STREAM;
3200     }
3201 #endif
3202 
3203     u32VPUStreamId = (MS_U32) HAL_VPU_EX_GetFreeStream(eVpuStreamType);
3204     if(u32VPUStreamId == E_HAL_VPU_STREAM_NONE)
3205     {
3206        return E_MVD_RET_FAIL;
3207     }
3208 
3209     u32MVDStreamId = (MS_U32) HAL_MVD_GetFreeStream(eHalStreamType);
3210     if(u32MVDStreamId == E_HAL_MVD_STREAM_NONE)
3211     {
3212         HAL_VPU_EX_ReleaseFreeStream(i);
3213     }
3214 
3215     MVD_DEBUGVERBAL(MVD_PRINT("%s:: i=0x%x, mvd=0x%x, vpu=0x%x\n", __FUNCTION__,
3216             i, u32MVDStreamId, u32VPUStreamId));
3217 
3218     if (u32VPUStreamId && u32MVDStreamId)
3219     {
3220         MVD_DEBUGINFO(MVD_PRINT("%s   i=0x%x, mvd=0x%x, vpu=0x%x\n", __FUNCTION__,
3221             i, u32MVDStreamId, u32VPUStreamId));
3222 #ifdef VDEC3
3223         *pu32Id = ((u32MVDStreamId & 0x0F) << 16 | u32MVDStreamId << 8 | u32VPUStreamId);
3224         if (FALSE == MVD_SaveStreamId(u32MVDStreamId&0x0F, u32MVDStreamId, u32VPUStreamId))
3225         {
3226             return E_MVD_RET_FAIL;
3227         }
3228 #else
3229         *pu32Id = (i << 16 | u32MVDStreamId << 8 | u32VPUStreamId);
3230         if (FALSE == MVD_SaveStreamId(i, u32MVDStreamId, u32VPUStreamId))
3231         {
3232             return E_MVD_RET_FAIL;
3233         }
3234 #endif
3235     }
3236     else
3237     {
3238 #ifdef VDEC3
3239         MVD_DEBUGINFO(MVD_PRINT("%s(%d) NG  i=0x%x, mvd=0x%x, vpu=0x%x\n", __FUNCTION__, __LINE__,
3240             u32MVDStreamId&0xf, u32MVDStreamId, u32VPUStreamId));
3241 #else
3242         MVD_DEBUGINFO(MVD_PRINT("%s(%d) NG  i=0x%x, mvd=0x%x, vpu=0x%x\n", __FUNCTION__, __LINE__,
3243             i, u32MVDStreamId, u32VPUStreamId));
3244 #endif
3245     }
3246 
3247     return E_MVD_RET_OK;
3248 }
3249 
3250 //------------------------------------------------------------------------------
3251 /// Set bitstream buffer overflow threshold
3252 /// @return -none
3253 //------------------------------------------------------------------------------
MDrv_MVD_SetOverflowTH(MS_U32 u32Id,MS_U32 u32Threshold)3254 void MDrv_MVD_SetOverflowTH(MS_U32 u32Id, MS_U32 u32Threshold)
3255 {
3256     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3257     HAL_MVD_SetOverflowTH(u8HalIdx, u32Threshold);
3258     return;
3259 }
3260 
3261 //------------------------------------------------------------------------------
3262 /// Set bitstream buffer underflow threshold
3263 /// @return -none
3264 //------------------------------------------------------------------------------
MDrv_MVD_SetUnderflowTH(MS_U32 u32Id,MS_U32 u32Threshold)3265 void MDrv_MVD_SetUnderflowTH(MS_U32 u32Id, MS_U32 u32Threshold)
3266 {
3267     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3268     HAL_MVD_SetUnderflowTH(u8HalIdx, u32Threshold);
3269     return;
3270 }
3271 
MDrv_MVD_SetSingleDecodeMode(MS_BOOL bEnable)3272 MS_BOOL MDrv_MVD_SetSingleDecodeMode(MS_BOOL bEnable)
3273 {
3274     return HAL_VPU_EX_SetSingleDecodeMode(bEnable);
3275 }
3276 
3277 //-----------------------------------------------------------------------------
3278 /// Release fd mask
3279 /// @return -TRUE for success; FALSE for failure.
3280 //-----------------------------------------------------------------------------
MDrv_MVD_ReleaseFdMask(MS_U32 u32Id,MS_BOOL bRls)3281 MS_BOOL MDrv_MVD_ReleaseFdMask(MS_U32 u32Id, MS_BOOL bRls)
3282 {
3283     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3284     return HAL_MVD_ReleaseFdMask(u8HalIdx, bRls);
3285 }
3286 
3287 //------------------------------------------------------------------------------
3288 /// Reset MVD parser .  It is used to reset MVD Parser.
3289 /// @return -TRUE for success; FALSE for failure.
3290 //------------------------------------------------------------------------------
MDrv_MVD_ParserRstDone(MS_U32 u32Id,MS_BOOL bEnable)3291 MS_BOOL MDrv_MVD_ParserRstDone(MS_U32 u32Id, MS_BOOL bEnable)
3292 {
3293     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3294     return HAL_MVD_ParserRstDone(u8HalIdx, bEnable);
3295 }
3296 //------------------------------------------------------------------------------
3297 /// Flush PTS buffer.
3298 /// @return -TRUE for success; FALSE for failure.
3299 //------------------------------------------------------------------------------
MDrv_MVD_FlushPTSBuf(MS_U32 u32Id,MS_BOOL bEnable)3300 MS_BOOL MDrv_MVD_FlushPTSBuf(MS_U32 u32Id,MS_BOOL bEnable)
3301 {
3302     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3303     return HAL_MVD_FlushPTSBuf(u8HalIdx ,bEnable);
3304 }
3305 
3306 //------------------------------------------------------------------------------
3307 /// Get SLQ number
3308 /// @return -the SLQ number
3309 //------------------------------------------------------------------------------
MDrv_MVD_GetSLQNum(MS_U32 u32Id)3310 MS_U32 MDrv_MVD_GetSLQNum(MS_U32 u32Id)
3311 {
3312 #ifdef VDEC3
3313     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
3314 
3315     if(pMVDDrvContext->u32FrameBaseMode[u8DrvIdx] == TRUE)
3316     {
3317     return 0;
3318     }
3319     else
3320 #endif
3321     {
3322         MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3323         return HAL_MVD_GetSLQNum(u8HalIdx);
3324     }
3325 }
3326 
3327 
3328 //-----------------------------------------------------------------------------
3329 /// @brief \b Function \b Name: MDrv_MVD_GetFrmRateIsSupported()
3330 /// @brief \b Function \b Description:  Get if the framerate is supported
3331 /// @return -The result of supported or not.
3332 //-----------------------------------------------------------------------------
MDrv_MVD_GetFrmRateIsSupported(MS_U32 u32Id)3333 MS_BOOL MDrv_MVD_GetFrmRateIsSupported(MS_U32 u32Id)
3334 {
3335     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
3336     MS_BOOL bSupported = pMVDDrvContext->bFrmRateSupported[u8DrvIdx];
3337 
3338     return bSupported;
3339 }
3340 
3341 //------------------------------------------------------------------------------
3342 /// set fw auto mute
3343 /// @return -TRUE for success; FALSE for failure.
3344 //------------------------------------------------------------------------------
MDrv_MVD_SetAutoMute(MS_U32 u32Id,MS_BOOL bEnable)3345 E_MVD_Result MDrv_MVD_SetAutoMute(MS_U32 u32Id, MS_BOOL bEnable)
3346 {
3347     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3348     MS_BOOL bRet = HAL_MVD_SetAutoMute(u8HalIdx, bEnable);
3349     return ((TRUE == bRet) ? E_MVD_RET_OK : E_MVD_RET_FAIL);
3350 }
3351 
MDrv_MVD_SetVSizeAlign(MS_U32 u32Id,MS_BOOL bEnable)3352 MS_BOOL MDrv_MVD_SetVSizeAlign(MS_U32 u32Id, MS_BOOL bEnable)
3353 {
3354     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3355     return HAL_MVD_SetVSizeAlign(u8HalIdx, bEnable);
3356 }
3357 
3358 //------------------------------------------------------------------------------
3359 /// Set codec type.
3360 /// @param -pCrcIn \b IN : the struct of generate CRC
3361 /// @param -pCrcOut \b OUT : CRC value from mvd hw
3362 //------------------------------------------------------------------------------
MDrv_MVD_GetCrcValue(MS_U32 u32Id,MVD_CrcIn * pCrcIn,MVD_CrcOut * pCrcOut)3363 E_MVD_Result MDrv_MVD_GetCrcValue(MS_U32 u32Id, MVD_CrcIn *pCrcIn, MVD_CrcOut *pCrcOut)
3364 {
3365     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3366 
3367     //check input parameters
3368     if (pCrcIn == NULL)
3369     {
3370         MVD_DEBUGERROR(MVD_ERR("PushQueue NULL pInfo\n"));
3371         return E_MVD_RET_INVALID_PARAM;
3372     }
3373 
3374     return HAL_MVD_GetCrcValue(u8HalIdx, pCrcIn, pCrcOut);
3375 }
3376 
3377 //------------------------------------------------------------------------------
3378 /// set debug mode
3379 /// @return -TRUE for success; FALSE for failure.
3380 //------------------------------------------------------------------------------
MDrv_MVD_SetDbgMode(MS_U32 u32Id,MVD_DbgMode enDbgMode,MS_BOOL bEn)3381 E_MVD_Result MDrv_MVD_SetDbgMode(MS_U32 u32Id, MVD_DbgMode enDbgMode, MS_BOOL bEn)
3382 {
3383     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3384     MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
3385     E_MVD_Result eRet=E_MVD_RET_FAIL;
3386 
3387     MVD_DEBUGINFO(MVD_PRINT("MDrv_MVD_SetDbgMode...%x\n",(unsigned int)pstCtrlCfg->stDbgModeCfg.value));
3388     switch (enDbgMode)
3389     {
3390         case E_MVD_EX_DBG_MODE_BYPASS_INSERT_START_CODE:
3391             {
3392                 pstCtrlCfg->stDbgModeCfg.bBypassInsertStartCode=bEn;
3393                 eRet=E_MVD_RET_OK;
3394             }
3395             break;
3396         case E_MVD_EX_DBG_MODE_BYPASS_DIVX_MC_PATCH:
3397             {
3398                 pstCtrlCfg->stDbgModeCfg.bBypassDivxMCPatch=bEn;
3399                 eRet=E_MVD_RET_OK;
3400             }
3401             break;
3402         default:
3403             eRet=E_MVD_RET_INVALID_PARAM;
3404             break;
3405     }
3406     MVD_DEBUGINFO(MVD_PRINT("%s   stDbgModeCfg=%x\n", __FUNCTION__, (unsigned int)pstCtrlCfg->stDbgModeCfg.value));
3407     return eRet;
3408 }
3409 
3410 //------------------------------------------------------------------------------
3411 /// Get SLQ number
3412 /// @return -the SLQ number
3413 //------------------------------------------------------------------------------
MDrv_MVD_GetDispQNum(MS_U32 u32Id)3414 MS_U32 MDrv_MVD_GetDispQNum(MS_U32 u32Id)
3415 {
3416     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3417     return HAL_MVD_GetDispQNum(u8HalIdx);
3418 }
3419 
3420 //------------------------------------------------------------------------------
3421 /// set fw fask suspend
3422 /// @return -TRUE for success; FALSE for failure.
3423 //------------------------------------------------------------------------------
3424 
MDrv_MVD_SuspendDynamicScale(MS_U32 u32Id,MS_BOOL bEnable)3425 MS_BOOL MDrv_MVD_SuspendDynamicScale(MS_U32 u32Id, MS_BOOL bEnable)
3426 {
3427     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3428     return HAL_MVD_SuspendDynamicScale(u8HalIdx, bEnable);
3429 }
3430 
MDrv_MVD_GetSuspendDynamicScale(MS_U32 u32Id)3431 MS_U8 MDrv_MVD_GetSuspendDynamicScale(MS_U32 u32Id)
3432 {
3433     MVD_FUNC_ENTRY();
3434     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3435     return HAL_MVD_GetSuspendDynamicScale(u8HalIdx);
3436 }
3437 
3438 //------------------------------------------------------------------------------
3439 /// get Stereo Type
3440 /// @return Stereo Type. 0000011(3) : 3d side-by-side   0001000(8) : 2d
3441 //------------------------------------------------------------------------------
3442 
MDrv_MVD_GetStereoType(MS_U32 u32Id)3443 MS_U8 MDrv_MVD_GetStereoType(MS_U32 u32Id)
3444 {
3445     MVD_FUNC_ENTRY();
3446     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3447     return HAL_MVD_GetStereoType(u8HalIdx);
3448 }
3449 
3450 //------------------------------------------------------------------------------
3451 /// Get MVD DivX plus Version,
3452 /// @return -non DivX plus  \b OUT 0
3453 //------------------------------------------------------------------------------
MDrv_MVD_GetDivxVer(MS_U32 u32Id)3454 MS_U32 MDrv_MVD_GetDivxVer(MS_U32 u32Id)
3455 {
3456     MVD_FUNC_ENTRY();
3457     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3458     return HAL_MVD_GetDivxVer(u8HalIdx);
3459 }
3460 
3461 //------------------------------------------------------------------------------
3462 /// Set IDCT mode
3463 /// @param -u8Mode \b IN : 0 for original IDCT, 1 for new IDCT
3464 /// @return -TRUE for success; FALSE for failure.
3465 //------------------------------------------------------------------------------
MDrv_MVD_SetIdctMode(MS_U32 u32Id,MS_U8 u8Mode)3466 MS_BOOL MDrv_MVD_SetIdctMode(MS_U32 u32Id, MS_U8 u8Mode)
3467 {
3468     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3469 
3470     return HAL_MVD_SetIdctMode(u8HalIdx, u8Mode);
3471 }
3472 
3473 //-----------------------------------------------------------------------------
3474 /// @brief \b Function \b Name: MDrv_MVD_EX_SetMVDClockSpeed()
3475 /// @brief \b Function \b Description:  set mvd clock speed
3476 /// @return - The result of setting mvd clock speed
3477 //-----------------------------------------------------------------------------
MDrv_MVD_EX_SetMVDClockSpeed(MVD_EX_ClockSpeed eClockSpeed)3478 E_MVD_Result MDrv_MVD_EX_SetMVDClockSpeed(MVD_EX_ClockSpeed eClockSpeed)
3479 {
3480     HAL_MVD_EX_ClockSpeed eMVDClockSpeed = E_HAL_MVD_EX_CLOCK_SPEED_NONE;
3481     switch (eClockSpeed)
3482     {
3483         case E_MVD_EX_CLOCK_SPEED_HIGHEST:
3484             eMVDClockSpeed = E_HAL_MVD_EX_CLOCK_SPEED_HIGHEST;
3485             break;
3486         case E_MVD_EX_CLOCK_SPEED_HIGH:
3487             eMVDClockSpeed = E_HAL_MVD_EX_CLOCK_SPEED_HIGH;
3488             break;
3489         case E_MVD_EX_CLOCK_SPEED_MEDIUM:
3490             eMVDClockSpeed = E_HAL_MVD_EX_CLOCK_SPEED_MEDIUM;
3491             break;
3492         case E_MVD_EX_CLOCK_SPEED_LOW:
3493             eMVDClockSpeed = E_HAL_MVD_EX_CLOCK_SPEED_LOW;
3494             break;
3495         case E_MVD_EX_CLOCK_SPEED_LOWEST:
3496             eMVDClockSpeed = E_HAL_MVD_EX_CLOCK_SPEED_LOWEST;
3497             break;
3498         case E_MVD_EX_CLOCK_SPEED_DEFAULT:
3499             eMVDClockSpeed = E_HAL_MVD_EX_CLOCK_SPEED_DEFAULT;
3500             break;
3501         default:
3502             MVD_DEBUGERROR(MVD_ERR("mvd clock setting is wrong(%d)\n", eClockSpeed));
3503             return E_MVD_RET_FAIL;
3504             break;
3505     }
3506 
3507     return HAL_MVD_EX_SetClockSpeed(eMVDClockSpeed);
3508 }
3509 
3510 
3511 //-----------------------------------------------------------------------------
3512 /// @brief \b Function \b Name: MDrv_MVD_HWBuffer_ReMappingMode()
3513 /// @brief \b Function \b Description:   Enable/ Disable to push first frame to display queue directly
3514 /// @param -bEnable \b IN :  Enable/ Disable
3515 ///                 -FALSE(0): disable this mode
3516 ///                 -TRUE(1): enable this mode
3517 /// @return -The result of command MDrv_MVD_HWBuffer_ReMappingMode
3518 //-----------------------------------------------------------------------------
MDrv_MVD_HWBuffer_ReMappingMode(MS_U32 u32Id,MS_BOOL bEnable)3519 E_MVD_Result MDrv_MVD_HWBuffer_ReMappingMode(MS_U32 u32Id,MS_BOOL bEnable)
3520 {
3521 
3522    E_MVD_Result eRet = E_MVD_RET_OK;
3523    MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3524 
3525    pMVDDrvContext->gMVDPreCtrl[u8HalIdx].bHWBufferReMapping = bEnable;
3526    eRet=HAL_MVD_HWBuffer_ReMappingMode(u8HalIdx,bEnable);
3527     return eRet;
3528 }
3529 
3530 
3531 //-----------------------------------------------------------------------------
3532 /// @brief \b Function \b Name: MDrv_MVD_ShowFirstFrameDirect()
3533 /// @brief \b Function \b Description:   Enable/ Disable to push first frame to display queue directly
3534 /// @param -bEnable \b IN :  Enable/ Disable
3535 ///                 -FALSE(0): disable this mode
3536 ///                 -TRUE(1): enable this mode
3537 /// @return -The result of command MDrv_MVD_ShowFirstFrameDirect
3538 //-----------------------------------------------------------------------------
MDrv_MVD_ShowFirstFrameDirect(MS_U32 u32Id,MS_BOOL bEnable)3539 MS_BOOL MDrv_MVD_ShowFirstFrameDirect(MS_U32 u32Id,MS_BOOL bEnable)
3540 {
3541     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3542 
3543     return HAL_MVD_ShowFirstFrameDirect(u8HalIdx, bEnable);
3544 }
3545 
3546 //------------------------------------------------------------------------------
3547 /// Set xc_low_delay parameter for xc_low_delay mechanism
3548 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
3549 //------------------------------------------------------------------------------
MDrv_MVD_SetXCLowDelayPara(MS_U32 u32Id,MS_U32 u32Para)3550 E_MVD_Result MDrv_MVD_SetXCLowDelayPara(MS_U32 u32Id,MS_U32 u32Para)
3551 {
3552     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3553 
3554     return HAL_MVD_SetXCLowDelayPara(u8HalIdx, u32Para);
3555 
3556 }
3557 
3558 //------------------------------------------------------------------------------
3559 /// Set self seqchange mode
3560 /// @param -bEnable \b IN : 0 for original seqchange, 1 for self seqchange
3561 /// @return -TRUE for success; FALSE for failure.
3562 //------------------------------------------------------------------------------
MDrv_MVD_SetSelfSeqChange(MS_U32 u32Id,MS_BOOL bEnable)3563 E_MVD_Result MDrv_MVD_SetSelfSeqChange(MS_U32 u32Id, MS_BOOL bEnable)
3564 {
3565     MS_U8 u8DrvIdx = _MVD_GET_IDX(u32Id);
3566     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3567     MS_BOOL ret;
3568 
3569     ret = HAL_MVD_EnableDynamicScale(u8HalIdx,bEnable);
3570 
3571     if(ret == TRUE)
3572     {
3573         pMVDDrvContext->bSelf_SeqChange[u8DrvIdx] = bEnable;
3574         return E_MVD_RET_OK;
3575     }
3576     else
3577     {
3578         return E_MVD_RET_FAIL;
3579     }
3580 }
3581 
3582 
3583 //------------------------------------------------------------------------------
3584 /// Set external DS buffer info.
3585 /// @param -pExternalBuf \b IN : External DS buffer info.
3586 /// @return -The result of setting external DS buffer
3587 //------------------------------------------------------------------------------
MDrv_MVD_SetExternalDSBuffer(MS_U32 u32Id,MVD_EX_ExternalDSBuf * pExternalBuf)3588 E_MVD_Result MDrv_MVD_SetExternalDSBuffer(MS_U32 u32Id, MVD_EX_ExternalDSBuf *pExternalBuf)
3589 {
3590 #define SIZE_3K 0xC00
3591     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3592     MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8HalIdx);
3593 
3594     //MS_U32 u32DrvAddr = NULL;
3595     if((pstMemCfg == NULL) || (pExternalBuf->u32DSBufSize < SIZE_3K)) /// DS buffer size need more than 3K (0xC00)
3596     {
3597         return E_MVD_RET_FAIL;
3598     }
3599 
3600 #if defined(CHIP_MONACO)
3601     if(VPU_FORCE_MIU_MODE == 1)
3602     {
3603         VPRINTF("this chip does not support set external DS buffer since VPU_FORCE_MIU_MODE == 1 !!\n");
3604         return E_MVD_RET_FAIL;
3605     }
3606 #endif
3607 
3608 #if (defined(CHIP_EDISON) || defined(CHIP_EINSTEIN) || defined(CHIP_NAPOLI) || defined(CHIP_MONACO))
3609     MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8HalIdx);
3610     MS_BOOL bRet = FALSE;
3611     MS_BOOL bExternalInMIU1 = FALSE;
3612     MS_VIRT u32DSAddr = pExternalBuf->u32DSBufAddr;
3613     MS_VIRT u32VPUAddr = NULL;
3614 
3615     if((pExternalBuf->u32DSBufAddr >= HAL_MVD_GetMiu1BaseAdd()) && (HAL_MVD_GetMiu1BaseAdd() != 0))
3616     {
3617         bExternalInMIU1 = TRUE;
3618         u32DSAddr -= HAL_MVD_GetMiu1BaseAdd();
3619     }
3620 
3621     /// If FW and external buf is in the same MIU, the External buffer do nothing.
3622     if(HAL_MVD_GetFWSelMiu1() == bExternalInMIU1)
3623     {
3624         u32VPUAddr = u32DSAddr;
3625     }
3626     else
3627     {
3628         /// If FW and external buf is not in the same MIU, the External buffer add the VPU Miu base size
3629         u32VPUAddr = u32DSAddr + HAL_VPU_EX_MIU1BASE();
3630     }
3631 
3632     ///VPRINTF("[EDS] VPU addr 0x%lx, drv addr 0x%lx, enable %d.\n",u32VPUAddr,pExternalBuf->u32DSBufAddr,pExternalBuf->bEnable);
3633     bRet = HAL_MVD_SetExternalDSBuff(u8HalIdx,u32VPUAddr,pExternalBuf->u32DSBufAddr);
3634 
3635     pstCtrlCfg->bExternalDSBuf = TRUE;
3636 
3637     if(bRet == TRUE)
3638     {
3639         return E_MVD_RET_OK;
3640     }
3641     else
3642     {
3643         return E_MVD_RET_FAIL;
3644     }
3645  #endif
3646 
3647     return E_MVD_RET_FAIL;
3648 }
3649 
MDrv_MVD_GetESBufferStatus(MS_U32 u32Id)3650 MS_U8 MDrv_MVD_GetESBufferStatus(MS_U32 u32Id)
3651 {
3652     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3653 
3654     return HAL_MVD_GetESBufferStatus(u8HalIdx);
3655 }
3656 
MDrv_MVD_Field_Polarity_Display_One_field(MS_U32 u32Id,MS_BOOL bEnable,MS_U8 top_bottom)3657 MS_BOOL MDrv_MVD_Field_Polarity_Display_One_field(MS_U32 u32Id, MS_BOOL bEnable,MS_U8 top_bottom)
3658 {
3659     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3660     return HAL_MVD_Field_Polarity_Display_One_field(u8HalIdx, bEnable,top_bottom);
3661 }
3662 
3663 
3664 //------------------------------------------------------------------------------
3665 /// set share memory base between driver and fw
3666 /// @return -TRUE for success; FALSE for failure.
3667 //------------------------------------------------------------------------------
MDrv_MVD_SetShareMemoryBase(MS_U32 u32Id,MS_VIRT u32base)3668 MS_BOOL MDrv_MVD_SetShareMemoryBase(MS_U32 u32Id, MS_VIRT u32base)
3669 {
3670     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3671 
3672     if((u32base & MVD_U32_MASK) == HAL_MIU1_BASE)
3673     {
3674         u32base -= HAL_MIU1_BASE;
3675         return HAL_MVD_SetShareMemoryBase(u8HalIdx, u32base,MIU_SEL_1); //in miu1
3676     }
3677     else
3678     {
3679         return HAL_MVD_SetShareMemoryBase(u8HalIdx, u32base,MIU_SEL_0); // in miu0
3680     }
3681 }
3682 
MDrv_MVD_GetShareMemoryOffset(MS_U32 u32Id,MS_VIRT * u32base)3683 MS_U32 MDrv_MVD_GetShareMemoryOffset(MS_U32 u32Id, MS_VIRT *u32base)
3684 {
3685     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3686     return HAL_MVD_GetShareMemoryOffset(u8HalIdx, u32base);
3687 }
3688 
MDrv_MVD_EnableVPUSecurityMode(MS_BOOL enable)3689 MS_BOOL MDrv_MVD_EnableVPUSecurityMode(MS_BOOL enable)
3690 {
3691     return HAL_VPU_EX_EnableSecurityMode(enable);
3692 }
3693 
MDrv_MVD_GetSupport2ndMVOPInterface(void)3694 MS_BOOL MDrv_MVD_GetSupport2ndMVOPInterface(void)
3695 {
3696     MVD_FUNC_ENTRY();
3697 
3698     return HAL_MVD_Support2ndMVOPInterface();
3699 }
3700 
MDrv_MVD_GetPVRSeamlessInfo(MS_U8 u8Idx,void * param)3701 MS_BOOL MDrv_MVD_GetPVRSeamlessInfo(MS_U8 u8Idx,void* param)
3702 {
3703     MVD_FUNC_ENTRY();
3704 
3705     return HAL_MVD_GetPVRSeamlessInfo(u8Idx,param);
3706 }
3707 
MDrv_MVD_REE_RegisterMBX(void)3708 MS_BOOL MDrv_MVD_REE_RegisterMBX(void)
3709 {
3710     return HAL_VPU_EX_REE_RegisterMBX();
3711 }
3712 
MDrv_MVD_REE_SetSHMBaseAddr(MS_U32 U32Type,MS_PHY u32SHMAddr,MS_PHY u32SHMSize,MS_PHY u32MIU1Addr)3713 MS_BOOL MDrv_MVD_REE_SetSHMBaseAddr(MS_U32 U32Type,MS_PHY u32SHMAddr,MS_PHY u32SHMSize,MS_PHY u32MIU1Addr)
3714 {
3715     return HAL_VPU_EX_REE_SetSHMBaseAddr(U32Type,u32SHMAddr,u32SHMSize,u32MIU1Addr);
3716 }
3717 
3718 //------------------------------------------------------------------------------
3719 /// set CC 608 or 708 share memory base between driver and fw
3720 /// @return -TRUE for success; FALSE for failure.
3721 //------------------------------------------------------------------------------
MDrv_MVD_SetExternal_CC608_Buffer(MS_U32 u32Id,MS_VIRT u32base,MS_U8 u8size)3722 MS_BOOL MDrv_MVD_SetExternal_CC608_Buffer(MS_U32 u32Id, MS_VIRT u32base,MS_U8 u8size)
3723 {
3724     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3725     return HAL_MVD_SetExternal_CC_Buffer(u8HalIdx,u32base,u8size,1);
3726 }
3727 
MDrv_MVD_SetExternal_CC708_Buffer(MS_U32 u32Id,MS_VIRT u32base,MS_U8 u8size)3728 MS_BOOL MDrv_MVD_SetExternal_CC708_Buffer(MS_U32 u32Id, MS_VIRT u32base,MS_U8 u8size)
3729 {
3730     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3731     return HAL_MVD_SetExternal_CC_Buffer(u8HalIdx,u32base,u8size,0);
3732 }
3733 
MDrv_MVD_SetPrebufferSize(MS_U32 u32Id,MS_U32 size)3734 MS_BOOL MDrv_MVD_SetPrebufferSize(MS_U32 u32Id, MS_U32 size)
3735 {
3736     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3737     return HAL_MVD_SetPrebufferSize(u8HalIdx,size);
3738 }
3739 
MDrv_MVD_REE_GetSHMInformation(MS_U32 u32Id,MS_VIRT * u32SHMAddr,MS_VIRT * u32VsyncSHMOffset)3740 void MDrv_MVD_REE_GetSHMInformation(MS_U32 u32Id, MS_VIRT* u32SHMAddr, MS_VIRT* u32VsyncSHMOffset)
3741 {
3742     *u32SHMAddr = HAL_VPU_EX_GetSHMAddr();
3743 
3744     #if defined(VDEC_FW30)
3745     *u32VsyncSHMOffset = HAL_MVD_GetVsyncAddrOffset();
3746     #elif defined(VDEC_FW31)
3747     *u32VsyncSHMOffset = HAL_VPU_EX_GetVsyncAddrOffset(u32Id);
3748     #else
3749     #error "controller.h should provide definition of VDEC_FW30 or VDEC_FW31"
3750     #endif
3751 }
3752 
MDrv_MVD_REE_GetVsyncExtShm(MS_U32 u32Id,MS_VIRT * u32SHMAddr,MS_VIRT * u32VsyncExtShmOffset)3753 E_MVD_Result MDrv_MVD_REE_GetVsyncExtShm(MS_U32 u32Id, MS_VIRT* u32SHMAddr, MS_VIRT* u32VsyncExtShmOffset)
3754 {
3755     *u32SHMAddr = HAL_VPU_EX_GetSHMAddr();
3756 
3757     #if defined(VDEC_FW30)
3758     *u32VsyncExtShmOffset = HAL_MVD_GetVsyncExtAddrOffset();
3759     #elif defined(VDEC_FW31)
3760     *u32VsyncExtShmOffset = HAL_VPU_EX_GetVsyncExtAddrOffset(u32Id);
3761     #else
3762     #error "controller.h should provide definition of VDEC_FW30 or VDEC_FW31"
3763     #endif
3764 
3765     if (0 == *u32VsyncExtShmOffset)
3766     {
3767         return E_MVD_RET_FAIL;
3768     }
3769 
3770     return E_MVD_RET_OK;
3771 }
3772 
3773 //------------------------------------------------------------------------------
3774 /// Set mvd/mpeg4 time_inc predict parameter...
3775 /// @param u32Para \b IN :
3776 ///          -Arg0(enable), 1 for enable, default is 0.
3777 ///          -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...
3778 ///          -Arg2(vop_time_incr_follow_vol_header), // 0 for follow vol_header...1 for bypass vol_header, default is 0...
3779 ///          -Arg3, reserve...
3780 /// @return -E_MVD_RET_OK for success; E_MVD_RET_FAIL for failure.
3781 //------------------------------------------------------------------------------
MDrv_MVD_SetTimeIncPredictParam(MS_U32 u32Id,MS_U32 u32Para)3782 E_MVD_Result MDrv_MVD_SetTimeIncPredictParam(MS_U32 u32Id,MS_U32 u32Para)
3783 {
3784 #if defined(CHIP_T2) || defined(CHIP_T7)
3785     return E_MVD_RET_FAIL;
3786 #else
3787     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3788     return HAL_MVD_SetTimeIncPredictParam(u8HalIdx,u32Para);
3789 #endif
3790 }
3791 
MDrv_MVD_SetDcodeTimeoutParam(MS_U32 u32Id,MS_BOOL enable,MS_U32 u32timeout)3792 MS_BOOL MDrv_MVD_SetDcodeTimeoutParam(MS_U32 u32Id,MS_BOOL enable,MS_U32 u32timeout)
3793 {
3794     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3795     return HAL_MVD_SetDecodeTimeoutParam(u8HalIdx,enable,u32timeout);
3796 }
3797 
MDrv_MVD_SetFramebufferAutoMode(MS_U32 u32Id,MS_BOOL bEnable)3798 MS_BOOL MDrv_MVD_SetFramebufferAutoMode(MS_U32 u32Id,MS_BOOL bEnable)
3799 {
3800     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3801     return _MVD_SetDynamicAllocateFB(u8HalIdx,bEnable);
3802 }
3803 
3804 //------------------------------------------------------------------------------
3805 /// set smooth rewind cmd to fw
3806 /// @return -TRUE for success; FALSE for failure.
3807 //------------------------------------------------------------------------------
MDrv_MVD_Set_Smooth_Rewind(MS_U32 u32Id,MS_U8 btype)3808 E_MVD_Result MDrv_MVD_Set_Smooth_Rewind(MS_U32 u32Id, MS_U8 btype)
3809 {
3810     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3811     return HAL_MVD_Set_Smooth_Rewind(u8HalIdx, btype);
3812 }
3813 
3814 //------------------------------------------------------------------------------
3815 /// get mvd is alive or not
3816 /// @return -TRUE for success; FALSE for failure.
3817 //------------------------------------------------------------------------------
3818 
MDrv_MVD_IsAlive(MS_U32 u32Id)3819 E_MVD_Result MDrv_MVD_IsAlive(MS_U32 u32Id)
3820 {
3821     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3822     return HAL_MVD_IsAlive(u8HalIdx);
3823 }
3824 
3825 //------------------------------------------------------------------------------
3826 /// enable/disable and set error tolerance value
3827 /// @return -TRUE for success; FALSE for failure.
3828 //------------------------------------------------------------------------------
MDrv_MVD_Set_Err_Tolerance(MS_U32 u32Id,MS_U16 u16Para)3829 E_MVD_Result MDrv_MVD_Set_Err_Tolerance(MS_U32 u32Id, MS_U16 u16Para)
3830 {
3831     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3832     return HAL_MVD_Set_Err_Tolerance(u8HalIdx,u16Para);
3833 }
3834 
3835 
3836 //------------------------------------------------------------------------------
3837 /// enable/disable Auto insert dummy pattern in SLQ mode
3838 /// @return -TRUE for success; FALSE for failure.
3839 //------------------------------------------------------------------------------
MDrv_MVD_EnableAutoInsertDummyPattern(MS_U32 u32Id,MS_BOOL bEnable)3840 void MDrv_MVD_EnableAutoInsertDummyPattern(MS_U32 u32Id, MS_BOOL bEnable)
3841 {
3842     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3843     return HAL_MVD_EnableAutoInsertDummyPattern(u8HalIdx,bEnable);
3844 }
3845 
MDrv_MVD_Drop_One_PTS(MS_U32 u32Id)3846 void MDrv_MVD_Drop_One_PTS(MS_U32 u32Id)
3847 {
3848     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3849     return HAL_MVD_Drop_One_PTS(u8HalIdx);
3850 }
MDrv_MVD_PVR_Seamless_mode(MS_U32 u32Id,MS_U8 u8Arg)3851 E_MVD_Result MDrv_MVD_PVR_Seamless_mode(MS_U32 u32Id, MS_U8 u8Arg)
3852 {
3853     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3854     return HAL_MVD_PVR_Seamless_mode(u8HalIdx,u8Arg);
3855 }
3856 
MDrv_MVD_SetDVXCShmAddr(MS_U32 u32Id,MS_PHY u32FWBaseAddr,MS_PHY u32DVXCShmAddr)3857 E_MVD_Result MDrv_MVD_SetDVXCShmAddr(MS_U32 u32Id, MS_PHY u32FWBaseAddr, MS_PHY u32DVXCShmAddr)
3858 {
3859     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3860     return HAL_MVD_SetDVXCShmAddr(u8HalIdx,u32FWBaseAddr,u32DVXCShmAddr);
3861 }
3862 
3863 
3864 // Please set it before cmd "CMD_ENABLE_LAST_FRAME_SHOW"
3865 // 0(default): for original just assert the last_frame_show_done when push to dispQ
3866 // 1: for strict qualify the last_frame_show_done after the last_frame been displayed by mvop, 20120309
MDrv_MVD_SetDispFinishMode(MS_U32 u32Id,MS_U8 u8Mode)3867 E_MVD_Result MDrv_MVD_SetDispFinishMode(MS_U32 u32Id,MS_U8 u8Mode)
3868 {
3869     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3870     return HAL_MVD_SetDisplayFinishMode(u8HalIdx,u8Mode);
3871 }
3872 
MDrv_MVD_Set_MBX_param(MS_U8 u8APIMbxMsgClass)3873 MS_BOOL MDrv_MVD_Set_MBX_param(MS_U8 u8APIMbxMsgClass)
3874 {
3875     return HAL_VPU_Set_MBX_param(u8APIMbxMsgClass);
3876 }
3877 
MDrv_MVD_SetDmxFrameRate(MS_U32 u32Id,MS_U32 u32Value)3878 void MDrv_MVD_SetDmxFrameRate(MS_U32 u32Id,MS_U32 u32Value)
3879 {
3880     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3881     HAL_MVD_SetDmxFrameRate(u8HalIdx,u32Value);
3882 }
3883 
MDrv_MVD_SetDmxFrameRateBase(MS_U32 u32Id,MS_U32 u32Value)3884 void MDrv_MVD_SetDmxFrameRateBase(MS_U32 u32Id,MS_U32 u32Value)
3885 {
3886     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3887     HAL_MVD_SetDmxFrameRateBase(u8HalIdx,u32Value);
3888 }
MDrv_MVD_Dynamic_FB_Mode(MS_BOOL bEnable,MS_PHY u32Address,MS_U32 u32Size)3889 void MDrv_MVD_Dynamic_FB_Mode(MS_BOOL bEnable,MS_PHY u32Address,MS_U32 u32Size)
3890 {
3891     HAL_VPU_EX_DynamicFBMode(bEnable,u32Address,u32Size);
3892 }
3893 
MDrv_MVD_SetCMAInformation(void * cmaInitParam)3894 void MDrv_MVD_SetCMAInformation(void* cmaInitParam)
3895 {
3896     pMVDDrvContext->bCMAUsed = TRUE;
3897     memcpy((void*)(&pMVDDrvContext->cmaInitParam),cmaInitParam,sizeof(struct CMA_Pool_Init_Param));
3898     HAL_MVD_SetCMAInformation(cmaInitParam);
3899 }
MDrv_MVD_ReleaseFreeStream(MS_U32 u32Id)3900 MS_BOOL MDrv_MVD_ReleaseFreeStream(MS_U32 u32Id)
3901 {
3902     MS_U8 u8HalIdx =_MVD_GET_IDX(u32Id);
3903     return HAL_VPU_EX_ReleaseFreeStream(u8HalIdx);
3904 }
3905 
3906 //------------------------------------------------------------------------------
3907 /// Enable FW PTS abnormal detect.
3908 /// @return -TRUE for success; FALSE for failure.
3909 //------------------------------------------------------------------------------
MDrv_MVD_EnablePTSDetector(MS_U32 u32Id,MS_BOOL bEn)3910 E_MVD_Result MDrv_MVD_EnablePTSDetector(MS_U32 u32Id, MS_BOOL bEn)
3911 {
3912     MVD_FUNC_ENTRY();
3913     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3914     return HAL_MVD_EnablePTSDetector(u8HalIdx, bEn);
3915 }
3916 
MDrv_MVD_SetAVSyncDispAutoDrop(MS_U32 u32Id,MS_BOOL bEnable)3917 MS_BOOL MDrv_MVD_SetAVSyncDispAutoDrop(MS_U32 u32Id,MS_BOOL bEnable)
3918 {
3919     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3920     return HAL_MVD_SetAVSyncDispAutoDrop(u8HalIdx,bEnable);
3921 }
3922 
MDrv_MVD_SetDynmcDispPath(MS_U32 u32Id,MS_BOOL bConnect,MVD_DISPLAY_PATH eValue,MS_BOOL bPreSet)3923 MS_BOOL MDrv_MVD_SetDynmcDispPath(MS_U32 u32Id,MS_BOOL bConnect,MVD_DISPLAY_PATH eValue,MS_BOOL bPreSet)
3924 {
3925     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3926     return HAL_MVD_SetDynmcDispPath(u8HalIdx,bConnect,eValue,bPreSet);
3927 }
3928 
MDrv_MVD_PreConnectInputTsp(MS_U32 u32Id,MS_BOOL bEnable,MVD_INPUT_TSP eInputTsp,MVD_Original_Stream eStream)3929 MS_BOOL MDrv_MVD_PreConnectInputTsp(MS_U32 u32Id, MS_BOOL bEnable, MVD_INPUT_TSP eInputTsp, MVD_Original_Stream eStream)
3930 {
3931     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3932     return HAL_MVD_PreConnectInputTsp(u8HalIdx, bEnable, eInputTsp, eStream);
3933 }
3934 
3935 //------------------------------------------------------------------------------
3936 /// Disable PB Frame Mode
3937 /// @return -TRUE for success; FALSE for failure.
3938 //------------------------------------------------------------------------------
MDrv_MVD_DisablePBFrameMode(MS_U32 u32Id,MS_BOOL bEn)3939 E_MVD_Result MDrv_MVD_DisablePBFrameMode(MS_U32 u32Id, MS_BOOL bEn)
3940 {
3941     MVD_FUNC_ENTRY();
3942     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3943     return HAL_MVD_DisablePBFrameMode(u8HalIdx, bEn);
3944 }
3945 
MDrv_MVD_CheckFreeStream(MVD_Original_Stream eStream)3946 MS_U8 MDrv_MVD_CheckFreeStream(MVD_Original_Stream eStream)
3947 {
3948     return HAL_VPU_EX_CheckFreeStream(eStream);
3949 }
3950 
MDrv_MVD_Set_SlowSyncParam(MS_U32 u32Id,MS_U8 u8RepeatPeriod,MS_U8 u8DropPeriod)3951 E_MVD_Result MDrv_MVD_Set_SlowSyncParam(MS_U32 u32Id, MS_U8 u8RepeatPeriod,MS_U8 u8DropPeriod)
3952 {
3953     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3954     return HAL_MVD_Set_SlowSyncParam(u8HalIdx,u8RepeatPeriod,u8DropPeriod);
3955 }
MDrv_MVD_VariableFrameRate(MS_U32 u32Id)3956 MS_BOOL MDrv_MVD_VariableFrameRate(MS_U32 u32Id)
3957 {
3958     MVD_FUNC_ENTRY();
3959     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3960     return HAL_MVD_VariableFrameRate(u8HalIdx);
3961 }
3962 
3963 //------------------------------------------------------------------------------
3964 /// Disable PB Frame Mode
3965 /// @return Min pre buffer size
3966 //------------------------------------------------------------------------------
MDrv_MVD_EX_GetMinTspDataSize(MS_U32 u32Id)3967 MS_U32 MDrv_MVD_EX_GetMinTspDataSize(MS_U32 u32Id)
3968 {
3969     MVD_FUNC_ENTRY();
3970     MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
3971     return HAL_MVD_GetMinTspDataSize(u8HalIdx);
3972 }
3973 
3974 #endif
3975