xref: /utopia/UTPA2-700.0.x/modules/pvr_iframelut/drv/pvr_iframelut/drvPVR_IframeLUT.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ///////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2010-2012 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ///////////////////////////////////////////////////////////////////////////////
94 
95 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// file    drvPVR_IframeLUT.c
98 /// @brief  Secure PVR Iframe LUT Driver Interface
99 /// @author MStar Semiconductor,Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101 
102 //-------------------------------------------------------------------------------------------------
103 //  Include Files
104 //-------------------------------------------------------------------------------------------------
105 
106 // Common Definition
107 #include "MsVersion.h"
108 #include "MsCommon.h"
109 #include "utopia.h"
110 #include "utopia_dapi.h"
111 
112 // Internal Definition
113 #include "asmCPU.h"
114 #include "drvMMIO.h"
115 #include "drvPVR_IframeLUT.h"
116 #include "drvPVR_IframeLUT_private.h"
117 #include "drvPVR_IframeLUT_v2.h"
118 #include "halPVR_IframeLUT.h"
119 
120 #ifdef MSOS_TYPE_LINUX
121     #include <sys/ioctl.h>
122     #include <unistd.h>
123     #include <fcntl.h> // O_RDWR
124 #endif
125 
126 #ifdef MSOS_TYPE_LINUX_KERNEL
127 #include <linux/string.h>
128 #endif
129 
130 //-------------------------------------------------------------------------------------------------
131 //  Local Compiler Options
132 //-------------------------------------------------------------------------------------------------
133 #if defined(CONFIG_PVR_IFRAMELUT_UTPA2_ENABLE)
134 #define PVR_IFRAMELUT_UTOPIA20 (1)
135 #else
136 #define PVR_IFRAMELUT_UTOPIA20 (0)
137 #endif
138 
139 //-------------------------------------------------------------------------------------------------
140 //  Local Defines
141 //-------------------------------------------------------------------------------------------------
142 #define PVR_IFRAMELUT_MUTEX_WAIT_TIME                     0xFFFFFFFFUL
143 
144 #define PVR_IFRAMELUT_DBGERR(_f,_a...)                    {if(_iframelutdbglevel >= E_PVR_IFRAMELUT_DBG_ERR) {printf(_f, ##_a);}}
145 #define PVR_IFRAMELUT_DBGINFO(_f,_a...)                   {if(_iframelutdbglevel >= E_PVR_IFRAMELUT_DBG_INFO){printf(_f, ##_a);}}
146 
147 #define PVR_IFRAMELUT_ASSERT(_bool)                        if(!(_bool))   \
148                                                            {              \
149                                                                if(_iframelutdbglevel >= E_PVR_IFRAMELUT_DBG_INFO)    \
150                                                                {  printf("[%s][%04d] ASSERT ERR\n", __FUNCTION__, __LINE__);  }         \
151                                                                return E_PVR_IFRAMELUT_FAIL;                          \
152                                                            }
153 
154 #define _PVR_IFRAMELUT_ENTRY()                             if(!MsOS_ObtainMutex(_lut_res->s32PVR_IframeLUTMutexId, PVR_IFRAMELUT_MUTEX_WAIT_TIME)) \
155                                                            {                                                                       \
156                                                                return E_PVR_IFRAMELUT_RESULT_FAIL;                                 \
157                                                            }
158 
159 #define _PVR_IFRAMELUT_RETURN(_ret)                        do{                                                                \
160                                                                MsOS_ReleaseMutex(_lut_res->s32PVR_IframeLUTMutexId);           \
161                                                                return _ret;                                                   \
162                                                            }while(0)
163 
164 //-------------------------------------------------------------------------------------------------
165 //  Local Structures
166 //-------------------------------------------------------------------------------------------------
167 typedef struct _PVR_IFRAMELUT_RESOURCE_PRIVATE
168 {
169     MS_S32 s32PVR_IframeLUTMutexId;
170     MS_BOOL bLUTBankInit;
171     MS_BOOL bLUTUsed[LUT_NUM];
172     MS_BOOL bSWInit;
173 } PVR_IFRAMELUT_RESOURCE_PRIVATE;
174 
175 //-------------------------------------------------------------------------------------------------
176 //  Global Variables
177 //-------------------------------------------------------------------------------------------------
178 #ifndef PVR_IFRAMELUT_UTOPIA20
179 static PVR_IFRAMELUT_RESOURCE_PRIVATE _tmp_res =
180 {
181     .s32PVR_IframeLUTMutexId = -1,
182     .bLUTBankInit = FALSE,
183     .bLUTUsed = {[0 ... (LUT_NUM-1)] = FALSE},
184     .bSWInit = TRUE
185 };
186 static PVR_IFRAMELUT_RESOURCE_PRIVATE *_lut_res = &_tmp_res;
187 #else
188 static PVR_IFRAMELUT_RESOURCE_PRIVATE *_lut_res = NULL;
189 #endif
190 
191 //-------------------------------------------------------------------------------------------------
192 //  Local Variables
193 //-------------------------------------------------------------------------------------------------
194 static EN_PVR_IFRAMELUT_DBGLEVEL _iframelutdbglevel = E_PVR_IFRAMELUT_DBG_INFO;
195 
196 #if PVR_IFRAMELUT_UTOPIA20
197 static void *_pInstantancePVRIframeLUT = NULL;
198 static void *_pAttributePVRIframeLUT = NULL;
199 #endif
200 
201 #if PVR_IFRAMELUT_UTOPIA20
_PVR_IframeLUT_UtopiaOpen(void)202 static MS_BOOL _PVR_IframeLUT_UtopiaOpen(void)
203 {
204     if(_pInstantancePVRIframeLUT == NULL)
205     {
206         // RegisterToUtopia will be called in Utopia.c
207         //PVR_IFRAMELUTRegisterToUtopia();
208 
209         #ifdef MSOS_TYPE_LINUX_KERNEL
210         PVR_IFRAMELUT_DBGINFO("[%s][%04d] Kernel Init\n", __FUNCTION__, __LINE__);
211         #else
212         PVR_IFRAMELUT_DBGINFO("[%s][%04d] User Init\n", __FUNCTION__, __LINE__);
213         #endif
214 
215         if(UtopiaOpen(MODULE_PVR_IFRAMELUT, &_pInstantancePVRIframeLUT, 0, _pAttributePVRIframeLUT) !=  UTOPIA_STATUS_SUCCESS)
216         {
217             PVR_IFRAMELUT_DBGERR("[%s][%04d] UtopiaOpen fail\n", __FUNCTION__, __LINE__);
218             return FALSE;
219         }
220 
221         PVR_IFRAMELUT_DBGINFO("[%s][%04d] _pInstantancePVRIframeLUT = %p\n", __FUNCTION__, __LINE__, _pInstantancePVRIframeLUT);
222     }
223     return TRUE;
224 }
225 #endif
226 
MDrv_PVR_IframeLUT_Init(void)227 EN_PVR_IFRAMELUT_RESULT MDrv_PVR_IframeLUT_Init(void)
228 {
229 #if PVR_IFRAMELUT_UTOPIA20
230     if(_pInstantancePVRIframeLUT == NULL)
231     {
232         _PVR_IframeLUT_UtopiaOpen();
233     }
234 
235     MS_U32 u32Ret = UtopiaIoctl(_pInstantancePVRIframeLUT, E_MDrv_CMD_PVR_IframeLUT_Init, NULL);
236     if(UTOPIA_STATUS_SUCCESS != u32Ret)
237     {
238         PVR_IFRAMELUT_DBGERR("[%s][%04d] UtopiaIoctl return value 0x%X\n", __FUNCTION__, __LINE__, (unsigned int)u32Ret);
239         return E_PVR_IFRAMELUT_RESULT_FAIL;
240     }
241     return E_PVR_IFRAMELUT_RESULT_OK;
242 #else
243     return _MDrv_PVR_IframeLUT_Init();
244 #endif
245 }
246 
MDrv_PVR_IframeLUT_Open(PVR_IFRAMELUT_Cfg * pstPVR_IframeLUTCfg)247 EN_PVR_IFRAMELUT_RESULT MDrv_PVR_IframeLUT_Open(PVR_IFRAMELUT_Cfg *pstPVR_IframeLUTCfg)
248 {
249 #if PVR_IFRAMELUT_UTOPIA20
250     if(_pInstantancePVRIframeLUT == NULL)
251     {
252         _PVR_IframeLUT_UtopiaOpen();
253     }
254 
255     PVR_IFRAMELUT_OPEN_PARAM *pArgs = pstPVR_IframeLUTCfg;
256 
257     MS_U32 u32Ret = UtopiaIoctl(_pInstantancePVRIframeLUT, E_MDrv_CMD_PVR_IframeLUT_Open, (void *)pArgs);
258     if(UTOPIA_STATUS_SUCCESS != u32Ret)
259     {
260         PVR_IFRAMELUT_DBGERR("[%s][%04d] UtopiaIoctl return value 0x%X\n", __FUNCTION__, __LINE__, (unsigned int)u32Ret);
261         return E_PVR_IFRAMELUT_RESULT_FAIL;
262     }
263     return E_PVR_IFRAMELUT_RESULT_OK;
264 #else
265     return _MDrv_PVR_IframeLUT_Open(pstPVR_IframeLUTCfg);
266 #endif
267 }
268 
MDrv_PVR_IframeLUT_SetVdecType(MS_U32 u32PvrEng,EN_PVR_IFRAMELUT_VDEC_TYPE eVdecType)269 EN_PVR_IFRAMELUT_RESULT MDrv_PVR_IframeLUT_SetVdecType(MS_U32 u32PvrEng, EN_PVR_IFRAMELUT_VDEC_TYPE eVdecType)
270 {
271 #if PVR_IFRAMELUT_UTOPIA20
272     if(_pInstantancePVRIframeLUT == NULL)
273     {
274         _PVR_IframeLUT_UtopiaOpen();
275     }
276 
277     PVR_IFRAMELUT_SETVDECTYPE_PARAM args;
278     args.u32PvrEng = u32PvrEng;
279     args.eVdecType = eVdecType;
280 
281     MS_U32 u32Ret = UtopiaIoctl(_pInstantancePVRIframeLUT, E_MDrv_CMD_PVR_IframeLUT_SetVdecType, (void *)&args);
282     if(UTOPIA_STATUS_SUCCESS != u32Ret)
283     {
284         PVR_IFRAMELUT_DBGERR("[%s][%04d] UtopiaIoctl return value 0x%X\n", __FUNCTION__, __LINE__, (unsigned int)u32Ret);
285         return E_PVR_IFRAMELUT_RESULT_FAIL;
286     }
287     return E_PVR_IFRAMELUT_RESULT_OK;
288 #else
289     return _MDrv_PVR_IframeLUT_SetVdecType(u32PvrEng, eVdecType);
290 #endif
291 }
292 
MDrv_PVR_IframeLUT_GetWritePtr(MS_U32 u32PvrEng,MS_U32 * pu32WritePtr)293 EN_PVR_IFRAMELUT_RESULT MDrv_PVR_IframeLUT_GetWritePtr(MS_U32 u32PvrEng, MS_U32 *pu32WritePtr)
294 {
295 #if PVR_IFRAMELUT_UTOPIA20
296     if(_pInstantancePVRIframeLUT == NULL)
297     {
298         _PVR_IframeLUT_UtopiaOpen();
299     }
300 
301     PVR_IFRAMELUT_GETWRITEPTR_PARAM args;
302     args.u32PvrEng = u32PvrEng;
303     args.pu32WritePtr = pu32WritePtr;
304 
305     MS_U32 u32Ret = UtopiaIoctl(_pInstantancePVRIframeLUT, E_MDrv_CMD_PVR_IframeLUT_GetWritePtr, (void *)&args);
306     if(UTOPIA_STATUS_SUCCESS != u32Ret)
307     {
308         PVR_IFRAMELUT_DBGERR("[%s][%04d] UtopiaIoctl return value 0x%X\n", __FUNCTION__, __LINE__, (unsigned int)u32Ret);
309         return E_PVR_IFRAMELUT_RESULT_FAIL;
310     }
311     return E_PVR_IFRAMELUT_RESULT_OK;
312 #else
313     return _MDrv_PVR_IframeLUT_GetWritePtr(u32PvrEng, pu32WritePtr);
314 #endif
315 }
316 
MDrv_PVR_IframeLUT_Close(MS_U32 u32PvrEng)317 EN_PVR_IFRAMELUT_RESULT MDrv_PVR_IframeLUT_Close(MS_U32 u32PvrEng)
318 {
319 #if PVR_IFRAMELUT_UTOPIA20
320     if(_pInstantancePVRIframeLUT == NULL)
321     {
322         _PVR_IframeLUT_UtopiaOpen();
323     }
324 
325     PVR_IFRAMELUT_CLOSE_PARAM args = u32PvrEng;
326 
327     MS_U32 u32Ret = UtopiaIoctl(_pInstantancePVRIframeLUT, E_MDrv_CMD_PVR_IframeLUT_Close, (void *)&args);
328     if(UTOPIA_STATUS_SUCCESS != u32Ret)
329     {
330         PVR_IFRAMELUT_DBGERR("[%s][%04d] UtopiaIoctl return value 0x%X\n", __FUNCTION__, __LINE__, (unsigned int)u32Ret);
331         return E_PVR_IFRAMELUT_RESULT_FAIL;
332     }
333     return E_PVR_IFRAMELUT_RESULT_OK;
334 #else
335     return _MDrv_PVR_IframeLUT_Close(u32PvrEng);
336 #endif
337 }
338 
MDrv_PVR_IframeLUT_Exit(void)339 EN_PVR_IFRAMELUT_RESULT MDrv_PVR_IframeLUT_Exit(void)
340 {
341 #if PVR_IFRAMELUT_UTOPIA20
342     if(_pInstantancePVRIframeLUT == NULL)
343     {
344         _PVR_IframeLUT_UtopiaOpen();
345     }
346 
347     MS_U32 u32Ret = UtopiaIoctl(_pInstantancePVRIframeLUT, E_MDrv_CMD_PVR_IframeLUT_Exit, NULL);
348     if(UTOPIA_STATUS_SUCCESS != u32Ret)
349     {
350         PVR_IFRAMELUT_DBGERR("[%s][%04d] UtopiaIoctl return value 0x%X\n", __FUNCTION__, __LINE__, (unsigned int)u32Ret);
351         return E_PVR_IFRAMELUT_RESULT_FAIL;
352     }
353     return E_PVR_IFRAMELUT_RESULT_OK;
354 #else
355     return _MDrv_PVR_IframeLUT_Exit();
356 #endif
357 }
358 
_MDrv_PVR_IframeLUT_Init(void)359 EN_PVR_IFRAMELUT_RESULT _MDrv_PVR_IframeLUT_Init(void)
360 {
361     PVR_IFRAMELUT_DBGINFO("[%s][%04d]\n", __FUNCTION__, __LINE__);
362 
363     // Set bank only once
364     if(!_lut_res->bLUTBankInit)
365     {
366         MS_VIRT u32Base;
367         MS_PHY u32Size;
368         MDrv_MMIO_Init();
369         if(FALSE == MDrv_MMIO_GetBASE(&u32Base, &u32Size, MS_MODULE_HW))
370         {
371             PVR_IFRAMELUT_DBGERR("[%s][%04d] Get MS_MODULE_PM fail\n", __FUNCTION__, __LINE__);
372             MS_ASSERT(0);
373         }
374 
375         // init LUT module
376         if(!HAL_PVR_IframeLUT_Init(u32Base))
377         {
378             PVR_IFRAMELUT_DBGERR("[%s][%04d] HAL_PVR_IframeLUT_Init fail 0x%08X\n", __FUNCTION__, __LINE__, u32Base);
379             return E_PVR_IFRAMELUT_RESULT_NOT_SUPPORT;
380         }
381 
382         // Create mutex if init LUT module success
383         if(_lut_res->s32PVR_IframeLUTMutexId == -1)
384         {
385             _lut_res->s32PVR_IframeLUTMutexId = MsOS_CreateMutex(E_MSOS_FIFO, "Mutex Iframe LUT", MSOS_PROCESS_SHARED);
386             if(_lut_res->s32PVR_IframeLUTMutexId == -1)
387             {
388                 PVR_IFRAMELUT_DBGERR("[%s][%04d] MsOS_CreateMutex failed", __FUNCTION__, __LINE__);
389                 return E_PVR_IFRAMELUT_RESULT_FAIL;
390             }
391         }
392 
393         _lut_res->bLUTBankInit = TRUE;
394 
395         PVR_IFRAMELUT_DBGINFO("[%s][%04d] Module set bank 0x%08X\n", __FUNCTION__, __LINE__, u32Base);
396         return E_PVR_IFRAMELUT_RESULT_OK;
397     }
398 
399     PVR_IFRAMELUT_DBGINFO("[%s][%04d] Module has been init once\n", __FUNCTION__, __LINE__);
400     return E_PVR_IFRAMELUT_RESULT_OK;
401 }
402 
_MDrv_PVR_IframeLUT_Open(PVR_IFRAMELUT_Cfg * pstPVR_IframeLUTCfg)403 EN_PVR_IFRAMELUT_RESULT _MDrv_PVR_IframeLUT_Open(PVR_IFRAMELUT_Cfg *pstPVR_IframeLUTCfg)
404 {
405     PVR_IFRAMELUT_DBGINFO("[%s][%04d]\n", __FUNCTION__, __LINE__);
406     _PVR_IFRAMELUT_ENTRY();
407 
408     if(_lut_res->bLUTUsed[pstPVR_IframeLUTCfg->u32PvrEng] == TRUE)
409     {
410         PVR_IFRAMELUT_DBGERR("[%s][%04d] LUT %d has been opened\n", __FUNCTION__, __LINE__, pstPVR_IframeLUTCfg->u32PvrEng);
411         _PVR_IFRAMELUT_RETURN(E_PVR_IFRAMELUT_RESULT_FAIL);
412     }
413 
414     if(!HAL_PVR_IframeLUT_Open(pstPVR_IframeLUTCfg->u32PvrEng, pstPVR_IframeLUTCfg->u32BufferStartAddr, pstPVR_IframeLUTCfg->u32BufferSize, pstPVR_IframeLUTCfg->eVdecType, 1))
415     {
416         PVR_IFRAMELUT_DBGERR("[%s][%04d] HAL_PVR_IframeLUT_Open fail\n", __FUNCTION__, __LINE__);
417         _PVR_IFRAMELUT_RETURN(E_PVR_IFRAMELUT_RESULT_FAIL);
418     }
419     _lut_res->bLUTUsed[pstPVR_IframeLUTCfg->u32PvrEng] = TRUE;
420     _PVR_IFRAMELUT_RETURN(E_PVR_IFRAMELUT_RESULT_OK);
421 }
422 
_MDrv_PVR_IframeLUT_SetVdecType(MS_U32 u32PvrEng,EN_PVR_IFRAMELUT_VDEC_TYPE eVdecType)423 EN_PVR_IFRAMELUT_RESULT _MDrv_PVR_IframeLUT_SetVdecType(MS_U32 u32PvrEng, EN_PVR_IFRAMELUT_VDEC_TYPE eVdecType)
424 {
425     PVR_IFRAMELUT_DBGINFO("[%s][%04d]\n", __FUNCTION__, __LINE__);
426 
427     _PVR_IFRAMELUT_ENTRY();
428 
429     PVR_IFRAMELUT_DBGINFO("[%s][%04d] PvrEng %d set vdec %d\n", __FUNCTION__, __LINE__, u32PvrEng, eVdecType);
430 
431     HAL_PVR_IframeLUT_VDEC_TYPE eHalVdecType;
432     switch(eVdecType)
433     {
434         case E_PVR_IFRAMELUT_VDEC_TYPE_MPEG:
435             eHalVdecType = E_HAL_PVR_IframeLUT_MPEG;
436             break;
437         case E_PVR_IFRAMELUT_VDEC_TYPE_H264:
438             eHalVdecType = E_HAL_PVR_IframeLUT_H264;
439             break;
440         case E_PVR_IFRAMELUT_VDEC_TYPE_HEVC:
441             eHalVdecType = E_HAL_PVR_IframeLUT_HEVC;
442             break;
443         case E_PVR_IFRAMELUT_VDEC_TYPE_AVS:
444             eHalVdecType = E_HAL_PVR_IframeLUT_AVS;
445             break;
446         default:
447             PVR_IFRAMELUT_DBGERR("[%s][%04d] Invalid Video Codec Type: %d\n", __FUNCTION__, __LINE__, eVdecType);
448             _PVR_IFRAMELUT_RETURN(E_PVR_IFRAMELUT_RESULT_INVALID_PARAM);
449     }
450     if(!HAL_PVR_IframeLUT_SetVdecType(u32PvrEng, eHalVdecType))
451     {
452         PVR_IFRAMELUT_DBGERR("[%s][%04d] HAL_PVR_IframeLUT_SetVdec fail\n", __FUNCTION__, __LINE__);
453         _PVR_IFRAMELUT_RETURN(E_PVR_IFRAMELUT_RESULT_FAIL);
454     }
455     _PVR_IFRAMELUT_RETURN(E_PVR_IFRAMELUT_RESULT_OK);
456 }
457 
_MDrv_PVR_IframeLUT_GetWritePtr(MS_U32 u32PvrEng,MS_U32 * pu32WritePtr)458 EN_PVR_IFRAMELUT_RESULT _MDrv_PVR_IframeLUT_GetWritePtr(MS_U32 u32PvrEng, MS_U32 *pu32WritePtr)
459 {
460     // Check if this PVR engine (LUT channel) is currently in use
461     if(_lut_res->bLUTUsed[u32PvrEng] == FALSE)
462     {
463         PVR_IFRAMELUT_DBGERR("[%s][%04d] PvrEng %d is not active!\n", __FUNCTION__, __LINE__, u32PvrEng);
464         return E_PVR_IFRAMELUT_RESULT_FAIL;
465     }
466 
467     *pu32WritePtr = HAL_PVR_IframeLUT_GetWritePtr(u32PvrEng);
468     if(*pu32WritePtr == 0)
469     {
470         PVR_IFRAMELUT_DBGERR("[%s][%04d] PvrEng %d get write ptr fail!\n", __FUNCTION__, __LINE__, u32PvrEng);
471         return E_PVR_IFRAMELUT_RESULT_FAIL;
472     }
473     PVR_IFRAMELUT_DBGINFO("[%s][%04d] PvrEng %d get write ptr 0x%08X\n", __FUNCTION__, __LINE__, u32PvrEng, *pu32WritePtr);
474     return E_PVR_IFRAMELUT_RESULT_OK;
475 }
476 
_MDrv_PVR_IframeLUT_Close(MS_U32 u32PvrEng)477 EN_PVR_IFRAMELUT_RESULT _MDrv_PVR_IframeLUT_Close(MS_U32 u32PvrEng)
478 {
479     PVR_IFRAMELUT_DBGINFO("[%s][%04d]\n", __FUNCTION__, __LINE__);
480     _PVR_IFRAMELUT_ENTRY();
481     if(!HAL_PVR_IframeLUT_Close(u32PvrEng))
482     {
483         PVR_IFRAMELUT_DBGERR("[%s][%04d] HAL_PVR_IframeLUT_Close fail\n", __FUNCTION__, __LINE__);
484         _PVR_IFRAMELUT_RETURN(E_PVR_IFRAMELUT_RESULT_FAIL);
485     }
486     _lut_res->bLUTUsed[u32PvrEng] = FALSE;
487     _PVR_IFRAMELUT_RETURN(E_PVR_IFRAMELUT_RESULT_OK);
488 }
489 
_MDrv_PVR_IframeLUT_Exit(void)490 EN_PVR_IFRAMELUT_RESULT _MDrv_PVR_IframeLUT_Exit(void)
491 {
492     PVR_IFRAMELUT_DBGINFO("[%s][%04d]\n", __FUNCTION__, __LINE__);
493     _PVR_IFRAMELUT_ENTRY();
494 
495     MS_U8 u8LUTIndex = 0;
496     for(u8LUTIndex = 0;u8LUTIndex < LUT_NUM;u8LUTIndex++)
497     {
498         if(_lut_res->bLUTUsed[u8LUTIndex] == TRUE)
499         {
500             PVR_IFRAMELUT_DBGINFO("[%s][%04d] LUT %u still in use\n", __FUNCTION__, __LINE__, u8LUTIndex);
501             _PVR_IFRAMELUT_RETURN(E_PVR_IFRAMELUT_RESULT_FAIL);
502         }
503     }
504 
505     if(!HAL_PVR_IframeLUT_Exit())
506     {
507         PVR_IFRAMELUT_DBGINFO("[%s][%04d] HAL_PVR_IframeLUT_Exit fail\n", __FUNCTION__, __LINE__);
508         _PVR_IFRAMELUT_RETURN(E_PVR_IFRAMELUT_RESULT_FAIL);
509     }
510 
511     for(u8LUTIndex = 0;u8LUTIndex < LUT_NUM;u8LUTIndex++)
512     {
513         _lut_res->bLUTUsed[u8LUTIndex] = FALSE;
514     }
515 
516     MsOS_ReleaseMutex(_lut_res->s32PVR_IframeLUTMutexId);
517     MsOS_DeleteMutex(_lut_res->s32PVR_IframeLUTMutexId);
518     _lut_res->s32PVR_IframeLUTMutexId = -1;
519     return E_PVR_IFRAMELUT_RESULT_OK;
520 }
521 
_MDrv_PVR_IframeLUT_GetCap(PVR_IFRAMELUT_QUERY_TYPE eQueryType,void * pOutput)522 EN_PVR_IFRAMELUT_RESULT _MDrv_PVR_IframeLUT_GetCap(PVR_IFRAMELUT_QUERY_TYPE eQueryType, void* pOutput)
523 {
524     if(eQueryType == PVR_IFRAMELUT_CAP_RESOURCE_SIZE)
525     {
526         *((MS_U32*)pOutput) = sizeof(PVR_IFRAMELUT_RESOURCE_PRIVATE);
527         return E_PVR_IFRAMELUT_RESULT_OK;
528     }
529     return E_PVR_IFRAMELUT_RESULT_FAIL;
530 }
531 
_MDrv_PVR_IframeLUT_InitResource(void * pResourceAddr)532 EN_PVR_IFRAMELUT_RESULT _MDrv_PVR_IframeLUT_InitResource(void *pResourceAddr)
533 {
534     _lut_res = (PVR_IFRAMELUT_RESOURCE_PRIVATE *)pResourceAddr;
535 
536     if(_lut_res->bSWInit != TRUE)
537     {
538         PVR_IFRAMELUT_DBGINFO("[%s][%04d] Init _lut_res\n", __FUNCTION__, __LINE__);
539         _lut_res->s32PVR_IframeLUTMutexId = -1;
540         _lut_res->bLUTBankInit = FALSE;
541         MS_U8 u8Index = 0;
542         for(u8Index = 0;u8Index < LUT_NUM;u8Index++)
543         {
544             _lut_res->bLUTUsed[u8Index] = FALSE;
545         }
546         _lut_res->bSWInit = TRUE;
547     }
548     else
549     {
550         PVR_IFRAMELUT_DBGINFO("[%s][%04d] Has Inited _lut_res\n", __FUNCTION__, __LINE__);
551     }
552     return E_PVR_IFRAMELUT_RESULT_OK;
553 }
554