xref: /utopia/UTPA2-700.0.x/modules/gpd/api/gpd/apiGPD.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-2007 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 #ifdef MSOS_TYPE_LINUX_KERNEL
95 #include <linux/module.h>
96 #include <linux/kernel.h>
97 #include <linux/time.h>
98 #include <linux/string.h>
99 #else
100 #include <stdio.h>
101 #include <stdlib.h>
102 #include <string.h>
103 #endif
104 #include <stddef.h>   /* for size_t */
105 #include "MsCommon.h"
106 #include "drvMMIO.h"
107 #include "gif_lib.h"
108 #include "apiGPD.h"
109 #include "drvgpd.h"
110 #include "gpd.h"
111 #include "drvMIU.h"
112 #include "halCHIP.h"
113 #ifdef CONFIG_MSTAR_CLKM
114 #ifdef MSOS_TYPE_LINUX_KERNEL
115 #include <linux/clkm.h>
116 #else
117 #include "drvCLKM.h"
118 #endif
119 #endif
120 
121 #include "utopia.h"
122 #include "apiGPD_priv.h"
123 #include "apiGPD_v2.h"
124 void* pInstantGPD = NULL;
125 
126 gpd_debug_level eEnableDbgMsg = E_GPD_DEBUG_LEVEL_NONE;
127 
128 //--------------------------------------------------------------------------------------------------
129 //  Internal define
130 //--------------------------------------------------------------------------------------------------
131 #if (defined CONFIG_MLOG)
132 #include "ULog.h"
133 
134 #define GPD_API_ERROR(format, args...)      do{if(eEnableDbgMsg & E_GPD_DEBUG_LEVEL_ERROR) ULOGE("API_GPD", format, ##args);}while(0)
135 #define GPD_API_INFO(format, args...)       do{if(eEnableDbgMsg & E_GPD_DEBUG_LEVEL_INFO) ULOGI("API_GPD", format, ##args);}while(0)
136 #else
137 
138 #ifdef ANDROID
139 #ifndef LOGD
140 #define GPD_API_ERROR(format, args...)      do{if(eEnableDbgMsg & E_GPD_DEBUG_LEVEL_ERROR) ALOGE(format, ##args);}while(0)
141 #define GPD_API_INFO(format, args...)       do{if(eEnableDbgMsg & E_GPD_DEBUG_LEVEL_INFO) ALOGI(format, ##args);}while(0)
142 #else
143 #define GPD_API_ERROR(format, args...)      do{if(eEnableDbgMsg & E_GPD_DEBUG_LEVEL_ERROR) LOGE(format, ##args);}while(0)
144 #define GPD_API_INFO(format, args...)       do{if(eEnableDbgMsg & E_GPD_DEBUG_LEVEL_INFO) LOGI(format, ##args);}while(0)
145 #endif
146 #else
147 #ifdef MSOS_TYPE_LINUX_KERNEL
148 #define GPD_API_ERROR(format, args...)      do{if(eEnableDbgMsg & E_GPD_DEBUG_LEVEL_ERROR) printk(format, ##args);}while(0)
149 #define GPD_API_INFO(format, args...)       do{if(eEnableDbgMsg & E_GPD_DEBUG_LEVEL_INFO) printk(format, ##args);}while(0)
150 #else
151 #define GPD_API_ERROR(format, args...)      do{if(eEnableDbgMsg & E_GPD_DEBUG_LEVEL_ERROR) printf(format, ##args);}while(0)
152 #define GPD_API_INFO(format, args...)       do{if(eEnableDbgMsg & E_GPD_DEBUG_LEVEL_INFO) printf(format, ##args);}while(0)
153 #endif
154 #endif
155 
156 #endif
157 
158 #define LOG_DATA_TO_USB         FALSE
159 
160 #ifdef GPD_UTOPIA_2K
161     #define GPD_DRIVER_BASE KERNEL_MODE
162 #else
163     #define GPD_DRIVER_BASE 0
164 #endif
165 
166 //#define VERIFY
167 
168 
169 #ifndef VERIFY
170 #define CBUFFER_SIZE         (1024UL*1024UL)
171 #define ZBUFFER_SIZE         (1024UL*1024UL)
172 
173 #define GPD_XIU_BASE  (0x13F00UL * 2UL)
174 #define GPD_RIU_BASE  (0x13E00UL * 2UL)
175 
176 
177 #define MIU_CLI_BASE  (0x01200UL * 2UL)
178 #define MIU_SEL_BASE  (0x00600UL * 2UL)
179 
180 #define STB_GPD_XIU_BASE  (0x10F00UL * 2UL)
181 #define STB_GPD_RIU_BASE  (0x10E00UL * 2UL)
182 
183 #else
184 
185 #define CBUFFER_SIZE         (1024UL*1024UL)
186 #define ZBUFFER_SIZE         (1024UL*1024UL)
187 #define STREAMBUFFER_SIZE  (4UL*1024UL*1024UL) //4MB
188 #define FRAMEBUFFER_SIZE  (22UL*1024UL*1024UL) //22MB
189 
190 
191 #define CBUFFER            (DRAMBASE + 0x11000000UL)
192 #define ZBUFFER            (CBUFFER + CBUFFER_SIZE)
193 #define STREAMBUFFER       (ZBUFFER + ZBUFFER_SIZE)
194 #define FRAMEBUFFER        (STREAMBUFFER + STREAMBUFFER_SIZE)
195 #define ARGBBUFFER         (FRAMEBUFFER + FRAMEBUFFER_SIZE)
196 
197 #if (defined(__arm__))
198 
199 #define HK_REG_BASE   0xFD200000UL
200 
201 #else
202 
203 #define HK_REG_BASE   0xBF200000UL
204 
205 #endif
206 
207 #define GPD_XIU_BASE  (HK_REG_BASE + 0x13F00UL * 2UL)
208 #define GPD_RIU_BASE  (HK_REG_BASE + 0x13E00UL * 2UL)
209 
210 #if 0
211 
212 #define CLK_GEN_BASE  (HK_REG_BASE + 0x00B00 * 2)
213 
214 #else
215 
216 #define CLK_GEN_BASE  (HK_REG_BASE + 0x03300UL * 2UL)
217 
218 #endif
219 
220 #define MIU_CLI_BASE  (HK_REG_BASE + 0x01200UL * 2UL)
221 
222 
223 #endif
224 
225 #define HW_MAX_SUPPORTED_WIDTH          8192UL
226 #define HW_MAX_SUPPORTED_HEIGHT         8192UL
227 
228 //--------------------------------------------------------------------------------------------------
229 //  Internal macros
230 //--------------------------------------------------------------------------------------------------
231 //#define MMIO8(addr) (*((volatile MS_U8*)(addr)))
232 #define _GPD_SHM_POINTER_CHECK()   \
233     do\
234     {\
235         if (pGPDContext == NULL)\
236         {\
237             return;\
238         }\
239     }while(0)
240 
241 #define _GPD_SHM_POINTER_CHECK_RETURN(x)   \
242     do\
243     {\
244         if (pGPDContext == NULL)\
245         {\
246             return x;\
247         }\
248     }while(0)
249 
250 //--------------------------------------------------------------------------------------------------
251 //  Internal Variable
252 //--------------------------------------------------------------------------------------------------
253 MS_U32 g_gpd_set_access_region = FALSE;
254 MS_VIRT g_gpd_clock;
255 
256 typedef struct
257 {
258     gpd_addr_info GpdAddrInfo;
259     gpd_pic_info Param;
260     MS_U32 MIUAllocation;
261     MS_U32 RIU_REG_BASE;
262     MS_U8 bIsGPDInit;
263 } GPD_EX_CTX;
264 
265 GPD_EX_CTX* pGPDContext = NULL;
266 GPD_EX_CTX gGPDContext;
267 
268 #ifdef CONFIG_UTOPIA_PROC_DBG_SUPPORT
269 #include "utopia_dapi.h"
270 
271 typedef struct
272 {
273 MS_VIRT _u32ReadBufferAddr;
274 MS_PHY _u32ReadBufferAddr_PA;
275 MS_U32 _u32ReadBufferSize;
276 #ifndef MSOS_TYPE_LINUX_KERNEL
277 MS_VIRT _u32WriteBufferAddr;
278 #endif
279 MS_PHY _u32WriteBufferAddr_PA;
280 MS_U32 _u32WriteBufferSize;
281 MS_VIRT _u32InternalBufferAddr;
282 MS_U32 _u32InternalBufferSize;
283 MS_PHY _u32InternalBufferAddr_PA;
284 
285 MS_U16 _u16Image_x_size;
286 MS_U16 _u16Image_y_size;
287 
288 MS_U32 ocolor;
289 MS_BOOL bPNG;
290 
291 MS_U32 _u32HWStartTime;
292 MS_U32 _u32HWEndTime;
293 
294 }GPD_MDebug;
295 
296 GPD_MDebug gGPDMDebug;
297 
298 #endif
299 
300 //--------------------------------------------------------------------------------------------------
301 //  Implementation
302 //--------------------------------------------------------------------------------------------------
303 
304 
305 //extern void *memset(void *ptr, MS_U32 value, size_t num);
306 extern void mdrv_gpd_setbuf(gpd_addr_info* addr_info);
307 extern MS_S32 mdrv_gpd_init(gpd_addr_info* param);
308 extern MS_S32 mdrv_gpd_decode(gpd_pic_info* pic_info, MS_U32 Ocolor, MS_U32 mode,gpd_roi_info* roi);
309 extern void mdrv_gpd_scaling_init(MS_U32 enable, MS_U32 mode);
310 #ifdef CONFIG_UTOPIA_PROC_DBG_SUPPORT
311 extern MS_BOOL mdrv_gpd_bPNG(void);
312 #endif
313 
314 MS_U32 MApi_GPD_Input_GetCRCResult(const MS_U8 *pu8Data, MS_U32 u32Size);
315 
316 #if (ENABLE_GPD_MESSAGE|| LOG_DATA_TO_USB)
317 static MS_U32 u32FileIndex=0;
318 #endif
319 
320 #if LOG_DATA_TO_USB
GPD_WRITE_INPUT_2_USB(MS_U32 u32addr,MS_U32 u32Size,MS_U32 u32Index)321 void GPD_WRITE_INPUT_2_USB(MS_U32 u32addr, MS_U32 u32Size, MS_U32 u32Index)
322 {
323     u32Size = ALIGN_16(u32Size);
324     static MS_U8 fileName2[]={'/','u','s','b','/','s','d','a','1','/','I','n', 'p', 'u', 't','_','0', '0', '0', '.', 'p', 'n', 'g',0};
325     MS_U8 u8FilenameIndex = 10;
326 
327     fileName2[u8FilenameIndex+6]=(u32Index/100)%10+'0';
328     fileName2[u8FilenameIndex+7]=(u32Index/10)%10+'0';
329     fileName2[u8FilenameIndex+8]=u32Index%10+'0';
330 
331     FILE *inBinfp;
332     if((inBinfp = fopen((char *)fileName2, "wb"))==NULL)
333     {
334         GPD_API_ERROR("Can't open input png file\n");
335     }
336     else
337     {
338         GPD_API_ERROR("open input png file success\n");
339     }
340 
341     fwrite((void *)u32addr, 1, u32Size, inBinfp);
342     fclose(inBinfp);
343 
344 }
345 
GPD_WRITE_OUTPUT_2_USB(MS_U32 u32addr,MS_U32 u32Size,MS_U32 u32Width,MS_U32 u32Height,MS_U32 u32Index)346 void GPD_WRITE_OUTPUT_2_USB(MS_U32 u32addr, MS_U32 u32Size, MS_U32 u32Width, MS_U32 u32Height, MS_U32 u32Index)
347 {
348     u32Size = ALIGN_16(u32Size);
349     static MS_U8 fileName2[]={'/','u','s','b','/','s','d','a','1','/','0','0', '0', '0', 'x','0','0', '0', '0', '_','0', '0', '0', '.', 'y', 'u', 'y', 'v',0};
350     MS_U8 u8FilenameIndex = 10;
351     fileName2[u8FilenameIndex]=u32Width/1000+'0';
352     fileName2[u8FilenameIndex+1]=(u32Width/100)%10+'0';
353     fileName2[u8FilenameIndex+2]=(u32Width/10)%10+'0';
354     fileName2[u8FilenameIndex+3]=u32Width%10+'0';
355     fileName2[u8FilenameIndex+5]=u32Height/1000+'0';
356     fileName2[u8FilenameIndex+6]=(u32Height/100)%10+'0';
357     fileName2[u8FilenameIndex+7]=(u32Height/10)%10+'0';
358     fileName2[u8FilenameIndex+8]=u32Height%10+'0';
359 
360     fileName2[u8FilenameIndex+10]=(u32Index/100)%10+'0';
361     fileName2[u8FilenameIndex+11]=(u32Index/10)%10+'0';
362     fileName2[u8FilenameIndex+12]=u32Index%10+'0';
363 
364 
365     FILE *outBinfp;
366     if((outBinfp = fopen((char *)fileName2, "wb"))==NULL)
367     {
368         GPD_API_ERROR("Can't open output yuyv file\n");
369     }
370     else
371     {
372         GPD_API_ERROR("open output yuyv file success\n");
373     }
374 
375     fwrite((void *)u32addr, 1, u32Size, outBinfp);
376     fclose(outBinfp);
377 
378 }
379 #endif
380 
_GPD_Context_Init(void)381 static void _GPD_Context_Init(void)
382 {
383 
384 
385 
386 
387 }
388 
389 
_GPD_Init_Share_Mem(void)390 static MS_BOOL _GPD_Init_Share_Mem(void)
391 {
392 #if defined(MSOS_TYPE_LINUX) || defined(MSOS_TYPE_LINUX_KERNEL) || defined(MSOS_TYPE_ECOS)
393     MS_U32 u32ShmId;
394     MS_VIRT u32Addr;
395     MS_U32 u32BufSize;
396 
397     if (FALSE == MsOS_SHM_GetId( (MS_U8*)"Linux GPD driver",
398                                           sizeof(GPD_EX_CTX),
399                                           &u32ShmId,
400                                           &u32Addr,
401                                           &u32BufSize,
402                                           MSOS_SHM_QUERY))
403     {
404         if (FALSE == MsOS_SHM_GetId((MS_U8*)"Linux GPD driver",
405                                              sizeof(GPD_EX_CTX),
406                                              &u32ShmId,
407                                              &u32Addr,
408                                              &u32BufSize,
409                                              MSOS_SHM_CREATE))
410         {
411             if(pGPDContext == NULL)
412             {
413                 pGPDContext = &gGPDContext;
414                 memset(pGPDContext,0,sizeof(GPD_EX_CTX));
415                 _GPD_Context_Init();
416             }
417             else
418             {
419                 GPD_API_INFO("[%s]Global structure exists!!!\n",__FUNCTION__);
420             }
421             return FALSE;
422         }
423         else
424         {
425             memset((MS_U8*)u32Addr, 0, sizeof(GPD_EX_CTX));
426             pGPDContext = (GPD_EX_CTX*)u32Addr; // for one process
427             _GPD_Context_Init();
428         }
429     }
430     else
431     {
432         pGPDContext = (GPD_EX_CTX*)u32Addr; // for another process
433     }
434 
435 
436 #else
437     if(pGPDContext == NULL)
438     {
439         pGPDContext = &gGPDContext;
440         memset(pGPDContext,0,sizeof(GPD_EX_CTX));
441         _GPD_Context_Init();
442     }
443 #endif
444 
445     return TRUE;
446 }
447 
_GPD_SetCacheable(MS_U32 param)448 static MS_U32 _GPD_SetCacheable(MS_U32 param)
449 {
450     MS_U32 cacheable;
451     cacheable = (param == TRUE) ? TRUE: FALSE;
452     drv_gpd_set_cacheable(cacheable);
453 
454     return TRUE;
455 }
456 
_GPD_SetAccessRegion(gpd_access_region * param)457 static MS_U32 _GPD_SetAccessRegion(gpd_access_region *param)
458 {
459     MS_VIRT BankBaseAddr;
460     MS_PHY BankSize;
461     MS_U32 u32GPDRIUBase, u32GPDXIUBase;
462 
463     MDrv_GPD_Reg_Base(&u32GPDRIUBase, &u32GPDXIUBase);
464 
465     if(FALSE == MDrv_MMIO_GetBASE((MS_VIRT*)&BankBaseAddr, &BankSize, MS_MODULE_GPD))
466     {
467         GPD_API_ERROR("MDrv_MMIO_GetBASE FAILED !! \n");
468         return FALSE;
469     }
470 
471     pGPDContext->GpdAddrInfo.RegBaseAddr = BankBaseAddr + (MS_VIRT)u32GPDRIUBase;
472     mdrv_gpd_setbuf(&pGPDContext->GpdAddrInfo);
473     drv_gpd_set_access_region(param->u32PA_StartAddr >> WORDALIGN, param->u32PA_EndAddr >> WORDALIGN);
474     g_gpd_set_access_region = TRUE;
475 
476     GPD_API_INFO("Set g_gpd_set_access_region to TRUE!!!!\n");
477     return TRUE;
478 
479 }
480 
_GPD_GetPitch(gpd_get_pitch_info * para)481 static MS_U32 _GPD_GetPitch(gpd_get_pitch_info *para)
482 {
483     if(para == NULL)
484     {
485         GPD_API_ERROR("_GPD_GetPitch FAILED !! para error\n");
486         return FALSE;
487     }
488     if(para->ocolor > GRAY_ALPHA)
489     {
490         GPD_API_ERROR("_GPD_GetPitch FAILED !! ocolor error\n");
491         return FALSE;
492     }
493     if(para->u32Width == 0)
494     {
495         GPD_API_ERROR("_GPD_GetPitch FAILED !! u32Width error\n");
496         return FALSE;
497     }
498     switch(para->ocolor)
499     {
500         case ARGB8888:
501             para->u32Pitch = (((para->u32Width) + 1) & ~1);     // 2-align
502             break;
503         case YUV422:
504         case RGB565:
505         case YVYU422:
506         case GRAY_ALPHA:
507             para->u32Pitch = (((para->u32Width) + 3) & ~3);     // 4-align
508             break;
509         case GRAY:
510             para->u32Pitch = (((para->u32Width) + 7) & ~7);     // 8-align
511             break;
512     }
513     return TRUE;
514 
515 }
516 
517 
518 #ifndef VERIFY
verGPD_ISR_CB(void)519 void verGPD_ISR_CB(void)
520 {
521     GPD_API_ERROR("verGPD_ISR_CB()!!!!!!!!!\n");
522 }
523 
524 
MApi_GPD_EnableISR(GPD_IsrFuncCb IsrCb)525 void MApi_GPD_EnableISR(GPD_IsrFuncCb IsrCb)
526 {
527     if(TRUE == MDrv_GPD_EnableISR((GPD_IsrFuncCb)IsrCb))
528     {
529     }
530     else
531     {
532         GPD_API_ERROR("%s : Fail!!!!\n", __FUNCTION__);
533     }
534     return;
535 }
536 //------------------------------------------------------------------------------
537 /********************************************************************/
538 /// Disable GPD ISR and unregister callback function.
539 ///@return \b JPEG_Result
540 /// - E_JPEG_OKAY : success.
541 /// - E_JPEG_FAILED : fail.
542 /********************************************************************/
MApi_GPD_DisableISR(void)543 void MApi_GPD_DisableISR(void)
544 {
545     if(TRUE == MDrv_GPD_DisableISR())
546     {
547     }
548     else
549     {
550         GPD_API_ERROR("%s : Fail!!!!\n", __FUNCTION__);
551     }
552     return;
553 }
554 
555 
_MApi_GPD_Init(MS_PHY SrcBuf)556 void *_MApi_GPD_Init(MS_PHY SrcBuf)
557 {
558     MS_VIRT BankBaseAddr;
559     MS_PHY BankSize;
560     MS_U32 GPD_CLK_BASE, GPD_CLK_OFFSET;
561     MS_U32 u32GPDRIUBase, u32GPDXIUBase;
562 
563     _GPD_Init_Share_Mem();
564     _GPD_SHM_POINTER_CHECK_RETURN(FALSE);
565 
566     if(pGPDContext->bIsGPDInit == TRUE)
567     {
568         GPD_API_ERROR("GPD is in used !! \n");
569         return FALSE;
570     }
571     else
572     {
573         pGPDContext->bIsGPDInit = TRUE;
574     }
575 
576     GPD_API_INFO("MApi_GPD_Init\n");
577     GPD_API_INFO("GPD version:%x\n", GPD_VERSION);
578 
579     if(FALSE == MDrv_MMIO_GetBASE(&BankBaseAddr, &BankSize, MS_MODULE_GPD))
580     {
581         GPD_API_ERROR("MDrv_MMIO_GetBASE FAILED !! \n");
582         pGPDContext->bIsGPDInit = FALSE;
583         return FALSE;
584     }
585 
586     pGPDContext->RIU_REG_BASE = BankBaseAddr;
587     GPD_API_INFO("[%s] [%d] BankBaseAddr = %tx, BankSize = %tx\n", __FUNCTION__, __LINE__, (ptrdiff_t)BankBaseAddr, (ptrdiff_t)BankSize);
588 
589     //enable gpd clck
590 
591     GPD_CLK_BASE = drv_gpd_get_clkbase();
592 
593     GPD_CLK_OFFSET = drv_gpd_get_clkoffset();
594 
595     GPD_API_INFO("GPD_CLK_BASE=%tx, GPD_CLK_OFFSET=%tx\n", (ptrdiff_t)GPD_CLK_BASE, (ptrdiff_t)GPD_CLK_OFFSET);
596 
597     drv_gpd_init_outside_reg(BankBaseAddr);
598 
599     if (TRUE == g_gpd_set_access_region)
600     {
601         g_gpd_clock = (BankBaseAddr + GPD_CLK_BASE + GPD_CLK_OFFSET);
602         GPD_API_INFO("Set g_gpd_clock to %tx!!!!(%tx %tx %tx)\n", (ptrdiff_t)g_gpd_clock,
603             (ptrdiff_t)BankBaseAddr, (ptrdiff_t)GPD_CLK_BASE, (ptrdiff_t)GPD_CLK_OFFSET);
604     }
605     else
606     {
607 #ifdef CONFIG_MSTAR_CLKM
608         drv_gpd_power_on();
609 #else
610 #if 1
611         GPD_API_INFO("@@@set gpd_clk to 216MHz\n");
612         *((volatile MS_U32 *)(BankBaseAddr + GPD_CLK_BASE + GPD_CLK_OFFSET)) = 0;   // 0x28 << 2
613 #elif 0
614         GPD_API_INFO("@@@set gpd_clk to 192MHz\n");
615         *((volatile MS_U32 *)(BankBaseAddr + GPD_CLK_BASE + GPD_CLK_OFFSET)) = 0x4;
616 #else
617         GPD_API_INFO("@@@set gpd_clk to 144MHz\n");
618         *((volatile MS_U32 *)(BankBaseAddr + GPD_CLK_BASE + GPD_CLK_OFFSET)) = 0xc;
619 #endif
620 #endif
621 
622     }
623     MDrv_GPD_Reg_Base(&u32GPDRIUBase, &u32GPDXIUBase);
624 
625 #if 0
626     MS_U32 u32Offset = 0;
627     _phy_to_miu_offset(pGPDContext->MIUAllocation, u32Offset, SrcBuf);
628     UNUSED(u32Offset);
629     switch(pGPDContext->MIUAllocation)
630     {
631         case E_CHIP_MIU_0:
632             MDrv_MIU_SelMIU(MIU_CLIENT_GPD_RW, MIU_SELTYPE_MIU0);
633             break;
634         case E_CHIP_MIU_1:
635             MDrv_MIU_SelMIU(MIU_CLIENT_GPD_RW, MIU_SELTYPE_MIU1);
636             break;
637         case E_CHIP_MIU_2:
638             MDrv_MIU_SelMIU(MIU_CLIENT_GPD_RW, MIU_SELTYPE_MIU2);
639             break;
640         case E_CHIP_MIU_3:
641             MDrv_MIU_SelMIU(MIU_CLIENT_GPD_RW, MIU_SELTYPE_MIU3);
642             break;
643         default:
644             MDrv_MIU_SelMIU(MIU_CLIENT_GPD_RW, MIU_SELTYPE_MIU0);
645             break;
646     }
647 #else
648     MS_U32 tmp = 0;
649     MS_U8 u8MIU_Offset;
650     MS_U16 u16MIU_Mask;
651     MDrv_GPD_MIU_Client(&u8MIU_Offset, &u16MIU_Mask);
652 
653     //check miu sel is controlled by HW or MIU
654     //GPD MIU select control is
655     tmp = *((volatile MS_U32 *)(BankBaseAddr + MIU_SEL_BASE + (((MS_U32)u8MIU_Offset)<< 1)));
656     tmp &= (~u16MIU_Mask);
657     *((volatile MS_U32 *)(BankBaseAddr + MIU_SEL_BASE + (((MS_U32)u8MIU_Offset) << 1))) = tmp;
658 
659     tmp = *((volatile MS_U32 *)(BankBaseAddr + MIU_CLI_BASE + (((MS_U32)u8MIU_Offset) << 1)));
660 
661     GPD_API_INFO("GPD MIU value = %tx\n", (ptrdiff_t)tmp);
662     GPD_API_INFO("SrcBuf :0x%tx\n", (ptrdiff_t)SrcBuf);
663 
664     pGPDContext->MIUAllocation = MDrv_GPD_MIU_Select(SrcBuf);
665     if(pGPDContext->MIUAllocation)
666     {
667         tmp |= (u16MIU_Mask);
668         GPD_API_INFO("Select MIU1\n");
669     }
670     else
671     {
672         tmp &= (~u16MIU_Mask);
673         GPD_API_INFO("Select MIU0\n");
674     }
675 
676     *((volatile MS_U32 *)(BankBaseAddr + MIU_CLI_BASE +(((MS_U32)u8MIU_Offset) << 1))) = tmp;
677 #endif
678 
679     pGPDContext->GpdAddrInfo.RegBaseAddr = BankBaseAddr + (MS_VIRT)u32GPDRIUBase;
680     pGPDContext->GpdAddrInfo.ReadBitBaseAddr = BankBaseAddr + (MS_VIRT)u32GPDXIUBase;
681 
682     pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr = SrcBuf;
683 
684     if (FALSE == drv_gpd_get_cacheable())
685     {
686         pGPDContext->GpdAddrInfo.u32VA_ColorBufferAddr = MsOS_PA2KSEG1(pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr);
687         pGPDContext->GpdAddrInfo.u32PA_DepthBufferAddr = pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr + 512UL * 1024UL;
688         pGPDContext->GpdAddrInfo.u32VA_DepthBufferAddr = MsOS_PA2KSEG1(pGPDContext->GpdAddrInfo.u32PA_DepthBufferAddr);
689     }
690     else
691     {
692         pGPDContext->GpdAddrInfo.u32VA_ColorBufferAddr = MsOS_PA2KSEG0(pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr);
693         pGPDContext->GpdAddrInfo.u32PA_DepthBufferAddr = pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr + 512UL * 1024UL;
694         pGPDContext->GpdAddrInfo.u32VA_DepthBufferAddr = MsOS_PA2KSEG0(pGPDContext->GpdAddrInfo.u32PA_DepthBufferAddr);
695     }
696 
697 
698     if(pGPDContext->GpdAddrInfo.u32VA_ColorBufferAddr == 0)
699     {
700         GPD_API_ERROR("Error!! MApi_GPD_Init with SrcBuf(PA)=0x%tx, VA=0\n", (ptrdiff_t)SrcBuf);
701         pGPDContext->bIsGPDInit = FALSE;
702         return FALSE;
703     }
704 
705 
706     mdrv_gpd_init(&pGPDContext->GpdAddrInfo);
707 #if 0
708     MApi_GPD_DisableISR();
709     MApi_GPD_EnableISR((GPD_IsrFuncCb)verGPD_ISR_CB);
710     MDrv_GPD_SetISRMask();
711 #endif
712 
713     return &(pGPDContext->GpdAddrInfo);
714 
715 }
716 
_MApi_GPD_InputSource(gpd_pic_info * param,MS_PHY InputBuf,MS_U32 Size)717 MS_S32 _MApi_GPD_InputSource(gpd_pic_info* param, MS_PHY InputBuf, MS_U32 Size)
718 {
719     MS_U8 u8MiuSel = 0;
720     MS_U32 u32Offset = 0;
721     _GPD_SHM_POINTER_CHECK_RETURN(FALSE);
722 
723     _phy_to_miu_offset(u8MiuSel, u32Offset, InputBuf);
724     UNUSED(u32Offset);
725     if(pGPDContext->MIUAllocation != u8MiuSel)
726     {
727         GPD_API_INFO("Wrong Memory Allocation\n");
728         pGPDContext->bIsGPDInit = FALSE;
729         return -1;
730     }
731 
732     if(pGPDContext->bIsGPDInit == FALSE)
733     {
734         GPD_API_ERROR("[%s]GPD is not inited\n", __FUNCTION__);
735         return -1;
736     }
737     GPD_API_INFO("MApi_GPD_ParseHeader\n");
738     pGPDContext->GpdAddrInfo.u32PA_ReadBufferAddr = InputBuf;
739 
740     GPD_API_INFO("InputBuf=%tx\n", (ptrdiff_t)InputBuf);
741 
742     if (FALSE == drv_gpd_get_cacheable())
743     {
744         pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr = MsOS_PA2KSEG1(pGPDContext->GpdAddrInfo.u32PA_ReadBufferAddr);
745         GPD_API_INFO("MsOS_PA2KSEG1(InputBuf)=%tx\n", (ptrdiff_t)MsOS_PA2KSEG1(InputBuf));
746     }
747     else
748     {
749         pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr = MsOS_PA2KSEG0(pGPDContext->GpdAddrInfo.u32PA_ReadBufferAddr);
750         GPD_API_INFO("MsOS_PA2KSEG0(InputBuf)=%tx\n", (ptrdiff_t)MsOS_PA2KSEG0(InputBuf));
751     }
752 
753     if(pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr == 0)
754     {
755         GPD_API_ERROR("Error!! MApi_GPD_InputSource with InputBuf(PA)=0x%tx, VA=0\n", (ptrdiff_t)InputBuf);
756         pGPDContext->bIsGPDInit = FALSE;
757         return -1;
758     }
759 
760     pGPDContext->GpdAddrInfo.u32ReadBufferSize = Size;
761 
762 #if (ENABLE_GPD_MESSAGE|| LOG_DATA_TO_USB)
763     u32FileIndex++;
764 #if LOG_DATA_TO_USB
765     GPD_WRITE_INPUT_2_USB((MS_U32)pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr, (MS_U32)Size, u32FileIndex);
766 #endif
767 
768 #if ENABLE_GPD_MESSAGE
769     GPD_API_INFO("[%s][addr=0x%tx, size=0x%tx] Input CRC result=0x%tx\n", __FUNCTION__,
770         (ptrdiff_t)pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr, (ptrdiff_t)pGPDContext->GpdAddrInfo.u32ReadBufferSize,
771         (ptrdiff_t)MApi_GPD_Input_GetCRCResult((MS_U8 *)(MS_VIRT)pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr,
772         pGPDContext->GpdAddrInfo.u32ReadBufferSize));
773 #endif
774 #endif
775 
776 
777     mdrv_gpd_setbuf(&(pGPDContext->GpdAddrInfo));
778     mdrv_gpd_decode(param,0,1,NULL);
779     if(param->u32Height > HW_MAX_SUPPORTED_HEIGHT || param->u32Width >HW_MAX_SUPPORTED_WIDTH)
780     {
781         param->enGPDStatus = -2;
782     }
783     memcpy((void*)(&(pGPDContext->Param)),(void*)(param),sizeof(gpd_pic_info));
784     return param->enGPDStatus;
785 
786 }
787 
788 #if ENABLE_GPD_MESSAGE
MApi_GPD_PrintMem(MS_VIRT u32Addr,MS_U32 u32Size)789 static void MApi_GPD_PrintMem(MS_VIRT u32Addr, MS_U32 u32Size)
790 {
791     MS_U32 u32i;
792     GPD_API_INFO("===========================================================\n");
793     GPD_API_INFO("print memory addr=0x%tx, size=0x%tx\n", (ptrdiff_t)u32Addr, (ptrdiff_t)u32Size);
794     GPD_API_INFO("===========================================================\n");
795 
796 #if 0
797     for(u32i=0; u32i<u32Size/8+((u32Size%8)? 1:0); u32i++)
798     {
799         GPD_API_INFO("%02x %02x %02x %02x %02x %02x %02x %02x \n",
800         *((MS_U8*)(u32Addr+u32i*8)), *((MS_U8*)(u32Addr+u32i*8+1)), *((MS_U8*)(u32Addr+u32i*8+2)), *((MS_U8*)(u32Addr+u32i*8+3)),
801         *((MS_U8*)(u32Addr+u32i*8+4)), *((MS_U8*)(u32Addr+u32i*8+5)), *((MS_U8*)(u32Addr+u32i*8+6)), *((MS_U8*)(u32Addr+u32i*8+7))
802         );
803     }
804 #else
805     for(u32i=0; u32i<u32Size/16+((u32Size%16)? 1:0); u32i++)
806     {
807         GPD_API_INFO("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x \n",
808         *((MS_U8*)(u32Addr+u32i*16)), *((MS_U8*)(u32Addr+u32i*16+1)), *((MS_U8*)(u32Addr+u32i*16+2)), *((MS_U8*)(u32Addr+u32i*16+3)),
809         *((MS_U8*)(u32Addr+u32i*16+4)), *((MS_U8*)(u32Addr+u32i*16+5)), *((MS_U8*)(u32Addr+u32i*16+6)), *((MS_U8*)(u32Addr+u32i*16+7)),
810         *((MS_U8*)(u32Addr+u32i*16+8)), *((MS_U8*)(u32Addr+u32i*16+9)), *((MS_U8*)(u32Addr+u32i*16+10)), *((MS_U8*)(u32Addr+u32i*16+11)),
811         *((MS_U8*)(u32Addr+u32i*16+12)), *((MS_U8*)(u32Addr+u32i*16+13)), *((MS_U8*)(u32Addr+u32i*16+14)), *((MS_U8*)(u32Addr+u32i*16+15))
812         );
813     }
814 #endif
815     GPD_API_INFO("===========================================================\n");
816 }
817 #endif
818 
819 
_MApi_GPD_OutputDecode(MS_PHY DecodeBuf,MS_U32 ocolor,MS_U32 Size)820 MS_S32 _MApi_GPD_OutputDecode(MS_PHY DecodeBuf, MS_U32 ocolor, MS_U32 Size)
821 {
822     //DecodeBuf needs 32-byte alignment
823     //gpd_pic_info info;
824     //gpd_pic_info* param = &info;
825     MS_U8 u8MiuSel = 0;
826     MS_U32 u32Offset = 0;
827 
828     _GPD_SHM_POINTER_CHECK_RETURN(FALSE);
829     _phy_to_miu_offset(u8MiuSel, u32Offset, DecodeBuf);
830     UNUSED(u32Offset);
831     if(pGPDContext->MIUAllocation != u8MiuSel)
832     {
833         GPD_API_INFO("Wrong Memory Allocation\n");
834         pGPDContext->bIsGPDInit = FALSE;
835         return -1;
836     }
837 
838     if(pGPDContext->bIsGPDInit == FALSE)
839     {
840         GPD_API_ERROR("[%s]GPD is not inited\n", __FUNCTION__);
841         return -1;
842     }
843     gpd_roi_info roi;
844     GPD_API_INFO("MApi_GPD_Decode\n");
845     pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr = DecodeBuf;
846     if (FALSE == drv_gpd_get_cacheable())
847     {
848         pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr = MsOS_PA2KSEG1(pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr);
849     }
850     else
851     {
852         pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr = MsOS_PA2KSEG0(pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr);
853     }
854     pGPDContext->GpdAddrInfo.u32WriteBufferSize = Size;
855 
856 
857     if(pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr == 0)
858     {
859         GPD_API_ERROR("Error!! MApi_GPD_OutputDecode with DecodeBuf(PA)=0x%tx, VA=0\n", (ptrdiff_t)DecodeBuf);
860         pGPDContext->bIsGPDInit = FALSE;
861         return -1;
862     }
863 
864     memset(&roi, 0, sizeof(roi));
865     mdrv_gpd_setbuf(&pGPDContext->GpdAddrInfo);
866 
867     drv_gpd_set_access_bound(pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr,pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr + pGPDContext->GpdAddrInfo.u32WriteBufferSize - 1,
868                                                     pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr, pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr +CBUFFER_SIZE+ZBUFFER_SIZE-1);
869 
870     GPD_API_INFO("GPDBaseAddr=0x%tx\n", (ptrdiff_t)pGPDContext->GpdAddrInfo.RegBaseAddr);
871     GPD_API_INFO("READBITBaseAddr=0x%tx\n", (ptrdiff_t)pGPDContext->GpdAddrInfo.ReadBitBaseAddr);
872     GPD_API_INFO("Read  buf PA=0x%tx,VA=0x%tx\n", (ptrdiff_t)pGPDContext->GpdAddrInfo.u32PA_ReadBufferAddr, (ptrdiff_t)pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr);
873     GPD_API_INFO("Write buf PA=0x%tx,VA=0x%tx\n", (ptrdiff_t)pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr, (ptrdiff_t)pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr);
874     GPD_API_INFO("Color buf PA=0x%tx,VA=0x%tx\n", (ptrdiff_t)pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr, (ptrdiff_t)pGPDContext->GpdAddrInfo.u32VA_ColorBufferAddr);
875     GPD_API_INFO("Depth buf PA=0x%tx,VA=0x%tx\n", (ptrdiff_t)pGPDContext->GpdAddrInfo.u32PA_DepthBufferAddr, (ptrdiff_t)pGPDContext->GpdAddrInfo.u32VA_DepthBufferAddr);
876     GPD_API_INFO("Read  buf size=0x%tx\n", (ptrdiff_t)pGPDContext->GpdAddrInfo.u32ReadBufferSize);
877     GPD_API_INFO("Write buf size=0x%tx\n", (ptrdiff_t)pGPDContext->GpdAddrInfo.u32WriteBufferSize);
878 
879 
880 #if ENABLE_GPD_MESSAGE
881 //    memset((void *)pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr, 0x37, (size_t)pGPDContext->GpdAddrInfo.u32WriteBufferSize);
882 #endif
883 
884 #ifdef CONFIG_UTOPIA_PROC_DBG_SUPPORT
885         gGPDMDebug._u32HWStartTime= MsOS_GetSystemTime();
886 #endif
887     mdrv_gpd_decode(&pGPDContext->Param, ocolor, 0, &roi);
888 
889 
890 #ifdef CONFIG_UTOPIA_PROC_DBG_SUPPORT
891     gGPDMDebug._u32HWEndTime= MsOS_GetSystemTime();
892     gGPDMDebug.bPNG = mdrv_gpd_bPNG();
893     gGPDMDebug._u32ReadBufferAddr_PA = pGPDContext->GpdAddrInfo.u32PA_ReadBufferAddr;
894     gGPDMDebug._u32WriteBufferAddr_PA= pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr;
895     gGPDMDebug._u32InternalBufferAddr_PA= pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr;
896 
897     gGPDMDebug._u32ReadBufferAddr = pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr;
898 #ifndef MSOS_TYPE_LINUX_KERNEL
899     gGPDMDebug._u32WriteBufferAddr= pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr;
900 #endif
901     gGPDMDebug._u32InternalBufferAddr= pGPDContext->GpdAddrInfo.u32VA_ColorBufferAddr;
902 
903     gGPDMDebug._u32ReadBufferSize = pGPDContext->GpdAddrInfo.u32ReadBufferSize;
904     gGPDMDebug._u32WriteBufferSize= pGPDContext->GpdAddrInfo.u32WriteBufferSize;
905     gGPDMDebug._u32InternalBufferSize= 0x200000;
906 
907     gGPDMDebug._u16Image_x_size = (MS_U16)pGPDContext->Param.u32Width;
908     gGPDMDebug._u16Image_y_size= (MS_U16)pGPDContext->Param.u32Height;
909 
910 #endif
911 
912 #if (ENABLE_GPD_MESSAGE|| LOG_DATA_TO_USB)
913 
914     MS_U8 u8BytesPerPixel;
915     switch(ocolor)
916     {
917         case ARGB8888:
918             u8BytesPerPixel = 4;
919             break;
920         case YUV422:
921         case RGB565:
922         case YVYU422:
923         case GRAY_ALPHA:
924             u8BytesPerPixel = 2;
925             break;
926         case GRAY:
927         default:
928             u8BytesPerPixel = 1;
929             break;
930     }
931 
932 #if LOG_DATA_TO_USB
933     GPD_WRITE_OUTPUT_2_USB((MS_U32)pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr,
934         (MS_U32)(pGPDContext->Param.u32Height)*(pGPDContext->Param.u32Width)*u8BytesPerPixel, pGPDContext->Param.u32Width, pGPDContext->Param.u32Height, u32FileIndex);
935 #endif
936 
937 #if ENABLE_GPD_MESSAGE
938     MApi_GPD_PrintMem(pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr, 100);
939     GPD_API_INFO("[%s, %td, %tdx%td], CRC result=0x%tx\n", __FUNCTION__,  (ptrdiff_t)u32FileIndex, (ptrdiff_t)pGPDContext->Param.u32Width, (ptrdiff_t)pGPDContext->Param.u32Height,
940         (ptrdiff_t)_MApi_GPD_GetCRCResult((MS_U8 *)pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr, (pGPDContext->Param.u32Height)*(pGPDContext->Param.u32Width)*u8BytesPerPixel, pGPDContext->Param.u32Width, ocolor));
941     GPD_API_INFO("[%s][addr=0x%tx, size=0x%tx] Input CRC result=0x%tx\n", __FUNCTION__,
942         (ptrdiff_t)pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr, (ptrdiff_t)pGPDContext->GpdAddrInfo.u32ReadBufferSize,
943         (ptrdiff_t)MApi_GPD_Input_GetCRCResult((MS_U8 *)pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr,
944         pGPDContext->GpdAddrInfo.u32ReadBufferSize));
945 
946 #endif
947 #endif
948 
949     drv_gpd_power_off();
950     pGPDContext->bIsGPDInit = FALSE;
951     return pGPDContext->Param.enGPDStatus;
952 
953 
954 }
955 
_MApi_GPD_OutputDecodeMGIF(MS_PHY DecodeBuf,MS_U32 ocolor,MS_U32 Size)956 MS_S32 _MApi_GPD_OutputDecodeMGIF(MS_PHY DecodeBuf, MS_U32 ocolor, MS_U32 Size)
957 {
958     //DecodeBuf needs 32-byte alignment
959     //gpd_pic_info info;
960     //gpd_pic_info* param = &info;
961     MS_U8 u8MiuSel = 0;
962     MS_U32 u32Offset = 0;
963     _GPD_SHM_POINTER_CHECK_RETURN(FALSE);
964     _phy_to_miu_offset(u8MiuSel, u32Offset, DecodeBuf);
965     UNUSED(u32Offset);
966     if(pGPDContext->MIUAllocation != u8MiuSel)
967     {
968         GPD_API_INFO("Wrong Memory Allocation\n");
969         pGPDContext->bIsGPDInit = FALSE;
970         return -1;
971     }
972     if(pGPDContext->bIsGPDInit == FALSE)
973     {
974         GPD_API_ERROR("[%s]GPD is not inited\n", __FUNCTION__);
975         return -1;
976     }
977     gpd_roi_info roi;
978     GPD_API_INFO("MApi_GPD_Decode\n");
979     pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr = DecodeBuf;
980     pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr = MsOS_PA2KSEG0(pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr);
981     pGPDContext->GpdAddrInfo.u32WriteBufferSize = Size;
982 
983     if(pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr == 0)
984     {
985         GPD_API_ERROR("Error!! MApi_GPD_OutputDecodeMGIF with DecodeBuf(PA)=0x%tx, VA=0\n", (ptrdiff_t)DecodeBuf);
986         pGPDContext->bIsGPDInit = FALSE;
987         return -1;
988     }
989 
990     memset(&roi, 0, sizeof(roi));
991     mdrv_gpd_setbuf(&pGPDContext->GpdAddrInfo);
992 
993     drv_gpd_set_access_bound(pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr,pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr + pGPDContext->GpdAddrInfo.u32WriteBufferSize - 1,
994                                                     pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr, pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr +CBUFFER_SIZE+ZBUFFER_SIZE-1);
995 
996     GPD_API_INFO("GPDBaseAddr=0x%tx\n",(ptrdiff_t)pGPDContext->GpdAddrInfo.RegBaseAddr);
997     GPD_API_INFO("READBITBaseAddr=0x%tx\n",(ptrdiff_t)pGPDContext->GpdAddrInfo.ReadBitBaseAddr);
998     GPD_API_INFO("Read  buf PA=0x%tx,VA=0x%tx\n",(ptrdiff_t)pGPDContext->GpdAddrInfo.u32PA_ReadBufferAddr,(ptrdiff_t)pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr);
999     GPD_API_INFO("Write buf PA=0x%tx,VA=0x%tx\n",(ptrdiff_t)pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr,(ptrdiff_t)pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr);
1000     GPD_API_INFO("Color buf PA=0x%tx,VA=0x%tx\n",(ptrdiff_t)pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr,(ptrdiff_t)pGPDContext->GpdAddrInfo.u32VA_ColorBufferAddr);
1001     GPD_API_INFO("Depth buf PA=0x%tx,VA=0x%tx\n",(ptrdiff_t)pGPDContext->GpdAddrInfo.u32PA_DepthBufferAddr,(ptrdiff_t)pGPDContext->GpdAddrInfo.u32VA_DepthBufferAddr);
1002     GPD_API_INFO("Read  buf size=0x%tx\n", (ptrdiff_t)pGPDContext->GpdAddrInfo.u32ReadBufferSize);
1003     GPD_API_INFO("Write buf size=0x%tx\n", (ptrdiff_t)pGPDContext->GpdAddrInfo.u32WriteBufferSize);
1004 
1005     mdrv_gpd_decode(&pGPDContext->Param, ocolor, 3, &roi);
1006 
1007 #if (ENABLE_GPD_MESSAGE ||LOG_DATA_TO_USB)
1008     MS_U8 u8BytesPerPixel;
1009     switch(ocolor)
1010     {
1011         case ARGB8888:
1012             u8BytesPerPixel = 4;
1013             break;
1014         case YUV422:
1015         case RGB565:
1016         case YVYU422:
1017         case GRAY_ALPHA:
1018             u8BytesPerPixel = 2;
1019             break;
1020         case GRAY:
1021         default:
1022             u8BytesPerPixel = 1;
1023             break;
1024     }
1025 
1026 #if LOG_DATA_TO_USB
1027     GPD_WRITE_OUTPUT_2_USB((MS_U32)pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr,
1028         (MS_U32)(pGPDContext->Param.u32Height)*(pGPDContext->Param.u32Width)*u8BytesPerPixel, pGPDContext->Param.u32Width, pGPDContext->Param.u32Height, u32FileIndex);
1029 #endif
1030 
1031 #if ENABLE_GPD_MESSAGE
1032     MApi_GPD_PrintMem(pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr, 100);
1033     GPD_API_INFO("[%s, %td, %tdx%td], CRC result=0x%tx\n", __FUNCTION__, (ptrdiff_t)u32FileIndex, (ptrdiff_t)pGPDContext->Param.u32Width, (ptrdiff_t)pGPDContext->Param.u32Height,
1034         (ptrdiff_t)_MApi_GPD_GetCRCResult((MS_U8 *)pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr,(pGPDContext->Param.u32Height)*(pGPDContext->Param.u32Width)*u8BytesPerPixel, pGPDContext->Param.u32Width, ocolor));
1035     GPD_API_INFO("[%s][addr=0x%tx, size=0x%tx] Input CRC result=0x%tx\n", __FUNCTION__,
1036         (ptrdiff_t)pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr, (ptrdiff_t)pGPDContext->GpdAddrInfo.u32ReadBufferSize,
1037         (ptrdiff_t)MApi_GPD_Input_GetCRCResult((MS_U8 *)pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr,
1038         pGPDContext->GpdAddrInfo.u32ReadBufferSize));
1039 
1040 #endif
1041 
1042 #endif
1043 
1044     drv_gpd_power_off();
1045     pGPDContext->bIsGPDInit = FALSE;
1046     return pGPDContext->Param.enGPDStatus;
1047 
1048 
1049 }
1050 
_MApi_GPD_GetDuration(void)1051 MS_S32 _MApi_GPD_GetDuration(void)
1052 {
1053     return MstDGifGetDuration();
1054 }
1055 
_MApi_GPD_SetGIFMode(MS_U32 mode)1056 void _MApi_GPD_SetGIFMode(MS_U32 mode)
1057 {
1058     MstDGifSetMode(mode);
1059 }
1060 
1061 
1062 
_MApi_GPD_OutputDecodeROI(MS_PHY DecodeBuf,MS_U32 ocolor,MS_U32 Size,gpd_roi_info * roi)1063 MS_S32 _MApi_GPD_OutputDecodeROI(MS_PHY DecodeBuf, MS_U32 ocolor, MS_U32 Size, gpd_roi_info *roi)
1064 {
1065     //DecodeBuf needs 32-byte alignment
1066     //gpd_pic_info info;
1067     //gpd_pic_info* param = &info;
1068     MS_U8 u8MiuSel = 0;
1069     MS_U32 u32Offset = 0;
1070     _GPD_SHM_POINTER_CHECK_RETURN(FALSE);
1071     _phy_to_miu_offset(u8MiuSel, u32Offset, DecodeBuf);
1072     UNUSED(u32Offset);
1073     if(pGPDContext->MIUAllocation != u8MiuSel)
1074     {
1075         GPD_API_INFO("Wrong Memory Allocation\n");
1076         pGPDContext->bIsGPDInit = FALSE;
1077         return -1;
1078     }
1079 
1080     if(pGPDContext->bIsGPDInit == FALSE)
1081     {
1082         GPD_API_ERROR("[%s]GPD is not inited\n", __FUNCTION__);
1083         return -1;
1084     }
1085 
1086     GPD_API_INFO("MApi_GPD_DecodeROI\n");
1087     pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr = DecodeBuf;
1088     if (FALSE == drv_gpd_get_cacheable())
1089     {
1090         pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr = MsOS_PA2KSEG1(pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr);
1091     }
1092     else
1093     {
1094         pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr = MsOS_PA2KSEG0(pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr);
1095     }
1096     pGPDContext->GpdAddrInfo.u32WriteBufferSize = Size;
1097 
1098     if(pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr == 0)
1099     {
1100         GPD_API_ERROR("Error!! MApi_GPD_OutputDecodeROI with DecodeBuf(PA)=0x%tx, VA=0\n", (ptrdiff_t)DecodeBuf);
1101         pGPDContext->bIsGPDInit = FALSE;
1102         return -1;
1103     }
1104 
1105 
1106     mdrv_gpd_setbuf(&pGPDContext->GpdAddrInfo);
1107 
1108     drv_gpd_set_access_bound(pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr,pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr + pGPDContext->GpdAddrInfo.u32WriteBufferSize - 1,
1109                                                     pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr, pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr +CBUFFER_SIZE+ZBUFFER_SIZE-1);
1110 
1111     GPD_API_INFO("GPDBaseAddr=0x%tx\n",(ptrdiff_t)pGPDContext->GpdAddrInfo.RegBaseAddr);
1112     GPD_API_INFO("READBITBaseAddr=0x%tx\n",(ptrdiff_t)pGPDContext->GpdAddrInfo.ReadBitBaseAddr);
1113     GPD_API_INFO("Read  buf PA=0x%tx,VA=0x%tx\n",(ptrdiff_t)pGPDContext->GpdAddrInfo.u32PA_ReadBufferAddr,(ptrdiff_t)pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr);
1114     GPD_API_INFO("Write buf PA=0x%tx,VA=0x%tx\n",(ptrdiff_t)pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr,(ptrdiff_t)pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr);
1115     GPD_API_INFO("Color buf PA=0x%tx,VA=0x%tx\n",(ptrdiff_t)pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr,(ptrdiff_t)pGPDContext->GpdAddrInfo.u32VA_ColorBufferAddr);
1116     GPD_API_INFO("Color buf PA=0x%tx,VA=0x%tx\n",(ptrdiff_t)pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr,(ptrdiff_t)pGPDContext->GpdAddrInfo.u32VA_ColorBufferAddr);
1117     GPD_API_INFO("Depth buf PA=0x%tx,VA=0x%tx\n",(ptrdiff_t)pGPDContext->GpdAddrInfo.u32PA_DepthBufferAddr,(ptrdiff_t)pGPDContext->GpdAddrInfo.u32VA_DepthBufferAddr);
1118     GPD_API_INFO("Read  buf size=0x%tx\n", (ptrdiff_t)pGPDContext->GpdAddrInfo.u32ReadBufferSize);
1119     GPD_API_INFO("Write buf size=0x%tx\n", (ptrdiff_t)pGPDContext->GpdAddrInfo.u32WriteBufferSize);
1120 
1121 #if ENABLE_GPD_MESSAGE
1122 //    memset((void *)pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr, 0x37, (size_t)pGPDContext->GpdAddrInfo.u32WriteBufferSize);
1123 #endif
1124     mdrv_gpd_decode(&pGPDContext->Param, ocolor, 2, roi);
1125 
1126 #if (ENABLE_GPD_MESSAGE || LOG_DATA_TO_USB)
1127 
1128     MS_U8 u8BytesPerPixel;
1129     switch(ocolor)
1130     {
1131         case ARGB8888:
1132             u8BytesPerPixel = 4;
1133             break;
1134         case YUV422:
1135         case RGB565:
1136         case YVYU422:
1137         case GRAY_ALPHA:
1138             u8BytesPerPixel = 2;
1139             break;
1140         case GRAY:
1141         default:
1142             u8BytesPerPixel = 1;
1143             break;
1144     }
1145 
1146 #if LOG_DATA_TO_USB
1147     GPD_WRITE_OUTPUT_2_USB((MS_U32)pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr,
1148         (MS_U32)(roi->height)*(roi->width)*u8BytesPerPixel, roi->width, roi->height, u32FileIndex);
1149 #endif
1150 
1151 #if ENABLE_GPD_MESSAGE
1152     MApi_GPD_PrintMem(pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr, 100);
1153     MS_U32 u32OutputCRC = _MApi_GPD_GetCRCResult((MS_U8 *)pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr,(MS_U32) (roi->height)*(roi->width)*u8BytesPerPixel, roi->width, ocolor);
1154     GPD_API_INFO("[%s, %td, %tdx%td], CRC result=0x%tx\n", __FUNCTION__, (ptrdiff_t)u32FileIndex, (ptrdiff_t)roi->width, (ptrdiff_t)roi->height,
1155         (ptrdiff_t)u32OutputCRC);
1156     GPD_API_INFO("[%s][addr=0x%tx, size=0x%tx] Input CRC result=0x%tx\n", __FUNCTION__,
1157         (ptrdiff_t)pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr, (ptrdiff_t)pGPDContext->GpdAddrInfo.u32ReadBufferSize,
1158         (ptrdiff_t)MApi_GPD_Input_GetCRCResult((MS_U8 *)pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr,
1159         pGPDContext->GpdAddrInfo.u32ReadBufferSize));
1160 
1161 #endif
1162 #endif
1163 
1164     drv_gpd_power_off();
1165     pGPDContext->bIsGPDInit = FALSE;
1166     return pGPDContext->Param.enGPDStatus;
1167 
1168 
1169 }
1170 
1171 
1172 #ifdef CONFIG_UTOPIA_PROC_DBG_SUPPORT
_MApi_GPD_GetMdbInfo(MS_U64 * u64ReqHdl)1173 void _MApi_GPD_GetMdbInfo(MS_U64* u64ReqHdl)
1174 {
1175     MdbPrint(u64ReqHdl,"---------MStar GPD Info---------\n\n");
1176     MdbPrint(u64ReqHdl,"Input buffer address PA               : 0x%lx\n", gGPDMDebug._u32ReadBufferAddr_PA);
1177     MdbPrint(u64ReqHdl,"Output buffer address PA              : 0x%lx\n", gGPDMDebug._u32WriteBufferAddr_PA);
1178     MdbPrint(u64ReqHdl,"Internal buffer address PA            : 0x%lx\n", gGPDMDebug._u32InternalBufferAddr_PA);
1179     MdbPrint(u64ReqHdl,"Input buffer address VA               : 0x%lx\n", gGPDMDebug._u32ReadBufferAddr);
1180 #ifndef MSOS_TYPE_LINUX_KERNEL
1181     MdbPrint(u64ReqHdl,"Output buffer address VA              : 0x%lx\n", gGPDMDebug._u32WriteBufferAddr);
1182 #endif
1183     MdbPrint(u64ReqHdl,"Internal buffer address VA            : 0x%lx\n", gGPDMDebug._u32InternalBufferAddr);
1184     MdbPrint(u64ReqHdl,"Input buffer size                     : 0x%lx\n", gGPDMDebug._u32ReadBufferSize);
1185     MdbPrint(u64ReqHdl,"Output buffer size                    : 0x%lx\n", gGPDMDebug._u32WriteBufferSize);
1186     MdbPrint(u64ReqHdl,"Internal buffer size                  : 0x%lx\n", gGPDMDebug._u32InternalBufferSize);
1187     MdbPrint(u64ReqHdl,"Picture resolution                    : %dx%d\n", gGPDMDebug._u16Image_x_size, gGPDMDebug._u16Image_y_size);
1188 
1189     switch(gGPDMDebug.ocolor)
1190     {
1191         case ARGB8888:
1192             MdbPrint(u64ReqHdl,"Output format                         : ARGB8888\n");
1193             break;
1194         case YUV422:
1195             MdbPrint(u64ReqHdl,"Output format                         : YUV422\n");
1196             break;
1197         case RGB565:
1198             MdbPrint(u64ReqHdl,"Output format                         : RGB565\n");
1199             break;
1200         case YVYU422:
1201             MdbPrint(u64ReqHdl,"Output format                         : YVYU422\n");
1202             break;
1203         case GRAY_ALPHA:
1204             MdbPrint(u64ReqHdl,"Output format                         : GRAY_ALPHA\n");
1205             break;
1206         case GRAY:
1207             MdbPrint(u64ReqHdl,"Output format                         : GRAY\n");
1208             break;
1209         default:
1210             break;
1211     }
1212 
1213     if(gGPDMDebug.bPNG)
1214     {
1215         MdbPrint(u64ReqHdl,"Picture type                          : png\n");
1216     }
1217     else
1218     {
1219         MdbPrint(u64ReqHdl,"Picture type                          : gif\n");
1220     }
1221 
1222 
1223     MdbPrint(u64ReqHdl,"HW decoding time                      : %dms\n", gGPDMDebug._u32HWEndTime - gGPDMDebug._u32HWStartTime);
1224 }
1225 #endif
1226 
1227 
1228 #else
1229 
MAdp_GPD_Init(void)1230 void* MAdp_GPD_Init(void)
1231 {
1232     MS_S32 err;
1233     //MS_U32 size=0;
1234     MS_S32 tmp;
1235 
1236     console_printf("MAdp_GPD_Init\n");
1237 
1238     pGPDContext->GpdAddrInfo.RegBaseAddr = (MS_U32)GPD_RIU_BASE;
1239     pGPDContext->GpdAddrInfo.ReadBitBaseAddr = (MS_U32)GPD_XIU_BASE;
1240 
1241 #if 0
1242 
1243    *((volatile MS_U32 *)(CLK_GEN_BASE + (0x5E << 1))) = 0;   // 0x2f << 2
1244 
1245 #else
1246 
1247     *((volatile MS_U32 *) (CLK_GEN_BASE + (0x50 << 1))) = 0;   // 0x28 << 2
1248     //*((volatile MS_U32 *) (CLK_GEN_BASE + (0x50 << 1))) = (2 << 2);   // 0x28 << 2
1249 
1250 #endif
1251 
1252     //set gpd miu channel
1253 
1254 #if 1
1255     tmp = *((volatile MS_U32 *)((MS_U32)MIU_CLI_BASE + (0xf4 << 1)));
1256 
1257 
1258     if ((MS_U32)CBUFFER & (1 << 29))  //512mb
1259     {
1260         tmp |= (0x40);  // bit 6
1261         console_printf("Select MIU1\n");
1262     }
1263     else
1264     {
1265         tmp &= (~0x40);
1266         console_printf("Select MIU0\n");
1267 
1268     }
1269 
1270     *((volatile MS_U32 *)((MS_U32)MIU_CLI_BASE +(0xf4 << 1))) = tmp;
1271 #endif
1272 
1273 #if 0
1274     *((volatile MS_U32 *)((MS_U32)MIU_CLI_BASE +(0x67 << 2))) = 0x26;
1275 
1276     *((volatile MS_U32 *)((MS_U32)MIU_CLI_BASE +(0x68 << 2))) = 0x8800;
1277 
1278     *((volatile MS_U32 *)((MS_U32)MIU_CLI_BASE +(0x69 << 2))) = 0x9800;
1279 
1280     *((volatile MS_U32 *)((MS_U32)MIU_CLI_BASE +(0x60 << 2))) = 0x2;
1281 
1282     console_printf("Enable MIU Protection\n");
1283 #endif
1284 
1285     pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr = (MS_U32)CBUFFER;
1286     pGPDContext->GpdAddrInfo.u32VA_ColorBufferAddr = MsOS_PA2KSEG1(pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr);
1287 
1288     console_printf("Get Color buffer\n");
1289 
1290     pGPDContext->GpdAddrInfo.u32PA_DepthBufferAddr = (MS_U32)ZBUFFER;
1291     pGPDContext->GpdAddrInfo.u32VA_DepthBufferAddr = MsOS_PA2KSEG1(pGPDContext->GpdAddrInfo.u32PA_DepthBufferAddr);
1292 
1293     console_printf("Get Depth buffer\n");
1294 
1295     pGPDContext->GpdAddrInfo.u32PA_ReadBufferAddr = (MS_U32)STREAMBUFFER;
1296     pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr = MsOS_PA2KSEG1(pGPDContext->GpdAddrInfo.u32PA_ReadBufferAddr);
1297 
1298     console_printf("Get Read buffer\n");
1299 
1300     pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr = (MS_U32)FRAMEBUFFER;
1301     pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr = MsOS_PA2KSEG1(pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr);
1302 
1303     console_printf("Get Write buffer\n");
1304 
1305     pGPDContext->GpdAddrInfo.u32WriteBufferSize = FRAMEBUFFER_SIZE;
1306 
1307 
1308     console_printf("GPDBaseAddr=0x%08x\n",pGPDContext->GpdAddrInfo.RegBaseAddr);
1309     console_printf("READBITBaseAddr=0x%08x\n",pGPDContext->GpdAddrInfo.ReadBitBaseAddr);
1310     console_printf("Read  buf PA=0x%08x,VA=0x%08x\n",pGPDContext->GpdAddrInfo.u32PA_ReadBufferAddr,pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr);
1311     console_printf("Write buf PA=0x%08x,VA=0x%08x\n",pGPDContext->GpdAddrInfo.u32PA_WriteBufferAddr,pGPDContext->GpdAddrInfo.u32VA_WriteBufferAddr);
1312     console_printf("Color buf PA=0x%08x,VA=0x%08x\n",pGPDContext->GpdAddrInfo.u32PA_ColorBufferAddr,pGPDContext->GpdAddrInfo.u32VA_ColorBufferAddr);
1313     console_printf("Depth buf PA=0x%08x,VA=0x%08x\n",pGPDContext->GpdAddrInfo.u32PA_DepthBufferAddr,pGPDContext->GpdAddrInfo.u32VA_DepthBufferAddr);
1314     console_printf("Read  buf size=0x%08x\n", pGPDContext->GpdAddrInfo.u32ReadBufferSize);
1315     console_printf("Write buf size=0x%08x\n", pGPDContext->GpdAddrInfo.u32WriteBufferSize);
1316 
1317 
1318     //Call mdrv_gpd_init, This should include Color-buffer, Z-buffer, Bitstream buffer, Frame Buffer.
1319     err = mdrv_gpd_init(&pGPDContext->GpdAddrInfo);
1320 
1321 
1322 
1323     return &pGPDContext->GpdAddrInfo;
1324 
1325 }
1326 
MAdp_GPD_Play(gpd_pic_info * param,MS_U32 ocolor,MS_U8 * srcbuffer,MS_U32 size)1327 MS_S32 MAdp_GPD_Play(gpd_pic_info* param, MS_U32 ocolor, MS_U8 *srcbuffer, MS_U32 size)
1328 {
1329 
1330     extern void *memcpy(void *destination, const void *source, size_t num);
1331     //FILE *hFile = 0;
1332     //long lSize,i=0;
1333     //size_t result;
1334     //MS_U32 i = 0;
1335     gpd_roi_info roi;
1336     //MS_U8 sig[10];
1337     //FILE *fp;
1338 
1339     console_printf("MAdp_GPD_Play\n");
1340 
1341     pGPDContext->Param = param;
1342     memset(&roi, 0, sizeof(roi));
1343     mdrv_gpd_setbuf(&pGPDContext->GpdAddrInfo);
1344 
1345 
1346     #if 1
1347 
1348     console_printf("size:%d\n",size);
1349 
1350     memcpy((void *)pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr, (void *)srcbuffer, size);
1351 
1352     pGPDContext->GpdAddrInfo.u32ReadBufferSize = size;
1353 
1354     console_printf("copy image done\n");
1355 
1356     #endif
1357 
1358 
1359     #if 0
1360     hFile = fopen(param->filename, "rb");
1361     if(!hFile)
1362     {
1363         console_printf("Open file error=%s!!\n",param->filename);
1364         return -1;
1365     }
1366     // obtain file size:
1367     fseek (hFile , 0 , SEEK_END);
1368     lSize = ftell (hFile);
1369     rewind (hFile);
1370 
1371     //fread file into bitstream buffer
1372     result = fread ((char *)pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr,1,lSize,hFile);
1373 
1374     #endif
1375 
1376 #if 0
1377     sig[0] = MMIO8(pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr);
1378     sig[1] = MMIO8(pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr+1);
1379     sig[2] = MMIO8(pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr+2);
1380     sig[3] = MMIO8(pGPDContext->GpdAddrInfo.u32VA_ReadBufferAddr+3);
1381     console_printf("Signaute = %x,%x,%x,%x\n",sig[0],sig[1],sig[2],sig[3]);
1382 #endif
1383     //Call mdrv_gpd_decode, specify output format;ARGB888/YUV422/RGB565
1384 
1385     #if 0
1386     roi.hstart = 0;
1387     roi.vstart = 0;
1388     roi.width = 64;
1389     roi.height = 64;
1390     #endif
1391 
1392     mdrv_gpd_decode(pGPDContext->Param, ocolor, 0, &roi);
1393 
1394     return pGPDContext->Param.enGPDStatus;
1395 }
1396 
1397 
MAdp_GPD_Compare(MS_U32 ocolor_typ)1398 MS_S32 MAdp_GPD_Compare(MS_U32 ocolor_typ)
1399 {
1400 
1401     extern MS_U32 memcmp(const void *ptr1, const void *ptr2, size_t num);
1402 
1403     MS_U32 frameptr, argbptr;
1404 
1405     MS_U32 hw_extra = 0, sw_extra = 0;
1406 
1407     MS_U32 pixelbytes = 0;
1408 
1409     MS_U32 width, height;
1410 
1411     MS_U32 result = 0;
1412 
1413     frameptr = MsOS_PA2KSEG1(FRAMEBUFFER);
1414 
1415     argbptr = MsOS_PA2KSEG1(ARGBBUFFER);
1416 
1417     console_printf("MAdp_GPD_Compare\n");
1418 
1419     #if 0
1420 
1421     console_printf("size:%d\n",size);
1422 
1423     memcpy((void *)ARGBBUFFER,(void *)srcbuffer,size);
1424 
1425     console_printf("copy image done\n");
1426 
1427     #endif
1428 
1429     width = pGPDContext->Param.u32Width;
1430 
1431     height = pGPDContext->Param.u32Height;
1432 
1433     console_printf("height:%d width:%d\n", height, width);
1434 
1435 
1436     switch (ocolor_typ)
1437     {
1438     case ARGB8888:
1439         pixelbytes = 4;
1440         if((width * pixelbytes) % 8)
1441             hw_extra = 8 - ((width * pixelbytes) % 8); break;
1442     case YUV422:
1443     case YVYU422:
1444         if(width & 1)
1445             sw_extra = 2;
1446     case RGB565:
1447     case GRAY_ALPHA:
1448         pixelbytes = 2;
1449         if((width * pixelbytes) % 8)
1450             hw_extra = 8 - ((width * pixelbytes) % 8); break;
1451     case GRAY:
1452         pixelbytes = 1;
1453         if((width * pixelbytes) % 8)
1454             hw_extra = 8 - ((width * pixelbytes) % 8); break;
1455     default:
1456         console_printf("Unsupported output color %d\n", ocolor_typ);
1457         return NULL;
1458     }
1459 
1460 
1461     while(height)
1462     {
1463 
1464         result = memcmp((void *) frameptr,(void *) argbptr, width * pixelbytes);
1465 
1466         if(result)
1467         {
1468             console_printf("compare failed\n");
1469 
1470             return result;
1471         }
1472 
1473         frameptr += width * pixelbytes + hw_extra;
1474 
1475         argbptr += width * pixelbytes + sw_extra;
1476 
1477         height--;
1478     }
1479 
1480     return 0;
1481 
1482 }
1483 
1484 
1485 #endif
1486 
_MApi_GPD_ScalingEnable(MS_U32 mode)1487 void _MApi_GPD_ScalingEnable(MS_U32 mode)
1488 {
1489 
1490     _GPD_SHM_POINTER_CHECK();
1491 
1492     mdrv_gpd_scaling_init(1, mode);
1493 
1494     GPD_API_INFO("GPD Scaling Enable, mode = %td\n", (ptrdiff_t)mode);
1495 }
1496 
1497 
1498 
_MApi_GPD_ScalingDisable(void)1499 void _MApi_GPD_ScalingDisable(void)
1500 {
1501     _GPD_SHM_POINTER_CHECK();
1502 
1503     mdrv_gpd_scaling_init(0, 0);
1504 
1505     GPD_API_INFO("GPD Scaling Disable\n");
1506 }
1507 
1508 
_MApi_GPD_SetControl(gpd_user_cmd cmd_id,MS_VIRT param)1509 MS_U32 _MApi_GPD_SetControl(gpd_user_cmd cmd_id, MS_VIRT param)
1510 {
1511     _GPD_Init_Share_Mem();
1512     _GPD_SHM_POINTER_CHECK_RETURN(FALSE);
1513     switch (cmd_id)
1514     {
1515         case E_GPD_USER_CMD_SET_ACCESS_REGION:
1516             return _GPD_SetAccessRegion((gpd_access_region *)param);
1517 
1518 	case E_GPD_USER_CMD_SET_CACHEABLE:
1519             return _GPD_SetCacheable((MS_U32)param);
1520 	case E_GPD_USER_CMD_SET_DEBUG_LEVEL:
1521             eEnableDbgMsg = (gpd_debug_level)param;
1522             return TRUE;
1523 
1524         default:
1525             return FALSE;
1526 
1527     }
1528 
1529 }
1530 
1531 
_MApi_GPD_GetControl(gpd_get_cmd cmd_id,MS_VIRT param)1532 MS_U32 _MApi_GPD_GetControl(gpd_get_cmd cmd_id, MS_VIRT param)
1533 {
1534     _GPD_SHM_POINTER_CHECK_RETURN(FALSE);
1535     switch (cmd_id)
1536     {
1537         case E_GPD_GET_CMD_GET_PITCH:
1538             return _GPD_GetPitch((gpd_get_pitch_info *)param);
1539         default:
1540             return FALSE;
1541     }
1542 
1543 }
1544 
1545 static MS_U32  u32CRC;
1546 
verGPD_CRC32_Init(void)1547 static void verGPD_CRC32_Init(void)
1548 {
1549     u32CRC = 0xFFFFFFFF;
1550 }
1551 
1552 
verGPD_CRC32_GetResult(void)1553 static MS_U32 verGPD_CRC32_GetResult(void)
1554 {
1555     return (~u32CRC);
1556 }
1557 
1558 
verGPD_Init_CRC_Table(MS_U32 * u32CRCtemptable)1559 static void verGPD_Init_CRC_Table(MS_U32 *u32CRCtemptable)
1560 {
1561 
1562     MS_U32 i,j,tmp, result;
1563 
1564     for(i=0;i<=0xFF;i++)
1565     {
1566         tmp=i;
1567         result=0;
1568 
1569         for(j=1;j<9;j++)
1570         {
1571              if(tmp & 1)
1572              {
1573                         result |= (1 << (8 - j));
1574              }
1575              tmp >>= 1;
1576         }
1577 
1578         u32CRCtemptable[i]=result<<24;
1579         for(j=0; j<8; j++)
1580         {
1581             u32CRCtemptable[i] = (u32CRCtemptable[i] << 1) ^ ((u32CRCtemptable[i] & (1 << 31)) ? 0x04C11DB7UL : 0);
1582         }
1583 
1584         tmp=u32CRCtemptable[i];
1585         result=0;
1586 
1587         for(j=1;j<33;j++)
1588         {
1589              if(tmp & 1)
1590              {
1591                 result |= (1 << (32 - j));
1592              }
1593              tmp >>= 1;
1594         }
1595         u32CRCtemptable[i]=result;
1596         }
1597 }
1598 
verGPD_CRC32_Update(const MS_U8 * pu8Data,MS_U32 u32Size,MS_U32 u32Width,MS_U32 ocolor)1599 static void verGPD_CRC32_Update(const MS_U8 *pu8Data, MS_U32 u32Size, MS_U32 u32Width, MS_U32 ocolor)
1600 {
1601     MS_U32 u32CRCTable[256];
1602     MS_U32  u32LoopCounter;
1603     MS_U8 u8BytesPerPixel;
1604     switch(ocolor)
1605     {
1606         case ARGB8888:
1607             u8BytesPerPixel = 4;
1608             break;
1609         case YUV422:
1610         case RGB565:
1611         case YVYU422:
1612         case GRAY_ALPHA:
1613             u8BytesPerPixel = 2;
1614             break;
1615         case GRAY:
1616         default:
1617             u8BytesPerPixel = 1;
1618             break;
1619     }
1620 
1621     if (pu8Data == NULL || u32Size == 0) return;
1622 
1623     verGPD_Init_CRC_Table(u32CRCTable);
1624 
1625     if((u32Width*u8BytesPerPixel)%8 ==0)
1626     {
1627         for (u32LoopCounter=0; u32LoopCounter<u32Size; u32LoopCounter++)
1628         {
1629             u32CRC = (u32CRC >> 8) ^ u32CRCTable[ pu8Data[u32LoopCounter] ^ (MS_U8)(u32CRC & 0xFF) ];
1630         }
1631     }
1632     else
1633     {
1634         MS_U32 u32LoopCounter2;
1635         MS_U32 u32WidthAlign;
1636         u32WidthAlign = u32Width + ((u32Width*u8BytesPerPixel)%8)/u8BytesPerPixel;
1637 
1638         for (u32LoopCounter=0; u32LoopCounter<u32Size/(u32Width*u8BytesPerPixel)*(u32WidthAlign*u8BytesPerPixel); u32LoopCounter+=u32WidthAlign*u8BytesPerPixel)
1639             for(u32LoopCounter2=0; u32LoopCounter2<u32Width*4; u32LoopCounter2++)
1640             {
1641                 u32CRC = (u32CRC >> 8) ^ u32CRCTable[ pu8Data[u32LoopCounter+u32LoopCounter2] ^ (MS_U8)(u32CRC & 0xFF) ];
1642             }
1643     }
1644 }
1645 
_MApi_GPD_GetCRCResult(const MS_U8 * pu8Data,MS_U32 u32Size,MS_U32 u32Width,MS_U32 ocolor)1646 MS_U32 _MApi_GPD_GetCRCResult(const MS_U8 *pu8Data, MS_U32 u32Size, MS_U32 u32Width, MS_U32 ocolor)
1647 {
1648     verGPD_CRC32_Init();
1649     verGPD_CRC32_Update(pu8Data, u32Size, u32Width, ocolor);
1650     return verGPD_CRC32_GetResult();
1651 }
1652 
1653 
1654 
verGPD_Input_CRC32_Init(void)1655 static void verGPD_Input_CRC32_Init(void)
1656 {
1657     u32CRC = 0xFFFFFFFFUL;
1658 }
1659 
1660 
verGPD_Input_CRC32_GetResult(void)1661 static MS_U32 verGPD_Input_CRC32_GetResult(void)
1662 {
1663     return (~u32CRC);
1664 }
1665 
1666 
verGPD_Input_Init_CRC_Table(MS_U32 * u32CRCtemptable)1667 static void verGPD_Input_Init_CRC_Table(MS_U32 *u32CRCtemptable)
1668 {
1669 
1670     MS_U32 i,j,tmp, result;
1671 
1672     for(i=0;i<=0xFF;i++)
1673     {
1674         tmp=i;
1675         result=0;
1676 
1677         for(j=1;j<9;j++)
1678         {
1679              if(tmp & 1)
1680              {
1681                         result |= (1 << (8 - j));
1682              }
1683              tmp >>= 1;
1684         }
1685 
1686         u32CRCtemptable[i]=result<<24;
1687         for(j=0; j<8; j++)
1688         {
1689             u32CRCtemptable[i] = (u32CRCtemptable[i] << 1) ^ ((u32CRCtemptable[i] & (1 << 31)) ? 0x04C11DB7UL : 0);
1690         }
1691 
1692         tmp=u32CRCtemptable[i];
1693         result=0;
1694 
1695         for(j=1;j<33;j++)
1696         {
1697              if(tmp & 1)
1698              {
1699                 result |= (1 << (32 - j));
1700              }
1701              tmp >>= 1;
1702         }
1703         u32CRCtemptable[i]=result;
1704         }
1705 }
1706 
verGPD_Input_CRC32_Update(const MS_U8 * pu8Data,MS_U32 u32Size)1707 static void verGPD_Input_CRC32_Update(const MS_U8 *pu8Data, MS_U32 u32Size)
1708 {
1709     MS_U32 u32CRCTable[256];
1710     MS_U32  u32LoopCounter;
1711 
1712     if (pu8Data == NULL || u32Size == 0) return;
1713 
1714     verGPD_Input_Init_CRC_Table(u32CRCTable);
1715 
1716     #if 0
1717         MS_U32 i;
1718         for(i = 0;i<256;i++)
1719         {
1720             printf("0x%08x,\n", u32CRCTable[i]);
1721         }
1722     #endif
1723 
1724     for (u32LoopCounter=0; u32LoopCounter<u32Size; u32LoopCounter++)
1725     {
1726         u32CRC = (u32CRC >> 8) ^ u32CRCTable[ pu8Data[u32LoopCounter] ^ (MS_U8)(u32CRC & 0xFF) ];
1727     }
1728 }
1729 
MApi_GPD_Input_GetCRCResult(const MS_U8 * pu8Data,MS_U32 u32Size)1730 MS_U32 MApi_GPD_Input_GetCRCResult(const MS_U8 *pu8Data, MS_U32 u32Size)
1731 {
1732     verGPD_Input_CRC32_Init();
1733     verGPD_Input_CRC32_Update(pu8Data, u32Size);
1734     return verGPD_Input_CRC32_GetResult();
1735 }
1736 
1737 
MApi_GPD_Init(MS_PHY SrcBuf)1738 void *MApi_GPD_Init(MS_PHY SrcBuf)
1739 {
1740     if (pInstantGPD == NULL)
1741     {
1742         if(UtopiaOpen(MODULE_GPD | GPD_DRIVER_BASE, &pInstantGPD, 0, NULL) !=  UTOPIA_STATUS_SUCCESS)
1743         {
1744             GPD_API_ERROR("Open GPD fail\n");
1745             return FALSE;
1746         }
1747     }
1748 #ifdef UTOPIA_20
1749     if(pInstantGPD==NULL)
1750     {
1751         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1752         return FALSE;
1753     }
1754     GPD_INIT_PARAM InitPara;
1755     memset(&InitPara , 0 ,sizeof(GPD_INIT_PARAM));
1756     InitPara.SrcBuf = SrcBuf;
1757     GPD_API_INFO("UtopiaIoctl(): MApi_CMD_GPD_Init\n");
1758     if(UtopiaIoctl(pInstantGPD,MApi_CMD_GPD_Init, (void*)(&InitPara)) != UTOPIA_STATUS_SUCCESS)
1759     {
1760         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1761         return FALSE;
1762     }
1763     return FALSE;
1764 #else
1765     return _MApi_GPD_Init(SrcBuf);
1766 #endif
1767 
1768 }
1769 
1770 
MApi_GPD_InputSource(gpd_pic_info * param,MS_PHY InputBuf,MS_U32 Size)1771 MS_S32 MApi_GPD_InputSource(gpd_pic_info* param, MS_PHY InputBuf, MS_U32 Size)
1772 {
1773 #ifdef UTOPIA_20
1774     if(pInstantGPD==NULL)
1775     {
1776         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1777         return FALSE;
1778     }
1779 
1780     GPD_INPUTSOURCE_PARAM InputPara;
1781     memset(&InputPara , 0 ,sizeof(GPD_INPUTSOURCE_PARAM));
1782     InputPara.param = param;
1783     InputPara.InputBuf = InputBuf;
1784     InputPara.Size = Size;
1785     GPD_API_INFO("UtopiaIoctl(): MApi_CMD_GPD_InputSource\n");
1786     if(UtopiaIoctl(pInstantGPD,MApi_CMD_GPD_InputSource, (void*)(&InputPara)) != UTOPIA_STATUS_SUCCESS)
1787     {
1788         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1789         return FALSE;
1790     }
1791     return InputPara.retVal;
1792 #else
1793     return _MApi_GPD_InputSource(param, InputBuf, Size);
1794 #endif
1795 }
1796 
MApi_GPD_OutputDecode(MS_PHY DecodeBuf,MS_U32 ocolor,MS_U32 Size)1797 MS_S32 MApi_GPD_OutputDecode(MS_PHY DecodeBuf, MS_U32 ocolor, MS_U32 Size)
1798 {
1799 #ifdef UTOPIA_20
1800     if(pInstantGPD==NULL)
1801     {
1802         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1803         return FALSE;
1804     }
1805 
1806     GPD_OUTPUTDECODE_PARAM OutputPara;
1807     memset(&OutputPara , 0 ,sizeof(GPD_OUTPUTDECODE_PARAM));
1808     OutputPara.DecodeBuf = DecodeBuf;
1809     OutputPara.ocolor = ocolor;
1810     OutputPara.Size = Size;
1811     GPD_API_INFO("UtopiaIoctl(): MApi_CMD_GPD_OutputDecode\n");
1812     if(UtopiaIoctl(pInstantGPD,MApi_CMD_GPD_OutputDecode, (void*)(&OutputPara)) != UTOPIA_STATUS_SUCCESS)
1813     {
1814         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1815         return FALSE;
1816     }
1817     else
1818     {
1819         if(UtopiaClose(pInstantGPD) != UTOPIA_STATUS_SUCCESS)
1820         {
1821             GPD_API_ERROR("Utopia Close GPD failed\n");
1822             return OutputPara.retVal;
1823         }
1824         pInstantGPD = NULL;
1825     }
1826     return OutputPara.retVal;
1827 #else
1828     return _MApi_GPD_OutputDecode(DecodeBuf, ocolor, Size);
1829 #endif
1830 }
1831 
MApi_GPD_OutputDecodeMGIF(MS_PHY DecodeBuf,MS_U32 ocolor,MS_U32 Size)1832 MS_S32 MApi_GPD_OutputDecodeMGIF(MS_PHY DecodeBuf, MS_U32 ocolor, MS_U32 Size)
1833 {
1834 #ifdef UTOPIA_20
1835     if(pInstantGPD==NULL)
1836     {
1837         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1838         return FALSE;
1839     }
1840 
1841     GPD_OUTPUTDECODE_PARAM OutputPara;
1842     memset(&OutputPara , 0 ,sizeof(GPD_OUTPUTDECODE_PARAM));
1843     OutputPara.DecodeBuf = DecodeBuf;
1844     OutputPara.ocolor = ocolor;
1845     OutputPara.Size = Size;
1846     GPD_API_INFO("UtopiaIoctl(): MApi_CMD_GPD_OutputDecodeMGIF\n");
1847     if(UtopiaIoctl(pInstantGPD,MApi_CMD_GPD_OutputDecodeMGIF, (void*)(&OutputPara)) != UTOPIA_STATUS_SUCCESS)
1848     {
1849         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1850         return FALSE;
1851     }
1852     else
1853     {
1854         if(UtopiaClose(pInstantGPD) != UTOPIA_STATUS_SUCCESS)
1855         {
1856             GPD_API_ERROR("Utopia Close GPD failed\n");
1857             return OutputPara.retVal;
1858         }
1859         pInstantGPD = NULL;
1860     }
1861     return OutputPara.retVal;
1862 #else
1863     return _MApi_GPD_OutputDecodeMGIF(DecodeBuf, ocolor, Size);
1864 #endif
1865 }
1866 
MApi_GPD_GetDuration(void)1867 MS_S32 MApi_GPD_GetDuration(void)
1868 {
1869 #ifdef UTOPIA_20
1870     if(pInstantGPD==NULL)
1871     {
1872         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1873         return FALSE;
1874     }
1875 
1876     GPD_GETDURATION_PARAM GetDuration;
1877     memset(&GetDuration , 0 ,sizeof(GPD_GETDURATION_PARAM));
1878     GPD_API_INFO("UtopiaIoctl(): MApi_CMD_GPD_GetDuration\n");
1879     if(UtopiaIoctl(pInstantGPD,MApi_CMD_GPD_GetDuration, (void*)(&GetDuration)) != UTOPIA_STATUS_SUCCESS)
1880     {
1881         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1882         return FALSE;
1883     }
1884     return GetDuration.retVal;
1885 #else
1886     return _MApi_GPD_GetDuration();
1887 #endif
1888 
1889 }
1890 
1891 
MApi_GPD_SetGIFMode(MS_U32 mode)1892 void MApi_GPD_SetGIFMode(MS_U32 mode)
1893 {
1894 #ifdef UTOPIA_20
1895     if(pInstantGPD==NULL)
1896     {
1897         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1898         return;
1899     }
1900 
1901     GPD_SETGIFMODE_PARAM GIFMode;
1902     memset(&GIFMode , 0 ,sizeof(GPD_SETGIFMODE_PARAM));
1903     GIFMode.mode = mode;
1904     GPD_API_INFO("UtopiaIoctl(): MApi_CMD_GPD_SetGIFMode\n");
1905     if(UtopiaIoctl(pInstantGPD,MApi_CMD_GPD_SetGIFMode, (void*)(&GIFMode)) != UTOPIA_STATUS_SUCCESS)
1906     {
1907         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1908         return;
1909     }
1910     return;
1911 #else
1912     _MApi_GPD_SetGIFMode(mode);
1913 #endif
1914 
1915 }
1916 
MApi_GPD_OutputDecodeROI(MS_PHY DecodeBuf,MS_U32 ocolor,MS_U32 Size,gpd_roi_info * roi)1917 MS_S32 MApi_GPD_OutputDecodeROI(MS_PHY DecodeBuf, MS_U32 ocolor, MS_U32 Size, gpd_roi_info *roi)
1918 {
1919 #ifdef UTOPIA_20
1920     if(pInstantGPD==NULL)
1921     {
1922         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1923         return FALSE;
1924     }
1925 
1926     GPD_OUTPUTDECODEROI_PARAM OutputParaROI;
1927     memset(&OutputParaROI , 0 ,sizeof(GPD_OUTPUTDECODEROI_PARAM));
1928     OutputParaROI.DecodeBuf = DecodeBuf;
1929     OutputParaROI.ocolor = ocolor;
1930     OutputParaROI.Size = Size;
1931     OutputParaROI.roi = roi;
1932     GPD_API_INFO("UtopiaIoctl(): MApi_CMD_GPD_OutputDecodeROI\n");
1933     if(UtopiaIoctl(pInstantGPD,MApi_CMD_GPD_OutputDecodeROI, (void*)(&OutputParaROI)) != UTOPIA_STATUS_SUCCESS)
1934     {
1935         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1936         return FALSE;
1937     }
1938     else
1939     {
1940         if(UtopiaClose(pInstantGPD) != UTOPIA_STATUS_SUCCESS)
1941         {
1942             GPD_API_ERROR("Utopia Close GPD failed\n");
1943             return OutputParaROI.retVal;
1944         }
1945         pInstantGPD = NULL;
1946     }
1947     return OutputParaROI.retVal;
1948 #else
1949     return _MApi_GPD_OutputDecodeROI(DecodeBuf, ocolor, Size, roi);
1950 #endif
1951 
1952 }
1953 
MApi_GPD_ScalingEnable(MS_U32 mode)1954 void MApi_GPD_ScalingEnable(MS_U32 mode)
1955 {
1956 #ifdef UTOPIA_20
1957     if(pInstantGPD==NULL)
1958     {
1959         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1960         return;
1961     }
1962 
1963     GPD_SCALINGENABLE_PARAM ScalingEnable;
1964     memset(&ScalingEnable , 0 ,sizeof(GPD_SCALINGENABLE_PARAM));
1965     ScalingEnable.mode = mode;
1966     GPD_API_INFO("UtopiaIoctl(): MApi_CMD_GPD_ScalingEnable\n");
1967     if(UtopiaIoctl(pInstantGPD,MApi_CMD_GPD_ScalingEnable, (void*)(&ScalingEnable)) != UTOPIA_STATUS_SUCCESS)
1968     {
1969         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1970         return;
1971     }
1972     return;
1973 #else
1974     _MApi_GPD_ScalingEnable(mode);
1975 #endif
1976 
1977 }
1978 
MApi_GPD_ScalingDisable(void)1979 void MApi_GPD_ScalingDisable(void)
1980 {
1981 #ifdef UTOPIA_20
1982     if(pInstantGPD==NULL)
1983     {
1984         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1985         return;
1986     }
1987 
1988     GPD_API_INFO("UtopiaIoctl(): MApi_CMD_GPD_ScalingDisable\n");
1989     if(UtopiaIoctl(pInstantGPD,MApi_CMD_GPD_ScalingDisable, NULL) != UTOPIA_STATUS_SUCCESS)
1990     {
1991         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
1992         return;
1993     }
1994     return;
1995 #else
1996     _MApi_GPD_ScalingDisable();
1997 #endif
1998 }
1999 
MApi_GPD_SetControl(gpd_user_cmd cmd_id,MS_VIRT param)2000 MS_U32 MApi_GPD_SetControl(gpd_user_cmd cmd_id, MS_VIRT param)
2001 {
2002 #ifdef UTOPIA_20
2003     if (pInstantGPD == NULL)
2004     {
2005         if(UtopiaOpen(MODULE_GPD | GPD_DRIVER_BASE, &pInstantGPD, 0, NULL) !=  UTOPIA_STATUS_SUCCESS)
2006         {
2007             GPD_API_ERROR("Open GPD fail\n");
2008             return FALSE;
2009         }
2010     }
2011 
2012     if(pInstantGPD==NULL)
2013     {
2014         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
2015         return FALSE;
2016     }
2017 
2018     GPD_CONTROL_PARAM CtrlPara;
2019     memset(&CtrlPara , 0 ,sizeof(GPD_CONTROL_PARAM));
2020     CtrlPara.cmd_id = cmd_id;
2021     CtrlPara.param = param;
2022     GPD_API_INFO("UtopiaIoctl(): MApi_CMD_GPD_SetControl\n");
2023     if(UtopiaIoctl(pInstantGPD,MApi_CMD_GPD_SetControl, (void*)(&CtrlPara)) != UTOPIA_STATUS_SUCCESS)
2024     {
2025         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
2026         return FALSE;
2027     }
2028     return CtrlPara.retVal;
2029 #else
2030     return _MApi_GPD_SetControl(cmd_id, param);
2031 #endif
2032 
2033 }
2034 
MApi_GPD_GetControl(gpd_get_cmd cmd_id,MS_VIRT param)2035 MS_U32 MApi_GPD_GetControl(gpd_get_cmd cmd_id, MS_VIRT param)
2036 {
2037 #ifdef UTOPIA_20
2038     if(pInstantGPD==NULL)
2039     {
2040         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
2041         return FALSE;
2042     }
2043 
2044     GPD_GET_CONTROL_PARAM CtrlPara;
2045     memset(&CtrlPara , 0 ,sizeof(GPD_GET_CONTROL_PARAM));
2046     CtrlPara.cmd_id = cmd_id;
2047     CtrlPara.param = param;
2048     GPD_API_INFO("UtopiaIoctl(): MApi_CMD_GPD_GetControl\n");
2049     if(UtopiaIoctl(pInstantGPD,MApi_CMD_GPD_GetControl, (void*)(&CtrlPara)) != UTOPIA_STATUS_SUCCESS)
2050     {
2051         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
2052         return FALSE;
2053     }
2054     return CtrlPara.retVal;
2055 #else
2056     return _MApi_GPD_GetControl(cmd_id, param);
2057 #endif
2058 
2059 }
2060 
MApi_GPD_GetCRCResult(const MS_U8 * pu8Data,MS_U32 u32Size,MS_U32 u32Width,MS_U32 ocolor)2061 MS_U32 MApi_GPD_GetCRCResult(const MS_U8 *pu8Data, MS_U32 u32Size, MS_U32 u32Width, MS_U32 ocolor)
2062 {
2063 #ifdef UTOPIA_20
2064     if(pInstantGPD==NULL)
2065     {
2066         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
2067         return FALSE;
2068     }
2069 
2070     GPD_GETCRCRESULT_PARAM CRCPara;
2071     memset(&CRCPara , 0 ,sizeof(GPD_GETCRCRESULT_PARAM));
2072     CRCPara.pu8Data = pu8Data;
2073     CRCPara.u32Size = u32Size;
2074     CRCPara.u32Width = u32Width;
2075     CRCPara.ocolor = ocolor;
2076     GPD_API_INFO("UtopiaIoctl(): MApi_CMD_GPD_GetCRCResult\n");
2077     if(UtopiaIoctl(pInstantGPD,MApi_CMD_GPD_GetCRCResult, (void*)(&CRCPara)) != UTOPIA_STATUS_SUCCESS)
2078     {
2079         GPD_API_ERROR("[Fail][%s,%d]\n",__FUNCTION__,__LINE__);
2080         return FALSE;
2081     }
2082     return CRCPara.retVal;
2083 #else
2084     return _MApi_GPD_GetCRCResult(pu8Data, u32Size, u32Width, ocolor);
2085 #endif
2086 
2087 }
2088 
MApi_GPD_GetConfig(void)2089 void MApi_GPD_GetConfig(void)
2090 {
2091     MApi_GPD_SetControl(E_GPD_USER_CMD_SET_DEBUG_LEVEL, E_GPD_DEBUG_LEVEL_NONE);
2092 }
2093 
2094