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