xref: /utopia/UTPA2-700.0.x/modules/dms/hal/M7221/dms/halDMS.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) 2006-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // (��MStar Confidential Information��) by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94 
95 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// file    halDMS.c
98 /// @author MStar Semiconductor Inc.
99 /// @brief  DMS Utility HAL
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101 #define  HAL_DMS_C
102 
103 //-------------------------------------------------------------------------------------------------
104 //  Include Files
105 //-------------------------------------------------------------------------------------------------
106 // Common Definition
107 #ifdef MSOS_TYPE_LINUX_KERNEL
108 #include <linux/string.h>
109 #else
110 #include <stdlib.h>
111 #include <string.h>
112 #include <unistd.h>
113 #endif
114 
115 #include "MsCommon.h"
116 #include "MsVersion.h"
117 #include "drvMMIO.h"
118 //#include "apiDMS_Type.h"
119 #include "drvDMS.h"
120 #include "halDMS.h"
121 #include "UFO.h"
122 #include "apiPNL.h"
123 
124 #include "utopia.h"
125 #include "utopia_dapi.h"
126 #include "apiDMS_private.h"
127 
128 #ifndef ANDROID
129 #define DMS_PRINTF printf
130 #else
131 #include <sys/mman.h>
132 #include <cutils/ashmem.h>
133 #include <cutils/log.h>
134 
135 #define DMS_PRINTF ALOGD
136 #endif
137 
138 //-------------------------------------------------------------------------------------------------
139 //  Driver Compiler Options
140 //-------------------------------------------------------------------------------------------------
141 
142 //-------------------------------------------------------------------------------------------------
143 //  Local Defines
144 //-------------------------------------------------------------------------------------------------
145 #define REG_MEMSYNC_BLACK_MODE               (0x117E)
146 #define BIT_MEMSYNC_PIXEL_MASK_EN            (0x100)
147 #define BIT_MEMSYNC_MOTION_RATIO_MASK_EN     (0x200)
148 #define BIT_MEMSYNC_RESET                    (0x400)
149 #define BIT_MEMSYNC_DELAY_ONE_FRAME          (0x800)
150 #define BIT_MEMSYNC_DOTLINE                  (0x1000)
_DMS_XC_SetVideoMute_AutoSync(MS_BOOL bEnable)151 static MS_BOOL _DMS_XC_SetVideoMute_AutoSync(MS_BOOL bEnable)
152 {
153     E_APIXC_ReturnValue eXcRet;
154 
155     eXcRet = MApi_XC_GenerateBlackVideoByMode(bEnable, MAIN_WINDOW,E_XC_BLACK_VIDEO_MEMSYNC);
156     if(eXcRet != E_APIXC_RET_OK)
157     {
158         DMS_PRINTF("[%s][%d]MApi_XC_GenerateBlackVideoByMode fail:%d", __FUNCTION__, __LINE__, eXcRet);
159         return FALSE;
160     }
161     return TRUE;
162 }
163 
Hal_DMS_XC_SetMute(void * pInstance,MS_BOOL bEnable)164 MS_BOOL Hal_DMS_XC_SetMute(void* pInstance, MS_BOOL bEnable)
165 {
166     MS_BOOL bRet = FALSE;
167     MApi_XC_SkipWaitVsync(MAIN_WINDOW,TRUE);
168     bRet = _DMS_XC_SetVideoMute_AutoSync(bEnable);
169     MApi_XC_SkipWaitVsync(MAIN_WINDOW,FALSE);
170     return bRet;
171 }
172 
173 #define H_PostScalingRatio(Input, Output)          ((MS_U32)( ((MS_U64)(Input)) * 2097152ul / (Output) + 1 )/2)
174 #define V_PostScalingRatio(Input, Output)          ((MS_U32)( ((MS_U64)(Input) * 2097152ul) / Output + 1) / 2)
175 #define DMS_DS_DEPTH 0x8
176 #define DMS_DS_SET_COUNT 0x6
177 #define ALL_IP_COMMAND 0
178 extern void* g_pDMSRes;
179 
HAL_DMS_XC_DSSetConfig(void * pInstance)180 MS_BOOL HAL_DMS_XC_DSSetConfig(void* pInstance)
181 {
182     DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
183     UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
184     memset(&pDMSResPri->stHalDMS.stDMS_DSSWDB, 0 , sizeof(pDMSResPri->stHalDMS.stDMS_DSSWDB));
185     pDMSResPri->stHalDMS.phyDSAddr = MApi_XC_R4BYTE(0x1F22);
186     pDMSResPri->stHalDMS.phyDSAddr *= 0x20;
187     printf("Get DS Addr 0x%tx\n",(ptrdiff_t)pDMSResPri->stHalDMS.phyDSAddr);
188     // SC0_MCU_DS_AVAILABLE
189     //Set DS is out of DMS
190     #if 0
191     XC_DynamicScaling_Info stDSInfo;
192     stDSInfo.u32DS_Info_BaseAddr = gphy_DSAddr;
193     stDSInfo.bOP_DS_On           = 0;
194     stDSInfo.u8DS_Index_Depth    = DMS_DS_DEPTH;
195     stDSInfo.bOP_DS_On           = TRUE;
196     stDSInfo.bIPS_DS_On          = FALSE;
197     stDSInfo.bIPM_DS_On          = TRUE;
198     MApi_XC_SetDynamicScaling(&stDSInfo,sizeof(stDSInfo),MAIN_WINDOW);
199     #endif
200     #if ALL_IP_COMMAND
201     MApi_XC_W2BYTEMSK(0x1F26,0x10,0xFF);
202     #else
203     //MApi_XC_W2BYTEMSK(0x2032,0x0,0x300);
204     #endif
205     return TRUE;
206 }
207 
208 #define DS_CMD_LEN_64BITS                   8
209 #define BYTE_PER_WORD           (32)  // MIU 128: 16Byte/W, MIU 256: 32Byte/W
210 #define OP_BASE_OFFSET (2 * DMS_DS_SET_COUNT * DMS_DS_DEPTH * BYTE_PER_WORD)
Hal_DMS_ResetSWDSCommand(void * pInstance,MS_U8 u8DSIndex)211 void Hal_DMS_ResetSWDSCommand(void* pInstance, MS_U8 u8DSIndex)
212 {
213     DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
214     UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
215 
216 #if ALL_IP_COMMAND
217     MS_PHY u32IndexBase = pDMSResPri->stHalDMS.phyDSAddr + u8DSIndex * DMS_DS_DEPTH * 2 * BYTE_PER_WORD;
218 #else
219     MS_PHY u32IndexBase = pDMSResPri->stHalDMS.phyDSAddr + u8DSIndex * DMS_DS_DEPTH * BYTE_PER_WORD;
220     MS_PHY u32IndexBase_OP = u32IndexBase + OP_BASE_OFFSET;
221 #endif
222 
223     MS_U16 u16TotalCmdCnt = DMS_DS_DEPTH;
224     MS_U16 i = 0;
225 
226     MS_U64 *pu64Data = NULL;
227     u16TotalCmdCnt *= 2;
228     u16TotalCmdCnt *= 2;
229 
230     for(i = 0; i < u16TotalCmdCnt; i++)
231     {
232         pu64Data  = (MS_U64*)MsOS_PA2KSEG1(u32IndexBase + i*DS_CMD_LEN_64BITS);
233         *pu64Data = 0x00000009FFFF0000;
234     }
235 #if (ALL_IP_COMMAND == 0)
236     for(i = 0; i < u16TotalCmdCnt; i++)
237     {
238         pu64Data  = (MS_U64*)MsOS_PA2KSEG1(u32IndexBase_OP + i*DS_CMD_LEN_64BITS);
239         *pu64Data = 0x00000009FFFF0000;
240     }
241 #endif
242 }
243 
Hal_DMS_WriteSWDSCommand(void * pInstance,SCALER_WIN eWindow,MS_U32 u32CmdRegAddr,MS_U16 u16CmdRegValue,DMS_ds_reg_ip_op_sel IPOP_Sel,DMS_ds_reg_source_sel Source_Select,DMS_DS_CMDCNT * pstXC_DS_CmdCnt)244 void Hal_DMS_WriteSWDSCommand(void* pInstance, SCALER_WIN eWindow, MS_U32 u32CmdRegAddr, MS_U16 u16CmdRegValue, DMS_ds_reg_ip_op_sel IPOP_Sel, DMS_ds_reg_source_sel Source_Select, DMS_DS_CMDCNT *pstXC_DS_CmdCnt)
245 {
246     DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
247     UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
248 
249     if(pstXC_DS_CmdCnt->u16CMDCNT_IPM == 0 && pstXC_DS_CmdCnt->u16CMDCNT_OPM == 0)
250     {
251         Hal_DMS_ResetSWDSCommand(pInstance, pDMSResPri->stHalDMS.u8DSIndex);
252     }
253 #if ALL_IP_COMMAND
254     MS_PHY u32Addr = pDMSResPri->stHalDMS.phyDSAddr + pDMSResPri->stHalDMS.u8DSIndex * DMS_DS_DEPTH * 2 * BYTE_PER_WORD;
255 #else
256     MS_PHY u32Addr = pDMSResPri->stHalDMS.phyDSAddr + pDMSResPri->stHalDMS.u8DSIndex * DMS_DS_DEPTH * BYTE_PER_WORD;
257 #endif
258 
259     //XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] u32DynamicScalingBaseAddr:%x  CurIdx:%d  IdxDepth:%d  BYTE_PER_WORD:%d  \n",__func__,__LINE__,(int)pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr,(int)pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex[eWindow],(int)pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth,(int)BYTE_PER_WORD);
260     //XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] u32Addr:%x  \n",__func__,__LINE__,(int)u32Addr);
261 
262     MS_U64 *pu64Data = NULL;
263     MS_U64 u64CmdTemp = 0;
264     MS_U8  u8AddrTemp = 0;
265     MS_U16 u16BankTemp = 0;
266     MS_U16 u16DataTemp = 0;
267     MS_U16 u16MaskTemp = 0;
268     MS_U8 u8MaxCmdCnt = DMS_DS_DEPTH * 2;
269 #if ALL_IP_COMMAND
270     u8MaxCmdCnt *= 2;
271 #endif
272 
273     if(Source_Select == DMS_DS_XC)
274     {
275         u16MaskTemp = 0xFFFF;
276         u16DataTemp = u16CmdRegValue;
277 
278         u8AddrTemp= (u32CmdRegAddr & 0x000000FF) >> 1;
279         u16BankTemp= 0x1300 | ((u32CmdRegAddr >> 8) & 0x000000FF); // 0x13XX xc sread mode address
280 
281         u64CmdTemp|= (MS_U64)u16DataTemp;
282         u64CmdTemp|= ((MS_U64)u8AddrTemp<<16);
283         u64CmdTemp|= ((MS_U64)u16BankTemp<<23);
284         u64CmdTemp|= ((MS_U64)u16MaskTemp<<48);
285 
286         if(IPOP_Sel == DS_IP)
287         {
288             if(eWindow == MAIN_WINDOW)
289             {
290                 MS_U32 u32MemShift_IPM;
291 
292                 if((pstXC_DS_CmdCnt->u16CMDCNT_IPM % 2) == 0)
293                 {
294                     u32MemShift_IPM = (pstXC_DS_CmdCnt->u16CMDCNT_IPM / 2) * BYTE_PER_WORD;
295                 }
296                 else
297                 {
298                     u32MemShift_IPM = (pstXC_DS_CmdCnt->u16CMDCNT_IPM / 2) * BYTE_PER_WORD  + DS_CMD_LEN_64BITS;
299                 }
300                 //XC_PRINTF("[%s,%5d] [DS_IP]pstXC_DS_CmdCnt->u16CMDCNT_IPM:%d u32MemShift_IPM:%lx \n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPM,(MS_U32)u32MemShift_IPM);
301                 //u32Addr = u32Addr + DS_CMD_LEN_64BITS * pstXC_DS_CmdCnt->u16CMDCNT_IPM;
302                 u32Addr = u32Addr + u32MemShift_IPM;
303                 if(0)//u32Addr == 0x11956200)
304                 {
305                     printf("[%s] addr 0x%llx, 0x%llx\n",__FUNCTION__,*((MS_U64*)MsOS_PA2KSEG1(0x11956200)),u64CmdTemp);
306                 }
307 
308                 pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr);//IPM
309 
310                 if(pstXC_DS_CmdCnt->u16CMDCNT_IPM < u8MaxCmdCnt)
311                 {
312                     *pu64Data = u64CmdTemp;
313                     pstXC_DS_CmdCnt->u16CMDCNT_IPM++;
314                 }
315                 else
316                 {
317                     printf("[%s,%5d] [DS] IPM Command count overflow !!  u16CMDCNT_IPM:%d  Max command count: %d\n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPM,DMS_DS_DEPTH * 2);
318                 }
319             }
320         }
321         else
322         {
323             if(eWindow == MAIN_WINDOW)
324             {
325                 MS_U32 u32MemShift_OPM;
326 
327                 if((pstXC_DS_CmdCnt->u16CMDCNT_OPM % 2) == 0)
328                 {
329                     u32MemShift_OPM = (pstXC_DS_CmdCnt->u16CMDCNT_OPM / 2) * BYTE_PER_WORD;
330                 }
331                 else
332                 {
333                     u32MemShift_OPM = (pstXC_DS_CmdCnt->u16CMDCNT_OPM / 2) * BYTE_PER_WORD  + DS_CMD_LEN_64BITS;
334                 }
335                 //XC_PRINTF("[%s,%5d] [DS_IP]pstXC_DS_CmdCnt->u16CMDCNT_IPM:%d u32MemShift_IPM:%lx \n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPM,(MS_U32)u32MemShift_IPM);
336                 //u32Addr = u32Addr + DS_CMD_LEN_64BITS * pstXC_DS_CmdCnt->u16CMDCNT_IPM;
337                 u32Addr = u32Addr + u32MemShift_OPM + OP_BASE_OFFSET;
338                 pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr);//IPM
339 
340                 if(pstXC_DS_CmdCnt->u16CMDCNT_OPM < u8MaxCmdCnt)
341                 {
342                     *pu64Data = u64CmdTemp;
343                     pstXC_DS_CmdCnt->u16CMDCNT_OPM++;
344                 }
345                 else
346                 {
347                     printf("[%s,%5d] [DS] OPM Command count overflow !!  u16CMDCNT_OPM:%d  Max command count: %d\n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_OPM,DMS_DS_DEPTH * 2);
348                 }
349             }
350         }
351     }
352     else if(Source_Select == DMS_DS_MVOP)// only in IP cmd
353     {
354         u16DataTemp = u16CmdRegValue;
355         u8AddrTemp = (u32CmdRegAddr&0x000000FF);
356         u16BankTemp = (u32CmdRegAddr&0x00FFFF00) >> 8; //EX: mvop mainwinodw: 0x1014 mvop bank
357         u16MaskTemp = 0xFFFF;
358 
359         u64CmdTemp|= (MS_U64)u16DataTemp;
360         u64CmdTemp|= ((MS_U64)u8AddrTemp<<16);
361         u64CmdTemp|= ((MS_U64)u16BankTemp<<23);
362         u64CmdTemp|= ((MS_U64)u16MaskTemp<<48);
363 
364         if(eWindow == MAIN_WINDOW)
365         {
366             MS_U32 u32MemShift_IPM;
367 
368             if((pstXC_DS_CmdCnt->u16CMDCNT_IPM % 2) == 0)
369             {
370                 u32MemShift_IPM = (pstXC_DS_CmdCnt->u16CMDCNT_IPM / 2) * BYTE_PER_WORD;
371             }
372             else
373             {
374                 u32MemShift_IPM = (pstXC_DS_CmdCnt->u16CMDCNT_IPM / 2) * BYTE_PER_WORD  + DS_CMD_LEN_64BITS;
375             }
376             //XC_PRINTF("[%s,%5d] [DS_IP(MVOP)]pstXC_DS_CmdCnt->u16CMDCNT_IPM:%d u32MemShift_IPM:%lx \n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPM,(MS_U32)u32MemShift_IPM);
377             //u32Addr = u32Addr + DS_CMD_LEN_64BITS * pstXC_DS_CmdCnt->u16CMDCNT_IPM;
378             u32Addr = u32Addr + u32MemShift_IPM;
379             pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr);//IPM
380 
381             if(pstXC_DS_CmdCnt->u16CMDCNT_IPM < u8MaxCmdCnt)
382             {
383                 *pu64Data = u64CmdTemp;
384                 pstXC_DS_CmdCnt->u16CMDCNT_IPM++;
385             }
386             else
387             {
388                 printf("[%s,%5d] [DS] Command count overflow !!  u16CMDCNT_IPM:%d  Max command count: %d\n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPM,DMS_DS_DEPTH * 2);
389             }
390         }
391     }
392     else
393     {
394         printf("[%s,%5d] [DS] Only can support XC/MVOP/GOP NOW !! \n",__func__,__LINE__);
395     }
396 
397 }
398 
Hal_DMS_Add_NullCommand(void * pInstance,SCALER_WIN eWindow,DMS_ds_reg_ip_op_sel IPOP_Sel,DMS_DS_CMDCNT * pstXC_DS_CmdCnt)399 void Hal_DMS_Add_NullCommand(void* pInstance, SCALER_WIN eWindow, DMS_ds_reg_ip_op_sel IPOP_Sel, DMS_DS_CMDCNT *pstXC_DS_CmdCnt)
400 {
401     DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
402     UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
403 
404     MS_U16 u16MaxCmdCnt = DMS_DS_DEPTH * 2; // It has two 64bit commands per MIU bus width
405     MS_U64 *pu64Data = NULL;
406     MS_U16 i;
407 #if ALL_IP_COMMAND
408     u16MaxCmdCnt *= 2;
409 #endif
410 
411     if(eWindow == MAIN_WINDOW)
412     {
413         if(IPOP_Sel == DS_IP)
414         {
415             for(i=pstXC_DS_CmdCnt->u16CMDCNT_IPM;i<u16MaxCmdCnt;i++)
416             {
417                 MS_PHY u32IndexBase= (pDMSResPri->stHalDMS.phyDSAddr +
418                     (MS_U32)pDMSResPri->stHalDMS.u8DSIndex * u16MaxCmdCnt * BYTE_PER_WORD +
419                     (i / 2) * BYTE_PER_WORD + (i % 2) * DS_CMD_LEN_64BITS);
420                 pu64Data  = (MS_U64*)MsOS_PA2KSEG1(u32IndexBase);
421                 *pu64Data = 0x00000009FFFF0000;
422             }
423         }
424 #if (ALL_IP_COMMAND == 0)
425         else
426         {
427             for(i=pstXC_DS_CmdCnt->u16CMDCNT_OPM;i<u16MaxCmdCnt;i++)
428             {
429                 MS_PHY u32IndexBase= (pDMSResPri->stHalDMS.phyDSAddr + OP_BASE_OFFSET +
430                     (MS_U32)pDMSResPri->stHalDMS.u8DSIndex * u16MaxCmdCnt * BYTE_PER_WORD +
431                     (i / 2) * BYTE_PER_WORD + (i % 2) * DS_CMD_LEN_64BITS);
432                 pu64Data  = (MS_U64*)MsOS_PA2KSEG1(u32IndexBase);
433                 *pu64Data = 0x00000009FFFF0000;
434             }
435         }
436 #endif
437     }
438 }
439 
HAL_DMS_XC_DSSetWin(void * pInstance,MS_WINDOW_TYPE * stMVOPCropWindow,const XC_SETWIN_INFO * stXCSetWinInfo,MS_U32 u32FlowFlag)440 MS_BOOL HAL_DMS_XC_DSSetWin(void* pInstance, MS_WINDOW_TYPE* stMVOPCropWindow, const XC_SETWIN_INFO* stXCSetWinInfo, MS_U32 u32FlowFlag)
441 {
442     DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
443     UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
444 
445     MS_U32 u32HRatio = 0;
446     MS_U32 u32VRatio = 0;
447     //printf("[%s] Post: %d -> %d, %d -> %d, flow %d\n",__FUNCTION__,stXCSetWinInfo->u16HCusScalingSrc,stXCSetWinInfo->u16HCusScalingDst,
448     //    stXCSetWinInfo->u16VCusScalingSrc,stXCSetWinInfo->u16VCusScalingDst,u32FlowFlag);
449 
450     if(stXCSetWinInfo->u16HCusScalingSrc != stXCSetWinInfo->u16HCusScalingDst)
451     {
452         u32HRatio = H_PostScalingRatio(stXCSetWinInfo->u16HCusScalingSrc, stXCSetWinInfo->u16HCusScalingDst);
453         u32HRatio &= 0x0FFFFFF;
454         u32HRatio |= 0x1000000;
455     }
456 
457     if(stXCSetWinInfo->u16VCusScalingSrc != stXCSetWinInfo->u16VCusScalingDst)
458     {
459         u32VRatio = V_PostScalingRatio(stXCSetWinInfo->u16VCusScalingSrc, stXCSetWinInfo->u16VCusScalingDst);
460         u32VRatio &= 0x00FFFFFF;
461         u32VRatio |= 0x81000000;
462     }
463 
464     pDMSResPri->stHalDMS.stDMS_DSSWDB.u32FlowFlag = u32FlowFlag;
465     pDMSResPri->stHalDMS.stDMS_DSSWDB.u32HPostRatio = u32HRatio;
466     pDMSResPri->stHalDMS.stDMS_DSSWDB.u32VPostRatio = u32VRatio;
467 
468     if(1)//u32FlowFlag == 1)
469     {
470         //from DIP need display window
471         pDMSResPri->stHalDMS.stDMS_DSSWDB.u16H_Start = g_IPanel.HStart() + stXCSetWinInfo->stDispWin.x;
472         pDMSResPri->stHalDMS.stDMS_DSSWDB.u16H_End   = pDMSResPri->stHalDMS.stDMS_DSSWDB.u16H_Start + stXCSetWinInfo->stDispWin.width - 1;
473         pDMSResPri->stHalDMS.stDMS_DSSWDB.u16V_Start = stXCSetWinInfo->stDispWin.y;
474         pDMSResPri->stHalDMS.stDMS_DSSWDB.u16V_End   = pDMSResPri->stHalDMS.stDMS_DSSWDB.u16V_Start + stXCSetWinInfo->stDispWin.height - 1;
475     }
476 
477     pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.x = stMVOPCropWindow->x;
478     pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.y = stMVOPCropWindow->y;
479     pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.width = stMVOPCropWindow->width;
480     pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.height = stMVOPCropWindow->height;
481     //printf("[%s] MVOP: %d %d, %d %d\n",__FUNCTION__,gDMS_DSSWDB.stMVOPCropWindow.x,gDMS_DSSWDB.stMVOPCropWindow.y,gDMS_DSSWDB.stMVOPCropWindow.width,gDMS_DSSWDB.stMVOPCropWindow.height);
482     //printf("[%s] Disp: %d %d, %d %d\n",__FUNCTION__,gDMS_DSSWDB.u16H_Start,gDMS_DSSWDB.u16H_End,gDMS_DSSWDB.u16V_Start,gDMS_DSSWDB.u16V_End);
483     //printf("[%s] H:0x%x , V:0x%x\n",__FUNCTION__,gDMS_DSSWDB.u32HPostRatio,gDMS_DSSWDB.u32VPostRatio);
484 
485     return TRUE;
486 }
487 
HAL_DMS_XC_DSSetMVOPPitch(void * pInstance,MS_U16 u16Pitch)488 MS_BOOL HAL_DMS_XC_DSSetMVOPPitch(void* pInstance, MS_U16 u16Pitch)
489 {
490     DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
491     UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
492 
493     pDMSResPri->stHalDMS.stDMS_DSSWDB.u16MVOP_Pitch = u16Pitch;
494     printf("[%s] Pitch: %d\n",__FUNCTION__,pDMSResPri->stHalDMS.stDMS_DSSWDB.u16MVOP_Pitch);
495     return TRUE;
496 }
497 
HAL_DMS_XC_DSSetMVOPAddr(void * pInstance,MS_PHY phyLumaAddr,MS_PHY phyChromaAddr,MS_BOOL b422Pack)498 MS_BOOL HAL_DMS_XC_DSSetMVOPAddr(void* pInstance, MS_PHY phyLumaAddr, MS_PHY phyChromaAddr, MS_BOOL b422Pack)
499 {
500     DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
501     UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
502 
503     pDMSResPri->stHalDMS.stDMS_DSSWDB.bMVOP_422Pack = b422Pack;
504     pDMSResPri->stHalDMS.stDMS_DSSWDB.phyMVOP_LumaAddr = phyLumaAddr;
505     pDMSResPri->stHalDMS.stDMS_DSSWDB.phyMVOP_ChromaAddr = phyChromaAddr;
506     return TRUE;
507 }
508 
509 #define MI_FLOW_PATCH 1
510 extern MS_U16 gDMSMVOPForceLookVDEC;
HAL_DMS_XC_DSFire(void * pInstance)511 MS_BOOL HAL_DMS_XC_DSFire(void* pInstance)
512 {
513     DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
514     UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
515 
516 #if (ALL_IP_COMMAND == 0)
517     if(MApi_XC_R2BYTEMSK(0x0006,0x1000))
518     {
519         MApi_XC_W2BYTEMSK(0x0006,0,0x1000);
520     }
521 #endif
522 
523 #if MI_FLOW_PATCH
524 //This Patch for FBL W/R diff need to be 0
525     if(MApi_XC_R2BYTEMSK(0x120E,0xF000))
526     {
527         MApi_XC_W2BYTEMSK(0x120E,0,0xF000);
528     }
529 //This Patch for FBL W/R must disable
530     if(MApi_XC_R2BYTEMSK(0x120E,0x0003) != 3)
531     {
532         MApi_XC_W2BYTEMSK(0x120E,0x0003,0x0003);
533     }
534 //This Patch for FBL DataFormat can not set
535     if(MApi_XC_R2BYTEMSK(0x1202,0x2F00))
536     {
537         MApi_XC_W2BYTEMSK(0x1202,0,0x2F00);
538     }
539 //This Patch for FBL do not need miu write size protect
540     if(MApi_XC_R2BYTEMSK(0x1230,0x8000))
541     {
542         MApi_XC_W2BYTEMSK(0x1230,0,0x8000);
543     }
544 
545 #endif
546 
547     DMS_DS_CMDCNT STXC_DS_CMDCNT;
548     STXC_DS_CMDCNT.u16CMDCNT_IPM =0;
549     STXC_DS_CMDCNT.u16CMDCNT_IPS =0;
550     STXC_DS_CMDCNT.u16CMDCNT_OPM =0;
551     STXC_DS_CMDCNT.u16CMDCNT_OPS =0;
552     //printf("[%s] MVOP: %d %d, %d %d\n",__FUNCTION__,gDMS_DSSWDB.stMVOPCropWindow.x,gDMS_DSSWDB.stMVOPCropWindow.y,gDMS_DSSWDB.stMVOPCropWindow.width,gDMS_DSSWDB.stMVOPCropWindow.height);
553     //printf("[%s] Disp: %d %d, %d %d\n",__FUNCTION__,gDMS_DSSWDB.u16H_Start,gDMS_DSSWDB.u16H_End,gDMS_DSSWDB.u16V_Start,gDMS_DSSWDB.u16V_End);
554     //printf("[%s] Pitch: %d\n",__FUNCTION__,gDMS_DSSWDB.u16MVOP_Pitch);
555     //printf("[%s] H:0x%x , V:0x%x\n",__FUNCTION__,gDMS_DSSWDB.u32HPostRatio,gDMS_DSSWDB.u32VPostRatio);
556 
557 #if ALL_IP_COMMAND
558     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1010, pDMSResPri->stHalDMS.stDMS_DSSWDB.u16H_Start, DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
559     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1012, pDMSResPri->stHalDMS.stDMS_DSSWDB.u16H_End, DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
560     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1014, pDMSResPri->stHalDMS.stDMS_DSSWDB.u16V_Start, DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
561     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1016, pDMSResPri->stHalDMS.stDMS_DSSWDB.u16V_End, DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
562 
563     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x230E, pDMSResPri->stHalDMS.stDMS_DSSWDB.u32HPostRatio & 0xFFFF          , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
564     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x2310, (pDMSResPri->stHalDMS.stDMS_DSSWDB.u32HPostRatio >> 16) & 0xFFFF  , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
565     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x2312, pDMSResPri->stHalDMS.stDMS_DSSWDB.u32VPostRatio & 0xFFFF          , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
566     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x2314, (pDMSResPri->stHalDMS.stDMS_DSSWDB.u32VPostRatio >> 16) & 0xFFFF  , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
567 
568     //Disable pre scaling for pre scaling be set out of DMS
569     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x0210, 0 , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
570     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x0212, 0 , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
571     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x0208, 0 , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
572     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x020A, 0 , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
573 
574     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x202A, pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.height & 0x0FFF  , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
575 
576 #else
577     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1010, pDMSResPri->stHalDMS.stDMS_DSSWDB.u16H_Start, DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
578     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1012, pDMSResPri->stHalDMS.stDMS_DSSWDB.u16H_End, DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
579     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1014, pDMSResPri->stHalDMS.stDMS_DSSWDB.u16V_Start, DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
580     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1016, pDMSResPri->stHalDMS.stDMS_DSSWDB.u16V_End, DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
581 
582     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x230E, pDMSResPri->stHalDMS.stDMS_DSSWDB.u32HPostRatio & 0xFFFF          , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
583     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x2310, (pDMSResPri->stHalDMS.stDMS_DSSWDB.u32HPostRatio >> 16) & 0xFFFF  , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
584     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x2312, pDMSResPri->stHalDMS.stDMS_DSSWDB.u32VPostRatio & 0xFFFF          , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
585     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x2314, (pDMSResPri->stHalDMS.stDMS_DSSWDB.u32VPostRatio >> 16) & 0xFFFF  , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
586 
587     //Disable pre scaling for pre scaling be set out of DMS
588     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x0210, 0 , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
589     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x0212, 0 , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
590     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x0208, 0 , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
591     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x020A, 0 , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
592 
593     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x202A, pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.height & 0x0FFF  , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
594 #if MI_FLOW_PATCH
595 //This Patch for keep ipm/opm fetch to max size
596     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x121E, 0x1000 , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
597     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x122E, 0x1000 , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
598 #endif
599 
600 #endif
601 
602     MS_U16 u16MVOPForceWrite = MApi_XC_ReadByte(0x10144E);
603     u16MVOPForceWrite |= 0x10;
604     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101427, u16MVOPForceWrite    , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
605     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101440, pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.x  , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
606     if(pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.y == 0)
607     {
608         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101441, (pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.y | 0xE000), DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
609     }
610     else
611     {
612         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101441, (pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.y | 0xA000), DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
613     }
614     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101442, pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.width    , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
615     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101443, pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.height   , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
616 
617     if(1)//gDMS_DSSWDB.u32FlowFlag == 1)
618     {
619         MS_PHY phyAddr = pDMSResPri->stHalDMS.stDMS_DSSWDB.phyMVOP_LumaAddr >> 3;
620         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101421, phyAddr & 0xFFFF           , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
621         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101422, (phyAddr >> 16) & 0x1FFF  , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
622         if(pDMSResPri->stHalDMS.stDMS_DSSWDB.bMVOP_422Pack)
623         {
624             phyAddr = pDMSResPri->stHalDMS.stDMS_DSSWDB.phyMVOP_LumaAddr + 16;
625         }
626         else
627         {
628             phyAddr = pDMSResPri->stHalDMS.stDMS_DSSWDB.phyMVOP_ChromaAddr;
629         }
630         phyAddr = phyAddr >> 3;
631         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101423, phyAddr & 0xFFFF           , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
632         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101424, (phyAddr >> 16) & 0x1FFF  , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
633     }
634 
635 //Pitch & Tile
636     MS_U8 u8MVOPCtrl0_H = MApi_XC_ReadByte(0x101441);
637     MS_U8 u8MVOPCtrl0_L = MApi_XC_ReadByte(0x101440);
638     MS_U8 u8MVOPPitch_L = MApi_XC_ReadByte(0x101430);
639     u8MVOPPitch_L = (u8MVOPPitch_L & (0xFF - 0x03)) | ((pDMSResPri->stHalDMS.stDMS_DSSWDB.u16MVOP_Pitch >> 8) & 0x03);
640     u8MVOPCtrl0_H = (pDMSResPri->stHalDMS.stDMS_DSSWDB.u16MVOP_Pitch & 0xFF);
641     if(pDMSResPri->stHalDMS.stDMS_DSSWDB.u32FlowFlag == 1)
642     {
643         //DIP
644         u8MVOPCtrl0_L = (u8MVOPCtrl0_L | 0xB0);
645     }
646     else if(pDMSResPri->stHalDMS.stDMS_DSSWDB.u32FlowFlag == 2)
647     {
648         //VDEC
649         u8MVOPCtrl0_L = (u8MVOPCtrl0_L & (0xFF - 0xB0));
650     }
651 
652     MS_U16 u16MVOPCtrl0 = u8MVOPCtrl0_H;
653     u16MVOPCtrl0 = ((u16MVOPCtrl0 << 8) | u8MVOPCtrl0_L);
654     if((gDMSMVOPForceLookVDEC == 1))
655     {
656         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101418, 0 , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
657         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101420, 0xF006 , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
658     }
659     else
660     {
661         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101418, u8MVOPPitch_L , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
662         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101420, u16MVOPCtrl0 , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
663     }
664 
665     u16MVOPForceWrite &= ~0x10;
666     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101427, u16MVOPForceWrite    , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
667 
668     MS_U32 ActiveSWClearEn = 0;
669     ActiveSWClearEn = MApi_XC_R2BYTE(0x1F2E);
670     ActiveSWClearEn |= 0x0010;//u32SW_Reset_IPM;
671     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1F2E, ActiveSWClearEn  , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
672 
673     Hal_DMS_Add_NullCommand(pInstance, MAIN_WINDOW, DS_IP,&STXC_DS_CMDCNT);
674     Hal_DMS_Add_NullCommand(pInstance, MAIN_WINDOW, DS_OP,&STXC_DS_CMDCNT);
675 
676 #if ALL_IP_COMMAND
677     if(STXC_DS_CMDCNT.u16CMDCNT_IPM > DMS_DS_DEPTH*4)
678 #else
679     if(STXC_DS_CMDCNT.u16CMDCNT_IPM > DMS_DS_DEPTH*2)
680 #endif
681     {
682         printf("\033[1;31m[%s][%d] error, IPM DS Command conut %d > Max_size %d\033[0m\n",__FUNCTION__,__LINE__,STXC_DS_CMDCNT.u16CMDCNT_IPM,DMS_DS_DEPTH*2);
683     }
684     if(STXC_DS_CMDCNT.u16CMDCNT_OPM > DMS_DS_DEPTH*2)
685     {
686         printf("\033[1;31m[%s][%d] error, OPM DS Command conut %d > Max_size %d\033[0m\n",__FUNCTION__,__LINE__,STXC_DS_CMDCNT.u16CMDCNT_OPM,DMS_DS_DEPTH*2);
687     }
688 
689     MApi_XC_Set_DSForceIndex(TRUE,pDMSResPri->stHalDMS.u8DSIndex,MAIN_WINDOW);
690     if(pDMSResPri->stHalDMS.u8DSIndex == 0)
691     {
692         pDMSResPri->stHalDMS.u8DSIndex = 1;
693     }
694     else
695     {
696         pDMSResPri->stHalDMS.u8DSIndex = 0;
697     }
698     return TRUE;
699 }
700 
HAL_DMS_XC_GetCaps(void * pInstance,EN_DMS_CAPABILITY * peCapability)701 MS_BOOL HAL_DMS_XC_GetCaps(void* pInstance, EN_DMS_CAPABILITY *peCapability)
702 {
703     *peCapability |= E_DMS_CAPABILITY_MULTI_WINDOW;
704     return TRUE;
705 }
706 
707 #if(DMS_DONT_USE_CMA == 1)
708 #ifdef MSOS_TYPE_LINUX_KERNEL
709 #include "drvCMAPool_v2.h"
710 #else
711 #include "drvCMAPool.h"
712 #endif
713 #include "msos/linux/mdrv_cma_pool_st.h"
714 #endif
715 
716 #define DMS_CMA_4MB 0x0400000
717 #define DMS_CMA_8MB 0x0800000
718 #define DMS_CMA_16MB 0x1000000
719 #define DMS_CMA_24MB 0x1800000
720 #define DMS_CMA_32MB 0x2000000
721 #define DMS_CMA_48MB 0x3000000
722 
723 #if(DMS_DONT_USE_CMA == 1)
HAL_DMS_Release_CMA(void * pInstance,EN_DMS_MEMORY_TYPE enMemType,MS_U32 u32CMAHeapID)724 MS_BOOL HAL_DMS_Release_CMA(void* pInstance, EN_DMS_MEMORY_TYPE enMemType, MS_U32 u32CMAHeapID)
725 {
726     return FALSE;
727 }
728 
HAL_DMS_Setup_CMA(void * pInstance,EN_DMS_MEMORY_TYPE enMemType,MS_U32 u32CMAHeapID)729 MS_BOOL HAL_DMS_Setup_CMA(void* pInstance, EN_DMS_MEMORY_TYPE enMemType, MS_U32 u32CMAHeapID)
730 {
731     MS_U32 u32GetCMABufferSize = 0;
732     switch(enMemType)
733     {
734         case E_DMS_MEMORY_TYPE_GOP_DISPLAY:
735         {
736 #if (DMS_DIP_Support_HVSP == 0)
737             u32GetCMABufferSize = DMS_CMA_48MB;
738 #else
739             u32GetCMABufferSize = DMS_CMA_32MB;
740 #endif
741             break;
742         }
743         case E_DMS_MEMORY_TYPE_FREEZE:
744         {
745             u32GetCMABufferSize = DMS_CMA_4MB;
746             break;
747         }
748         case E_DMS_MEMORY_TYPE_MVOP_DISPLAY:
749         {
750             u32GetCMABufferSize = DMS_CMA_24MB;
751             break;
752         }
753         default:
754         {
755             DMS_PRINTF("\033[1;31m[%s][%d] unuse mem type %d set CMA\033[0m\n",__FUNCTION__,__LINE__,enMemType);
756             break;
757         }
758     }
759     if(u32GetCMABufferSize == 0)
760     {
761         DMS_PRINTF("\033[1;31m[%s][%d] CMA buffer size = 0\033[0m\n",__FUNCTION__,__LINE__);
762         return FALSE;
763     }
764 
765     struct CMA_Pool_Alloc_Param CMA_Pool_GetMem;
766     CMA_Pool_GetMem.pool_handle_id = u32CMAHeapID;
767     CMA_Pool_GetMem.offset_in_pool = 0;
768     CMA_Pool_GetMem.flags = CMA_FLAG_VIRT_ADDR;
769     CMA_Pool_GetMem.length = u32GetCMABufferSize;
770 
771     if (MApi_CMA_Pool_GetMem(&CMA_Pool_GetMem) == FALSE)
772     {
773         DMS_PRINTF("\033[1;31m Function = %s, Line = %d, MApi_CMA_Pool_GetMem() fail!!! (Type %d, HeapID %d, Size 0x%x)\033[m\n", __PRETTY_FUNCTION__, __LINE__,
774             enMemType,u32CMAHeapID,u32GetCMABufferSize);
775         return FALSE;
776     }
777 
778     return TRUE;
779 }
780 #endif
781