1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94
95 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// file drvGE.c
98 /// @brief GE Driver Interface
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101 #ifndef _DRV_GE_C_
102 #define _DRV_GE_C_
103
104 //-------------------------------------------------------------------------------------------------
105 // Include Files
106 //-------------------------------------------------------------------------------------------------
107 #ifndef MSOS_TYPE_LINUX_KERNEL
108 #include <stdio.h>
109 #include <string.h>
110 #endif
111 #include "MsCommon.h"
112 #include "MsVersion.h"
113 #include "MsOS.h"
114 #include "utopia.h"
115 #include "utopia_dapi.h"
116
117 #include "drvGE.h"
118 #include "halGE.h"
119 #include "drvGE_private.h"
120 #include "regCHIP.h"
121 #include "halCHIP.h"
122 #include "regGE.h"
123 #include "drvSEM.h"
124 #include "osalGE.h"
125 #include "drvMMIO.h"
126
127 //-------------------------------------------------------------------------------------------------
128 // Driver Compiler Options
129 //-------------------------------------------------------------------------------------------------
130 #define GE_DEBUG_ENABLE 0UL
131
132 #define ENABLE_PWR 0UL // FIXME: for porting
133 #define MS_DEBUG 1UL
134
135 #if (GFX_UTOPIA20)
136 #define g_drvGECtxLocal psGFXInstPriTmp->GFXPrivate_g_drvGECtxLocal
137 #else
138 GE_CTX_LOCAL g_drvGECtxLocal;
139 #endif
140
141 #if defined(MSOS_TYPE_LINUX) || defined(MSOS_TYPE_LINUX_KERNEL)
142 #else
143 GE_CTX_SHARED g_drvGECtxShared;
144 #endif
145
146
147 typedef struct
148 {
149 MS_U32 u32BlitFlags;
150 MS_U32 u32TrapeHeight;
151 //Src
152 MS_U32 u32SrcX;
153 MS_U32 u32SrcY;
154 MS_U32 u32SrcW;
155 MS_U32 u32SrcH;
156 MS_S32 s32DeltaSrcX; //s5.12
157 MS_S32 s32DeltaSrcY; //s5.12
158 //Dst
159 MS_U32 u32DstX0;
160 MS_U32 u32DstY0;
161 MS_U32 u32DstX1;
162 MS_U32 u32DstY1;
163 MS_S32 s32DeltaDstX0; //s5.12
164 MS_S32 s32DeltaDstY0; //s5.12
165 MS_S32 s32DeltaDstX1; //s5.12
166 MS_U32 s32DeltaDstY1; //s5.12
167 }GE_TrapeBatchBlitObj;
168
169 typedef struct
170 {
171 MS_U32 u32FillFlags;
172 MS_U32 u32TrapeHeight;
173 //Src
174 MS_U32 u32ColorS;
175 MS_U32 u32ColorE;
176 MS_S32 s32ColorDeltaB;
177 MS_S32 s32ColorDeltaG;
178 MS_S32 s32ColorDeltaR;
179 MS_S32 s32ColorDeltaA;
180
181 //Dst
182 MS_U32 u32DstX0;
183 MS_U32 u32DstY0;
184 MS_U32 u32DstX1;
185 MS_U32 u32DstY1;
186 MS_S32 s32DeltaDstX0; //s5.12
187 MS_S32 s32DeltaDstY0; //s5.12
188 MS_S32 s32DeltaDstX1; //s5.12
189 MS_U32 s32DeltaDstY1; //s5.12
190 }GE_TrapeBatchFillObj;
191
192 //-------------------------------------------------------------------------------------------------
193 // Local Defines
194 //-------------------------------------------------------------------------------------------------
195 #define DYNAMIC_POWER_ON_OFF 0UL
196 #define SEM_HK51ID 0x01UL
197 #define SEM_HKAeonID 0x02UL
198 #define SEM_MWMipsID 0x03UL
199 #define GESEMID 0x01UL
200 #define PREGESEMID 0x02UL
201
202 #define MDrv_PWR_ClockTurnOn(x) {} // FIXME: for porting
203 #define MDrv_PWR_ClockTurnOff(x) {} // FIXME: for porting
204
205 #define E_PWR_MODULE_GE 0UL
206
207 #ifdef MSOS_TYPE_LINUX
208 #include <assert.h>
209 #include <unistd.h>
210 #define GE_ASSERT_CHECK(_bool, pri) if (!(_bool)) {GE_D_FATAL("\nAssert in %s,%d\n", __FUNCTION__, __LINE__); (pri); MsOS_DelayTask(100); assert(0);}
211 #else
212 #define GE_ASSERT_CHECK(_bool, pri) if (!(_bool)) {GE_D_FATAL("\nAssert in %s,%d\n", __FUNCTION__, __LINE__); (pri);};
213 #endif
214
215 #if GE_LOCK_SUPPORT
216 #define GE_ENTRY(pGECtx) do{\
217 if(!GE_API_MUTEX)\
218 {\
219 GE_BeginDraw(pGECtx,TRUE);\
220 }\
221 }while(0)
222 #define GE_RETURN(pGECtx, _ret) do{\
223 if(!GE_API_MUTEX)\
224 GE_EndDraw(pGECtx,TRUE);return _ret;\
225 }while(0)
226 #else
227 #define GE_ENTRY(pGECtx) do{}while(0);
228 #define GE_RETURN(pGECtx, _ret) return _ret;
229 #endif
230
231 #if GE_LOCK_SUPPORT //-----------------------------------------------------------------------------
232 #if GE_USE_HW_SEM
233 MS_U16 GE_HWSemaphore_count =0;
234 MS_U16 GE_GetHWSemaphoreID=0;
235
236 #define DRV_GE_ENTRY(pGECtx,bHWSemLock) do{\
237 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx; \
238 if(pGECtxLocal->u32CTXInitMagic != 0x55aabeef) {return;} \
239 if (0 > pGECtxLocal->s32GEMutex) \
240 { return; } \
241 if((pGECtxLocal->s32GE_Recursive_Lock_Cnt > 0) && (pGECtxLocal->s32GELock == MsOS_GetOSThreadID())) \
242 { \
243 pGECtxLocal->s32GE_Recursive_Lock_Cnt++; \
244 } \
245 else \
246 { \
247 /*Step 1: Check Mutex*/\
248 while(!MsOS_ObtainMutex(pGECtxLocal->s32GEMutex, MSOS_WAIT_FOREVER)) \
249 {\
250 GE_D_DBUG("\33[0;31m [%s][%d] Obtian GE Mutex Fail \33[m;\n",__FUNCTION__,__LINE__);\
251 }\
252 /*HWSemaphore*/ \
253 if(bHWSemLock == TRUE) \
254 { \
255 /*Step 1: Check HWSemaphore*/\
256 while (MDrv_SEM_Get_Resource(GESEMID, pGECtxLocal->u32GESEMID) == FALSE)\
257 { \
258 GE_HWSemaphore_count++;\
259 if(GE_HWSemaphore_count>10000)\
260 {\
261 MDrv_SEM_Get_ResourceID(GESEMID, &GE_GetHWSemaphoreID);\
262 GE_D_DBUG("\33[0;31m [Entry While][%s][%d]GE_GetHWSemphoreID=%tx; GESEMID=%tx, TID=0x%tx \33[m;\n",__FUNCTION__,__LINE__, (ptrdiff_t)GE_GetHWSemaphoreID, (ptrdiff_t)pGECtxLocal->u32GESEMID,MsOS_GetOSThreadID());\
263 GE_HWSemaphore_count =0;\
264 }\
265 }\
266 }\
267 /*HWSemaphore*/ \
268 pGECtxLocal->s32GELock = MsOS_GetOSThreadID(); \
269 pGECtxLocal->s32GE_Recursive_Lock_Cnt++; \
270 /*printf("[%s][%05d][%ld]GFX_LOCK+++[%ld]\n",__FUNCTION__,__LINE__, pGECtxLocal->s32GELock, pGECtxLocal->s32GE_Recursive_Lock_Cnt); */ \
271 if(pGECtxLocal->pSharedCtx->u32LstGEClientId!=pGECtxLocal->u32GEClientId) \
272 { \
273 if(!pGECtxLocal->pSharedCtx->bNotFirstInit) \
274 { \
275 GE_Restore_HAL_Context(&pGECtxLocal->halLocalCtx); \
276 } \
277 pGECtxLocal->pSharedCtx->u32LstGEClientId = pGECtxLocal->u32GEClientId; \
278 } \
279 } \
280 }while(0)
281
282 #define DRV_GE_RETURN(pGECtx,bHWSemLock) do{ \
283 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx; \
284 GE_ASSERT_CHECK((pGECtxLocal->s32GELock==MsOS_GetOSThreadID()), (GE_D_FATAL("\nGE_RETURN: Fatal Error, Task ID mismatch[%td]->[%td]\n", (ptrdiff_t)pGECtxLocal->s32GELock, (ptrdiff_t)(MS_S32)MsOS_GetOSThreadID()))); \
285 GE_ASSERT_CHECK((0<pGECtxLocal->s32GE_Recursive_Lock_Cnt), (GE_D_FATAL("\nGE_RETURN: Fatal Error, No Mutex to release[Cnt=%td]\n", (ptrdiff_t)pGECtxLocal->s32GE_Recursive_Lock_Cnt))); \
286 if(pGECtxLocal->s32GE_Recursive_Lock_Cnt > 1) \
287 { \
288 pGECtxLocal->s32GE_Recursive_Lock_Cnt--; \
289 } \
290 else \
291 { \
292 pGECtxLocal->s32GE_Recursive_Lock_Cnt--; \
293 /*HWSemaphore*/ \
294 if(bHWSemLock == TRUE) \
295 { \
296 while(MDrv_SEM_Free_Resource(GESEMID, pGECtxLocal->u32GESEMID) ==FALSE)\
297 {\
298 GE_HWSemaphore_count++;\
299 if(GE_HWSemaphore_count>10000)\
300 {\
301 MDrv_SEM_Get_ResourceID(GESEMID, &GE_GetHWSemaphoreID);\
302 GE_D_DBUG("\33[0;31m [Return While][%s][%d] GE_GetHWSemphoreID=%tx, GESEMID=%tx, TID=0x%tx \33[m;\n",__FUNCTION__,__LINE__, (ptrdiff_t)GE_GetHWSemaphoreID, (ptrdiff_t)pGECtxLocal->u32GESEMID,(ptrdiff_t)(MS_S32)MsOS_GetOSThreadID());\
303 GE_HWSemaphore_count =0;\
304 }\
305 }\
306 }\
307 /*HWSemaphore*/ \
308 while(!MsOS_ReleaseMutex(pGECtxLocal->s32GEMutex)) \
309 {\
310 GE_D_DBUG("\33[0;31m [%s][%d] Release GE Mutex Fail \33[m;\n",__FUNCTION__,__LINE__);\
311 }\
312 }\
313 }while(0)
314
315 #else
316 #define DRV_GE_ENTRY(pGECtx,bHWSemLock) do{\
317 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx; \
318 if(pGECtxLocal->u32CTXInitMagic != 0x55aabeef) {return;} \
319 if (0 > pGECtxLocal->s32GEMutex) \
320 { return; } \
321 if((pGECtxLocal->s32GE_Recursive_Lock_Cnt > 0) && (pGECtxLocal->s32GELock == MsOS_GetOSThreadID())) \
322 { \
323 pGECtxLocal->s32GE_Recursive_Lock_Cnt++; \
324 } \
325 else \
326 { \
327 /*Step 1: Check Mutex*/\
328 while(!MsOS_ObtainMutex(pGECtxLocal->s32GEMutex, MSOS_WAIT_FOREVER)) \
329 {\
330 GE_D_DBUG("\33[0;31m [%s][%d] Obtian GE Mutex Fail \33[m;\n",__FUNCTION__,__LINE__);\
331 }\
332 pGECtxLocal->s32GELock = MsOS_GetOSThreadID(); \
333 pGECtxLocal->s32GE_Recursive_Lock_Cnt++; \
334 /*printf("[%s][%05d][%ld]GFX_LOCK+++[%ld]\n",__FUNCTION__,__LINE__, pGECtxLocal->s32GELock, pGECtxLocal->s32GE_Recursive_Lock_Cnt); */ \
335 if(pGECtxLocal->pSharedCtx->u32LstGEClientId!=pGECtxLocal->u32GEClientId) \
336 { \
337 if(!pGECtxLocal->pSharedCtx->bNotFirstInit) \
338 { \
339 GE_Restore_HAL_Context(&pGECtxLocal->halLocalCtx); \
340 } \
341 pGECtxLocal->pSharedCtx->u32LstGEClientId = pGECtxLocal->u32GEClientId; \
342 } \
343 } \
344 }while(0)
345
346 #define DRV_GE_RETURN(pGECtx,bHWSemLock) do{ \
347 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx; \
348 GE_ASSERT_CHECK((pGECtxLocal->s32GELock==MsOS_GetOSThreadID()), (GE_D_FATAL("\nGE_RETURN: Fatal Error, Task ID mismatch[%td]->[%td]\n", (ptrdiff_t)pGECtxLocal->s32GELock, (ptrdiff_t)(MS_S32)MsOS_GetOSThreadID()))); \
349 GE_ASSERT_CHECK((0<pGECtxLocal->s32GE_Recursive_Lock_Cnt), (GE_D_FATAL("\nGE_RETURN: Fatal Error, No Mutex to release[Cnt=%td]\n", (ptrdiff_t)pGECtxLocal->s32GE_Recursive_Lock_Cnt))); \
350 if(pGECtxLocal->s32GE_Recursive_Lock_Cnt > 1) \
351 { \
352 pGECtxLocal->s32GE_Recursive_Lock_Cnt--; \
353 } \
354 else \
355 { \
356 pGECtxLocal->s32GE_Recursive_Lock_Cnt--; \
357 while(!MsOS_ReleaseMutex(pGECtxLocal->s32GEMutex)) \
358 {\
359 GE_D_DBUG("\33[0;31m [%s][%d] Release GE Mutex Fail \33[m;\n",__FUNCTION__,__LINE__);\
360 }\
361 }\
362 }while(0)
363 #endif //GE_USE_HW_SEM
364 #else //-------------------------------------------------------------------------------------------
365 MS_U16 GE_HWSemaphore_count =0;
366 MS_U16 GE_GetHWSemaphoreID=0;
367
368 #define DRV_GE_ENTRY(pGECtx,bHWSemLock) do{\
369 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx; \
370 if(pGECtxLocal->u32CTXInitMagic != 0x55aabeef) {return;} \
371 if((pGECtxLocal->s32GE_Recursive_Lock_Cnt > 0)) \
372 { \
373 pGECtxLocal->s32GE_Recursive_Lock_Cnt++; \
374 } \
375 else \
376 { \
377 /*Step 1: Check HWSemaphore*/\
378 while (MDrv_SEM_Get_Resource(GESEMID, pGECtxLocal->u32GESEMID) == FALSE)\
379 { \
380 GE_HWSemaphore_count++;\
381 if(GE_HWSemaphore_count>10000)\
382 {\
383 MDrv_SEM_Get_ResourceID(GESEMID, &GE_GetHWSemaphoreID);\
384 GE_D_DBUG("\33[0;31m [Entry While][%s][%d]GE_GetHWSemphoreID=%tx; pGECtxLocal->u32GESEMID=%tx \33[m;\n",__FUNCTION__,__LINE__, (ptrdiff_t)GE_GetHWSemaphoreID, (ptrdiff_t)pGECtxLocal->u32GESEMID);\
385 GE_HWSemaphore_count =0;\
386 }\
387 }\
388 pGECtxLocal->s32GE_Recursive_Lock_Cnt++; \
389 if(pGECtxLocal->pSharedCtx->u32LstGEClientId!=pGECtxLocal->u32GEClientId) \
390 { \
391 if(!pGECtxLocal->pSharedCtx->bNotFirstInit) \
392 { \
393 GE_Restore_HAL_Context(&pGECtxLocal->halLocalCtx); \
394 } \
395 pGECtxLocal->pSharedCtx->u32LstGEClientId = pGECtxLocal->u32GEClientId; \
396 } \
397 } \
398 }while(0)
399
400 #define DRV_GE_RETURN(pGECtx,bHWSemLock) do{\
401 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx; \
402 GE_ASSERT_CHECK((0<pGECtxLocal->s32GE_Recursive_Lock_Cnt), (GE_D_FATAL("\nGE_RETURN: Fatal Error, No Mutex to release[Cnt=%td]\n", (ptrdiff_t)pGECtxLocal->s32GE_Recursive_Lock_Cnt))); \
403 if(pGECtxLocal->s32GE_Recursive_Lock_Cnt > 1) \
404 { \
405 pGECtxLocal->s32GE_Recursive_Lock_Cnt--; \
406 } \
407 else \
408 { \
409 pGECtxLocal->s32GE_Recursive_Lock_Cnt--; \
410 while(MDrv_SEM_Free_Resource(GESEMID, pGECtxLocal->u32GESEMID) ==FALSE)\
411 {\
412 GE_HWSemaphore_count++;\
413 if(GE_HWSemaphore_count>10000)\
414 {\
415 MDrv_SEM_Get_ResourceID(GESEMID, &GE_GetHWSemaphoreID);\
416 GE_D_DBUG("\33[0;31m [Return While][%s][%d] GE_GetHWSemphoreID=%tx; u32GESEMID=%tx\33[m;\n",__FUNCTION__,__LINE__, (ptrdiff_t)GE_GetHWSemaphoreID, (ptrdiff_t)pGECtxLocal->u32GESEMID);\
417 GE_HWSemaphore_count =0;\
418 }\
419 }\
420 }\
421 }while(0)
422 #endif //------------------------------------------------------------------------------------------
423
424 #if GE_DEBUG_ENABLE
425 #define GE_DBG(_fmt, _args...) MS_DEBUG_MSG(GE_D_DBUG(_fmt, ##_args))
426 #else
427 #define GE_DBG(_fmt, _args...) { }
428 #endif
429
430 #ifdef MS_DEBUG //---------------------------------------------------------------------------------
431 #define GE_ERR(_fmt, _args...) GE_D_ERR(_fmt, ##_args)
432 #define GE_ASSERT(_cnd, _ret, _fmt, _args...) \
433 do{if (!(_cnd)) { \
434 GE_D_ERR(_fmt, ##_args); \
435 return _ret; \
436 } \
437 }while(0);
438 #else //-------------------------------------------------------------------------------------------
439 #define GE_ERR(_fmt, _args...) { }
440 #define GE_ASSERT(_cnd, _ret, _fmt, _args...) \
441 do{if (!(_cnd)) { \
442 GE_D_ERR(_fmt, ##_args); \
443 return _ret; \
444 } \
445 }while(0); // CAUTION: It should be before GE_ENTRY
446 #endif //------------------------------------------------------------------------------------------
447
448 #define INT_TO_FIX32(X) (((MS_S32) (X)) << 12)
449 #define FIX32_TO_INT(X) ((MS_S32) ((X) >> 12))
450
451 //-------------------------------------------------------------------------------------------------
452 // Local Structurs
453 //-------------------------------------------------------------------------------------------------
454
455 //-------------------------------------------------------------------------------------------------
456 // Global Variables
457 //-------------------------------------------------------------------------------------------------
458
459
460 //-------------------------------------------------------------------------------------------------
461 // Local Variables
462 //-------------------------------------------------------------------------------------------------
463 static MSIF_Version _drv_ge_version = {
464 .DDI = { GE_DRV_VERSION },
465 };
466 static MS_U32 dbg_level = 0;
467 MS_BOOL bDither = FALSE;
468 #ifdef GE_SPLIT_SUPPORT
469 MS_BOOL bABL = FALSE;
470 #endif
471 #ifdef GE_ALPHA_BLEND_PATCH
472 extern MS_U16 u16GAlphaConst;
473 extern MS_U16 u16GAlphaMode;
474 #endif
475 static MS_VIRT* pTLBSRCStartVA=NULL;
476 static MS_VIRT* pTLBDSTStartVA=NULL;
477
478 #ifdef GE_VQ_MIU_HANG_PATCH
479 static MS_U8 u8SrcMIU,u8DstMIU;
480 #endif
481
482 //-------------------------------------------------------------------------------------------------
483 // Debug Functions
484 //-------------------------------------------------------------------------------------------------
485
486
487 //-------------------------------------------------------------------------------------------------
488 // Local Functions
489 //-------------------------------------------------------------------------------------------------
GE_BeginDraw(GE_Context * pGECtx,MS_BOOL bHWSemLock)490 static void GE_BeginDraw(GE_Context *pGECtx,MS_BOOL bHWSemLock)
491 {
492 DRV_GE_ENTRY(pGECtx,bHWSemLock);
493 }
494
GE_EndDraw(GE_Context * pGECtx,MS_BOOL bHWSemLock)495 static void GE_EndDraw(GE_Context *pGECtx,MS_BOOL bHWSemLock)
496 {
497 DRV_GE_RETURN(pGECtx,bHWSemLock);
498 }
499
GE_FastClip(GE_Context * pGECtx,MS_U16 x0,MS_U16 y0,MS_U16 x1,MS_U16 y1)500 static MS_BOOL GE_FastClip(GE_Context *pGECtx, MS_U16 x0, MS_U16 y0, MS_U16 x1, MS_U16 y1)
501 {
502 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
503 if ( ((x0 < pGECtxLocal->u16ClipL) && (x1 < pGECtxLocal->u16ClipL)) ||
504 ((x0 > pGECtxLocal->u16ClipR) && (x1 > pGECtxLocal->u16ClipR)) ||
505 ((y0 < pGECtxLocal->u16ClipT) && (y1 < pGECtxLocal->u16ClipT)) ||
506 ((y0 > pGECtxLocal->u16ClipB) && (y1 > pGECtxLocal->u16ClipB)) )
507 {
508 return TRUE; // can't be clipped
509 }
510 return FALSE;
511 }
512
513 #ifdef CONFIG_GFX_TRAPZOID
GE_FastClipTrapezoid(GE_Context * pGECtx,MS_U16 u16X0,MS_U16 u16Y0,MS_U16 u16X1,MS_U16 u16Y1,MS_U16 u16DeltaTop,MS_U16 u16DeltaBottom,MS_BOOL bYTrapezoid)514 static MS_BOOL GE_FastClipTrapezoid(GE_Context *pGECtx, MS_U16 u16X0, MS_U16 u16Y0, MS_U16 u16X1, MS_U16 u16Y1, MS_U16 u16DeltaTop, MS_U16 u16DeltaBottom, MS_BOOL bYTrapezoid)
515 {
516 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
517 MS_U16 u16MinusX, u16MaxX, u16MinusY, u16MaxY;
518
519 if(bYTrapezoid)
520 {
521 u16MinusX = u16X1;
522 u16MaxX = u16X0;
523 u16MinusY = MIN(u16Y0, u16Y1);
524 u16MaxY = MAX((u16Y0+u16DeltaTop),(u16Y1+u16DeltaBottom));
525 }
526 else
527 {
528 u16MinusY = u16Y0;
529 u16MaxY = u16Y1;
530 u16MinusX = MIN(u16X0, u16X1);
531 u16MaxX = MAX((u16X0+u16DeltaTop),(u16X1+u16DeltaBottom));
532 }
533
534 if((u16MaxX<pGECtxLocal->u16ClipL) ||
535 (u16MinusX>pGECtxLocal->u16ClipR) ||
536 (u16MaxY<pGECtxLocal->u16ClipT) ||
537 (u16MinusY>pGECtxLocal->u16ClipB))
538 {
539 return TRUE; // can't be clipped
540 }
541
542 return FALSE;
543 }
544 #endif
GE_RectOverlap(GE_CTX_LOCAL * pGECtxLocal,GE_Rect * rect0,GE_DstBitBltType * rect1)545 static MS_BOOL GE_RectOverlap(GE_CTX_LOCAL *pGECtxLocal, GE_Rect *rect0, GE_DstBitBltType *rect1)
546 {
547 if ( (pGECtxLocal->PhySrcAddr != pGECtxLocal->PhyDstAddr) ||
548 (rect0->x+rect0->width-1 < rect1->dstblk.x) ||
549 (rect0->x > rect1->dstblk.x+rect1->dstblk.width-1) ||
550 (rect0->y+rect0->height-1 < rect1->dstblk.y) ||
551 (rect0->y > rect1->dstblk.y+rect1->dstblk.height-1))
552 {
553 return FALSE; // no overlap
554 }
555
556 return TRUE;
557 }
558 #ifdef CONFIG_GFX_TRAPZOID
GE_TrapezoidOverlap(GE_Rect * pGeRect,GE_Trapezoid * pGeTrapezoid)559 static MS_BOOL GE_TrapezoidOverlap(GE_Rect *pGeRect, GE_Trapezoid *pGeTrapezoid)
560 {
561 MS_U16 u16DeltaX, u16DeltaY;
562 MS_U16 u16MinorX, u16MajorX, u16MinorY, u16MajorY;
563 MS_U16 u16CheckMinorX0, u16CheckMinorX1, u16CheckMajorX0, u16CheckMajorX1;
564
565 u16MinorX = (pGeTrapezoid->u16X0 >= pGeTrapezoid->u16X1) ? pGeTrapezoid->u16X1 : pGeTrapezoid->u16X0;
566 u16MajorX = (pGeTrapezoid->u16X0 >= pGeTrapezoid->u16X1) ? pGeTrapezoid->u16X0 : pGeTrapezoid->u16X1;
567 u16MinorY = (pGeTrapezoid->u16Y0 >= pGeTrapezoid->u16Y1) ? pGeTrapezoid->u16Y1 : pGeTrapezoid->u16Y0;
568 u16MajorY = (pGeTrapezoid->u16Y0 >= pGeTrapezoid->u16Y1) ? pGeTrapezoid->u16Y0 : pGeTrapezoid->u16Y1;
569
570 //check Y:
571 if((pGeRect->y > u16MajorY) || ((pGeRect->y+pGeRect->height-1) < u16MajorY))
572 {
573 return FALSE; // no overlap
574 }
575
576 u16CheckMinorX0 = u16CheckMinorX1 = u16CheckMajorX0 = u16CheckMajorX1 = 0;
577
578 //check X:
579 u16DeltaX = u16MajorX - u16MinorX;
580 u16DeltaY = u16MajorY - u16MinorY;
581
582 //Get u16CheckMinorX0, X1:
583 if((pGeRect->y >= u16MinorY) && (pGeRect->y <= u16MajorY))
584 {
585 u16CheckMinorX0 = (pGeTrapezoid->u16Y0 == u16MinorY) ? pGeTrapezoid->u16X0 : pGeTrapezoid->u16X1;
586 if(u16CheckMinorX0 == u16MinorX)
587 {
588 u16CheckMinorX0 += ((u16DeltaX/u16DeltaY) * (pGeRect->y-u16MinorY));
589 }
590 else
591 {
592 u16CheckMinorX0 -= ((u16DeltaX/u16DeltaY) * (pGeRect->y-u16MinorY));
593 }
594 }
595
596 if(((pGeRect->y+pGeRect->height-1) >= u16MinorY) && ((pGeRect->y+pGeRect->height-1) <= u16MajorY))
597 {
598 u16CheckMinorX1 = (pGeTrapezoid->u16Y0 == u16MinorY) ? pGeTrapezoid->u16X0 : pGeTrapezoid->u16X1;
599 if(u16CheckMinorX1 == u16MinorX)
600 {
601 u16CheckMinorX1 += ((u16DeltaX/u16DeltaY) * (pGeRect->y+pGeRect->height-1-u16MinorY));
602 }
603 else
604 {
605 u16CheckMinorX1 -= ((u16DeltaX/u16DeltaY) * (pGeRect->y+pGeRect->height-1-u16MinorY));
606 }
607 }
608
609 //Get MajorX0, MajorX1:
610 u16MinorX = ((pGeTrapezoid->u16X0+pGeTrapezoid->u16DeltaTop)>= (pGeTrapezoid->u16X1+pGeTrapezoid->u16DeltaBottom)) ? (pGeTrapezoid->u16X1+pGeTrapezoid->u16DeltaBottom) : (pGeTrapezoid->u16X0+pGeTrapezoid->u16DeltaTop);
611 u16MajorX = ((pGeTrapezoid->u16X0+pGeTrapezoid->u16DeltaTop)>= (pGeTrapezoid->u16X1+pGeTrapezoid->u16DeltaBottom)) ? (pGeTrapezoid->u16X0+pGeTrapezoid->u16DeltaTop) : (pGeTrapezoid->u16X1+pGeTrapezoid->u16DeltaBottom);
612 u16DeltaX = u16MajorX - u16MinorX;
613
614 if((pGeRect->y >= u16MinorY) && (pGeRect->y <= u16MajorY))
615 {
616 u16CheckMajorX0 = (pGeTrapezoid->u16Y0 == u16MinorY) ? (pGeTrapezoid->u16X0+pGeTrapezoid->u16DeltaTop): (pGeTrapezoid->u16X1+pGeTrapezoid->u16DeltaBottom);
617 if(u16CheckMajorX0 == u16MinorX)
618 {
619 u16CheckMajorX0 += ((u16DeltaX/u16DeltaY) * (pGeRect->y-u16MinorY));
620 }
621 else
622 {
623 u16CheckMajorX0 -= ((u16DeltaX/u16DeltaY) * (pGeRect->y-u16MinorY));
624 }
625 }
626
627 if(((pGeRect->y+pGeRect->height-1) >= u16MinorY) && ((pGeRect->y+pGeRect->height-1) <= u16MajorY))
628 {
629 u16CheckMajorX1 = (pGeTrapezoid->u16Y0 == u16MinorY) ? (pGeTrapezoid->u16X0+pGeTrapezoid->u16DeltaTop) : (pGeTrapezoid->u16X1+pGeTrapezoid->u16DeltaBottom);
630 if(u16CheckMajorX1 == u16MinorX)
631 {
632 u16CheckMajorX1 += ((u16DeltaX/u16DeltaY) * (pGeRect->y+pGeRect->height-1-u16MinorY));
633 }
634 else
635 {
636 u16CheckMajorX1 -= ((u16DeltaX/u16DeltaY) * (pGeRect->y+pGeRect->height-1-u16MinorY));
637 }
638 }
639
640 if((u16CheckMinorX0!=0) || (u16CheckMajorX0!=0))
641 {
642 if((pGeRect->x > u16CheckMajorX0) || ((pGeRect->x+pGeRect->width-1)<u16CheckMinorX0))
643 {
644 return FALSE;
645 }
646 }
647
648 if((u16CheckMinorX1!=0) || (u16CheckMajorX1!=0))
649 {
650 if((pGeRect->x > u16CheckMajorX1) || ((pGeRect->x+pGeRect->width-1)<u16CheckMinorX1))
651 {
652 return FALSE;
653 }
654 }
655
656 return TRUE;
657 }
658 #endif
659
GE_GetFmt(GE_BufFmt fmt)660 static MS_U16 GE_GetFmt(GE_BufFmt fmt)
661 {
662 switch(fmt)
663 {
664 case E_GE_FMT_I1:
665 return GE_FMT_I1;
666 break;
667 case E_GE_FMT_I2:
668 return GE_FMT_I2;
669 break;
670 case E_GE_FMT_I4:
671 return GE_FMT_I4;
672 break;
673 case E_GE_FMT_I8:
674 return GE_FMT_I8;
675 break;
676 case E_GE_FMT_FaBaFgBg2266:
677 return GE_FMT_FaBaFgBg2266;
678 break;
679 case E_GE_FMT_1ABFgBg12355:
680 return GE_FMT_1ABFgBg12355;
681 break;
682 case E_GE_FMT_RGB565:
683 return GE_FMT_RGB565;
684 break;
685 case E_GE_FMT_ARGB1555:
686 return GE_FMT_ARGB1555;
687 break;
688 case E_GE_FMT_ARGB4444:
689 return GE_FMT_ARGB4444;
690 break;
691 case E_GE_FMT_ARGB1555_DST:
692 return GE_FMT_ARGB1555_DST;
693 break;
694 case E_GE_FMT_YUV422:
695 return GE_FMT_YUV422;
696 break;
697 case E_GE_FMT_ARGB8888:
698 return GE_FMT_ARGB8888;
699 break;
700 case E_GE_FMT_RGBA5551:
701 return GE_FMT_RGBA5551;
702 break;
703 case E_GE_FMT_RGBA4444:
704 return GE_FMT_RGBA4444;
705 break;
706 case E_GE_FMT_ABGR8888:
707 return GE_FMT_ABGR8888;
708 break;
709 case E_GE_FMT_ABGR1555:
710 return GE_FMT_ABGR1555;
711 break;
712 case E_GE_FMT_BGRA5551:
713 return GE_FMT_BGRA5551;
714 break;
715 case E_GE_FMT_ABGR4444:
716 return GE_FMT_ABGR4444;
717 break;
718 case E_GE_FMT_BGRA4444:
719 return GE_FMT_BGRA4444;
720 break;
721 case E_GE_FMT_BGR565:
722 return GE_FMT_BGR565;
723 break;
724 case E_GE_FMT_RGBA8888:
725 return GE_FMT_RGBA8888;
726 break;
727 case E_GE_FMT_BGRA8888:
728 return GE_FMT_BGRA8888;
729 break;
730 default:
731 return GE_FMT_GENERIC;
732 break;
733 }
734 }
735
736 #ifdef GE_VQ_MIU_HANG_PATCH
GE_IsVcmdqEnabled(GE_Context * pGECtx)737 static MS_BOOL GE_IsVcmdqEnabled(GE_Context *pGECtx)
738 {
739 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
740 MS_U16 u16tmp = 0x0;
741 MS_BOOL bEnable = TRUE;
742
743 u16tmp = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_CFG);
744
745 bEnable = ((u16tmp & GE_CFG_VCMDQ) > 0) ? TRUE : FALSE;
746
747 return bEnable;
748 }
749 #endif
750
GE_Divide2Fixed(MS_U16 u16x,MS_U16 u16y,MS_U8 nInteger,MS_U8 nFraction)751 MS_U32 GE_Divide2Fixed(MS_U16 u16x, MS_U16 u16y, MS_U8 nInteger, MS_U8 nFraction)
752 {
753 MS_U8 neg = 0;
754 MS_U32 mask;
755 MS_U32 u32x;
756 MS_U32 u32y;
757
758 if (u16x == 0)
759 {
760 return 0;
761 }
762
763 if (u16x & 0x8000)
764 {
765 u32x = 0xFFFF0000 | u16x;
766 u32x = ~u32x + 1; //convert to positive
767 neg++;
768 }
769 else
770 {
771 u32x = u16x;
772 }
773
774 if (u16y & 0x8000)
775 {
776 u32y = 0xFFFF0000 | u16y;
777 u32y = ~u32y + 1; //convert to positive
778 neg++;
779 }
780 else
781 {
782 u32y = u16y;
783 }
784
785 // start calculation
786 u32x = (u32x << nFraction) / u32y;
787 if (neg % 2)
788 {
789 u32x = ~u32x + 1;
790 }
791 // total bit number is: 1(s) + nInteger + nFraction
792 mask = (1 << (1 + nInteger + nFraction)) - 1;
793 u32x &= mask;
794
795 return u32x;
796 }
797
GE_CalcColorDelta(MS_U32 color0,MS_U32 color1,MS_U16 ratio,GE_ColorDelta * delta)798 static void GE_CalcColorDelta(MS_U32 color0, MS_U32 color1, MS_U16 ratio, GE_ColorDelta *delta)
799 {
800 MS_U8 a0, r0, g0, b0;
801 MS_U8 a1, r1, g1, b1;
802
803
804 // Get A,R,G,B
805 //[TODO] special format
806 b0 = (color0) & 0xFF;
807 g0 = (color0 >> 8) & 0xFF;
808 r0 = (color0 >> 16) & 0xFF;
809 a0 = (color0 >> 24);
810 b1 = (color1) & 0xFF;
811 g1 = (color1 >> 8) & 0xFF;
812 r1 = (color1 >> 16) & 0xFF;
813 a1 = (color1 >> 24);
814
815 //[TODO] revise and take advantage on Divid2Fixed for negative value
816 if (b0 > b1)
817 {
818 delta->b = GE_Divide2Fixed((b0-b1), ratio, 7, 12);
819 delta->b = (MS_U32)(1<<(1+7+12)) - delta->b; // negative
820 }
821 else
822 {
823 delta->b = GE_Divide2Fixed((b1-b0), ratio, 7, 12);
824 }
825
826 if (g0 > g1)
827 {
828 delta->g = GE_Divide2Fixed((g0-g1), ratio, 7, 12);
829 delta->g = (MS_U32)(1<<(1+7+12)) - delta->g; // negative
830 }
831 else
832 {
833 delta->g = GE_Divide2Fixed((g1-g0), ratio, 7, 12);
834 }
835
836 if (r0 > r1)
837 {
838 delta->r = GE_Divide2Fixed((r0-r1), ratio, 7, 12);
839 delta->r = (MS_U32)(1<<(1+7+12)) - delta->r; // negative
840 }
841 else
842 {
843 delta->r = GE_Divide2Fixed((r1-r0), ratio, 7, 12);
844 }
845
846 if (a0 > a1)
847 {
848 delta->a = (MS_U16)GE_Divide2Fixed((a0-a1), ratio, 4, 11);
849 delta->a = (MS_U16)(1<<(1+4+11)) - delta->a; // negative
850 }
851 else
852 {
853 delta->a = (MS_U16)GE_Divide2Fixed((a1-a0), ratio, 4, 11);
854 }
855 }
856 #ifdef CONFIG_GFX_TRAPZOID
GE_NormalizeTrapezoidDef(GE_Trapezoid * pGeTrapezoid,GE_Normalized_Trapezoid * pGeNormTrapezoid,MS_BOOL bYTrapezoid)857 static void GE_NormalizeTrapezoidDef(GE_Trapezoid *pGeTrapezoid, GE_Normalized_Trapezoid *pGeNormTrapezoid, MS_BOOL bYTrapezoid)
858 {
859 MS_U16 u16DeltaR, u16DeltaM; //Responsible Var and Main Var of Delta Calculation.
860 MS_BOOL bMinus;
861
862 //Get Top-Left Point:
863 pGeNormTrapezoid->u16X0 = pGeTrapezoid->u16X0;
864 pGeNormTrapezoid->u16Y0 = pGeTrapezoid->u16Y0;
865 //Get Top-Right Edge and Bottom Edge X/Y:
866 if(bYTrapezoid)
867 {
868 pGeNormTrapezoid->u16X1 = pGeTrapezoid->u16X1;
869 pGeNormTrapezoid->u16Y1 = pGeTrapezoid->u16Y0+pGeTrapezoid->u16DeltaTop;
870 }
871 else
872 {
873 pGeNormTrapezoid->u16X1 = pGeTrapezoid->u16X0+pGeTrapezoid->u16DeltaTop;
874 pGeNormTrapezoid->u16Y1 = pGeTrapezoid->u16Y1;
875 }
876
877 //Get DeltaL(s5.12):
878 if(bYTrapezoid)
879 {
880 bMinus = (pGeTrapezoid->u16Y0 > pGeTrapezoid->u16Y1);
881 u16DeltaR = bMinus ? (pGeTrapezoid->u16Y0 - pGeTrapezoid->u16Y1) : (pGeTrapezoid->u16Y1 - pGeTrapezoid->u16Y0);
882 u16DeltaM = (pGeTrapezoid->u16X0 - pGeTrapezoid->u16X1);
883 }
884 else
885 {
886 bMinus = (pGeTrapezoid->u16X0 > pGeTrapezoid->u16X1);
887 u16DeltaR = bMinus ? (pGeTrapezoid->u16X0 - pGeTrapezoid->u16X1) : (pGeTrapezoid->u16X1 - pGeTrapezoid->u16X0);
888 u16DeltaM = (pGeTrapezoid->u16Y1 - pGeTrapezoid->u16Y0);
889 }
890
891 pGeNormTrapezoid->u32DeltaL = GE_Divide2Fixed(u16DeltaR, u16DeltaM, 5, 12); // s5.12
892
893 if(bMinus)
894 {
895 pGeNormTrapezoid->u32DeltaL = (MS_U32)(1<<(6+12)) - pGeNormTrapezoid->u32DeltaL; //BIT(17)~bIT(0) valid.
896 }
897
898 //Get DeltaR of Trapezoid (s5.12):
899 if(bYTrapezoid)
900 {
901 bMinus = ((pGeTrapezoid->u16Y0+pGeTrapezoid->u16DeltaTop) > (pGeTrapezoid->u16Y1+pGeTrapezoid->u16DeltaBottom));
902 u16DeltaR = bMinus ? ((pGeTrapezoid->u16Y0+pGeTrapezoid->u16DeltaTop)-(pGeTrapezoid->u16Y1+pGeTrapezoid->u16DeltaBottom)) : ((pGeTrapezoid->u16Y1+pGeTrapezoid->u16DeltaBottom) - (pGeTrapezoid->u16Y0+pGeTrapezoid->u16DeltaTop));
903 u16DeltaM = (pGeTrapezoid->u16X0 - pGeTrapezoid->u16X1);
904 }
905 else
906 {
907 bMinus = ((pGeTrapezoid->u16X0+pGeTrapezoid->u16DeltaTop) > (pGeTrapezoid->u16X1+pGeTrapezoid->u16DeltaBottom));
908 u16DeltaR = bMinus ? ((pGeTrapezoid->u16X0+pGeTrapezoid->u16DeltaTop) - (pGeTrapezoid->u16X1+pGeTrapezoid->u16DeltaBottom)) : ((pGeTrapezoid->u16X1+pGeTrapezoid->u16DeltaBottom) - (pGeTrapezoid->u16X0+pGeTrapezoid->u16DeltaTop));
909 u16DeltaM = (pGeTrapezoid->u16Y1 - pGeTrapezoid->u16Y0);
910 }
911
912 pGeNormTrapezoid->u32DeltaR = GE_Divide2Fixed(u16DeltaR, u16DeltaM, 5, 12); // s5.12
913
914 if(bMinus)
915 {
916 pGeNormTrapezoid->u32DeltaR = (MS_U32)(1<<(6+12)) - pGeNormTrapezoid->u32DeltaR; //BIT(17)~bIT(0) valid.
917 }
918 }
919 #endif
GE_SetPalette(GE_CTX_LOCAL * pGECtxLocal)920 static GE_Result GE_SetPalette(GE_CTX_LOCAL *pGECtxLocal)
921 {
922 MS_U32 u32Idx= 0;
923
924 #ifdef GE_PALETTE_PATCH
925 MS_U8 i= 0;
926 MS_U16 GEstatus = 0;
927 MS_BOOL bBusy = FALSE;
928 MS_U32 waitcount = 0;
929 MS_U16 tmp1 = 0;
930
931 GE_WaitIdle(&pGECtxLocal->halLocalCtx);
932 for(u32Idx=0; u32Idx<GE_PALETTE_NUM; u32Idx++)
933 {
934 do
935 {
936 GEstatus = GE_ReadReg(&pGECtxLocal->halLocalCtx,REG_GE_STAT);
937 bBusy = (MS_BOOL)GEstatus & GE_STAT_BUSY;
938 if (waitcount >= 0x8000000)
939 {
940 GE_D_INFO("[%s][%d] Wait GE Idle: waitcount=%d, tmp1=%d\n",__FUNCTION__,__LINE__,waitcount,tmp1);
941 if(tmp1 > 10)
942 {
943 GE_D_ERR("[%s][%d]Set GE palette fail\n",__FUNCTION__,__LINE__);
944 return (E_GE_FAIL);
945 }
946 tmp1++;
947 }
948 waitcount++;
949 }while(bBusy != 0);
950 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CLUT_H, ByteSwap16(pGECtxLocal->halLocalCtx.u32Palette[u32Idx]) & 0xFFFF);
951 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CLUT_L, ByteSwap16(pGECtxLocal->halLocalCtx.u32Palette[u32Idx]>>16));
952 for(i=0; i<1; i++)
953 {
954 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CLUT_CTRL, ((u32Idx) & GE_CLUT_CTRL_IDX_MASK) | GE_CLUT_CTRL_RD);
955 }
956 for(i=0; i<4; i++)
957 {
958 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CLUT_CTRL, ((u32Idx) & GE_CLUT_CTRL_IDX_MASK) | GE_CLUT_CTRL_WR);
959 }
960 for(i=0; i<1; i++)
961 {
962 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CLUT_CTRL, ((u32Idx) & GE_CLUT_CTRL_IDX_MASK) | GE_CLUT_CTRL_RD);
963 }
964 }
965 #else
966 for(u32Idx=0; u32Idx<GE_PALETTE_NUM; u32Idx++)
967 {
968 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CLUT_H, ByteSwap16(pGECtxLocal->halLocalCtx.u32Palette[u32Idx]) & 0xFFFF);
969 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CLUT_L, ByteSwap16(pGECtxLocal->halLocalCtx.u32Palette[u32Idx]>>16));
970 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CLUT_CTRL, ((u32Idx) & GE_CLUT_CTRL_IDX_MASK) | GE_CLUT_CTRL_WR);
971 }
972 #endif
973
974 return (E_GE_OK);
975 }
976
GE_Restore_PaletteContext(GE_CTX_LOCAL * pGECtxLocal)977 static GE_Result GE_Restore_PaletteContext(GE_CTX_LOCAL *pGECtxLocal)
978 {
979 if((TRUE == pGECtxLocal->bSrcPaletteOn) /*|| (TRUE == pGECtxLocal->bDstPaletteOn)*/)
980 { //Palette on in this KickOff, Need Restore Palette Context if need:
981 if( (pGECtxLocal->u32GESEMID!=pGECtxLocal->u16GEPrevSEMID)
982 || (TRUE == pGECtxLocal->halLocalCtx.bPaletteDirty)
983 || ((pGECtxLocal->pSharedCtx->u32LstGEPaletteClientId!=pGECtxLocal->u32GEClientId) && pGECtxLocal->pSharedCtx->u32LstGEPaletteClientId) )
984 { //Need restore palette:
985 GE_SetPalette(pGECtxLocal);
986 pGECtxLocal->pSharedCtx->u32LstGEPaletteClientId = pGECtxLocal->u32GEClientId;
987 pGECtxLocal->halLocalCtx.bPaletteDirty = FALSE;
988 pGECtxLocal->bSrcPaletteOn = FALSE;
989 }
990 }
991
992 return (E_GE_OK);
993 }
994 #ifdef CONFIG_GFX_TRAPZOID
GE_TrapezoidBlitEx(GE_CTX_LOCAL * pGECtxLocal,GE_TrapeBatchBlitObj * pTrapeBatchBlitObj)995 static GE_Result GE_TrapezoidBlitEx(GE_CTX_LOCAL *pGECtxLocal, GE_TrapeBatchBlitObj *pTrapeBatchBlitObj)
996 {
997 MS_U32 u32BlitIdx;
998 GE_Rect geBlitSrc;
999 GE_DstBitBltType geBlitDst;
1000 MS_S32 s32FixSrcX, s32FixSrcY;
1001 MS_S32 s32FixDstX0, s32FixDstY0, s32FixDstX1, s32FixDstY1;
1002
1003 //Prepare Fix Type Src
1004 s32FixSrcX = INT_TO_FIX32(pTrapeBatchBlitObj->u32SrcX);
1005 s32FixSrcY = INT_TO_FIX32(pTrapeBatchBlitObj->u32SrcY);
1006 //Prepare Fix Type Dst
1007 s32FixDstX0 = INT_TO_FIX32(pTrapeBatchBlitObj->u32DstX0);
1008 s32FixDstY0 = INT_TO_FIX32(pTrapeBatchBlitObj->u32DstY0);
1009 s32FixDstX1 = INT_TO_FIX32(pTrapeBatchBlitObj->u32DstX1);
1010 s32FixDstY1 = INT_TO_FIX32(pTrapeBatchBlitObj->u32DstY1);
1011
1012 for(u32BlitIdx=0; u32BlitIdx<pTrapeBatchBlitObj->u32TrapeHeight; u32BlitIdx++)
1013 {
1014 //Prepare Src:
1015 geBlitSrc.x = FIX32_TO_INT(s32FixSrcX);
1016 geBlitSrc.y = FIX32_TO_INT(s32FixSrcY);
1017 geBlitSrc.width = pTrapeBatchBlitObj->u32SrcW;
1018 geBlitSrc.height = pTrapeBatchBlitObj->u32SrcH;
1019 //Prepare Dst:
1020 geBlitDst.dstblk.x = FIX32_TO_INT(s32FixDstX0);
1021 geBlitDst.dstblk.y = FIX32_TO_INT(s32FixDstY0);
1022 geBlitDst.dstblk.width = FIX32_TO_INT(s32FixDstX1) - geBlitDst.dstblk.x + 1;
1023 geBlitDst.dstblk.height = FIX32_TO_INT(s32FixDstY1) - geBlitDst.dstblk.y + 1;
1024 //BitBlit:
1025 MDrv_GE_BitBltEX((GE_Context *)pGECtxLocal, &geBlitSrc, &geBlitDst, pTrapeBatchBlitObj->u32BlitFlags, NULL);
1026
1027 //Delta change of Src:
1028 s32FixSrcX += pTrapeBatchBlitObj->s32DeltaSrcX;
1029 s32FixSrcY += pTrapeBatchBlitObj->s32DeltaSrcY;
1030 //Delta change of Dst:
1031 s32FixDstX0 += pTrapeBatchBlitObj->s32DeltaDstX0;
1032 s32FixDstY0 += pTrapeBatchBlitObj->s32DeltaDstY0;
1033 s32FixDstX1 += pTrapeBatchBlitObj->s32DeltaDstX1;
1034 s32FixDstY1 += pTrapeBatchBlitObj->s32DeltaDstY1;
1035 }
1036
1037 return (E_GE_OK);
1038 }
1039
GE_TrapezoidBlit(GE_CTX_LOCAL * pGECtxLocal,GE_Rect * pSrcRect,GE_Normalized_Trapezoid * pGENormTrapezoid,MS_U32 u32Flags,GE_ScaleInfo * pScaleinfo)1040 static GE_Result GE_TrapezoidBlit(GE_CTX_LOCAL *pGECtxLocal, GE_Rect *pSrcRect, GE_Normalized_Trapezoid *pGENormTrapezoid, MS_U32 u32Flags, GE_ScaleInfo* pScaleinfo)
1041 {
1042 GE_TrapeBatchBlitObj geTrapeBatchBlitObj;
1043 MS_BOOL bYTrapezoid = (u32Flags & E_GE_FLAG_TRAPEZOID_Y) ? TRUE : FALSE;
1044
1045 geTrapeBatchBlitObj.u32BlitFlags = (u32Flags & (E_GE_FLAG_BLT_STRETCH | E_GE_FLAG_STRETCH_NEAREST | E_GE_FLAG_BLT_ITALIC));
1046
1047 //Prepare & Translate Trapezoid BatchBlit Parames:
1048 if(bYTrapezoid)
1049 {
1050 //Trapezoid Height:
1051 geTrapeBatchBlitObj.u32TrapeHeight = pGENormTrapezoid->u16X0 - pGENormTrapezoid->u16X1 + 1;
1052 //Prepare Flag:
1053 geTrapeBatchBlitObj.u32BlitFlags |= (u32Flags & E_GE_FLAG_BLT_MIRROR_V);
1054 //Prepare Src:
1055 geTrapeBatchBlitObj.u32SrcX = (u32Flags & E_GE_FLAG_BLT_MIRROR_H) ? pSrcRect->x : (pSrcRect->x+pSrcRect->width);
1056 geTrapeBatchBlitObj.u32SrcY = (u32Flags & E_GE_FLAG_BLT_MIRROR_V) ? (pSrcRect->y+pSrcRect->height-1) : pSrcRect->y;
1057 geTrapeBatchBlitObj.u32SrcW = 0x1;
1058 geTrapeBatchBlitObj.u32SrcH = pSrcRect->height;
1059 geTrapeBatchBlitObj.s32DeltaSrcX = (u32Flags & E_GE_FLAG_BLT_MIRROR_H) ? pScaleinfo->x : (-(pScaleinfo->x));
1060 geTrapeBatchBlitObj.s32DeltaSrcY = 0x0;
1061
1062 //Prepare Dst:
1063 geTrapeBatchBlitObj.u32DstX0 = pGENormTrapezoid->u16X0;
1064 geTrapeBatchBlitObj.u32DstY0 = pGENormTrapezoid->u16Y0;
1065 geTrapeBatchBlitObj.u32DstX1 = pGENormTrapezoid->u16X0;
1066 geTrapeBatchBlitObj.u32DstY1 = pGENormTrapezoid->u16Y1;
1067 geTrapeBatchBlitObj.s32DeltaDstX0 = -(INT_TO_FIX32(0x1));
1068 geTrapeBatchBlitObj.s32DeltaDstY0 = (pGENormTrapezoid->u32DeltaL & (0x1<<(5+12))) ? (-((MS_S32)((MS_U32)((0x1<<(6+12))-pGENormTrapezoid->u32DeltaL)))) : (MS_S32)(pGENormTrapezoid->u32DeltaL);
1069 geTrapeBatchBlitObj.s32DeltaDstX1 = -(INT_TO_FIX32(0x1));
1070 geTrapeBatchBlitObj.s32DeltaDstY1 = (pGENormTrapezoid->u32DeltaR & (0x1<<(5+12))) ? (-((MS_S32)((MS_U32)((0x1<<(6+12))-pGENormTrapezoid->u32DeltaR)))) : (MS_S32)(pGENormTrapezoid->u32DeltaR);
1071 }
1072 else
1073 {
1074 //Trapezoid Height:
1075 geTrapeBatchBlitObj.u32TrapeHeight = pGENormTrapezoid->u16Y1 - pGENormTrapezoid->u16Y0 + 1;
1076 //Prepare Flag:
1077 geTrapeBatchBlitObj.u32BlitFlags |= (u32Flags & E_GE_FLAG_BLT_MIRROR_H);
1078 //Prepare Src:
1079 geTrapeBatchBlitObj.u32SrcX = (u32Flags & E_GE_FLAG_BLT_MIRROR_H) ? (pSrcRect->x+pSrcRect->width-1) : pSrcRect->x;
1080 geTrapeBatchBlitObj.u32SrcY = (u32Flags & E_GE_FLAG_BLT_MIRROR_V) ? (pSrcRect->y+pSrcRect->height) : pSrcRect->y;
1081 geTrapeBatchBlitObj.u32SrcW = pSrcRect->width;
1082 geTrapeBatchBlitObj.u32SrcH = 0x1;
1083 geTrapeBatchBlitObj.s32DeltaSrcX = 0x0;
1084 geTrapeBatchBlitObj.s32DeltaSrcY = (u32Flags & E_GE_FLAG_BLT_MIRROR_V) ? (-(MS_S32)pScaleinfo->y) : (MS_S32)pScaleinfo->y;
1085 //Prepare Dst:
1086 geTrapeBatchBlitObj.u32DstX0 = pGENormTrapezoid->u16X0;
1087 geTrapeBatchBlitObj.u32DstY0 = pGENormTrapezoid->u16Y0;
1088 geTrapeBatchBlitObj.u32DstX1 = pGENormTrapezoid->u16X1;
1089 geTrapeBatchBlitObj.u32DstY1 = pGENormTrapezoid->u16Y0;
1090 geTrapeBatchBlitObj.s32DeltaDstX0 = (pGENormTrapezoid->u32DeltaL & (0x1<<(5+12))) ? (-(MS_S32)((MS_U32)((0x1<<(6+12))-pGENormTrapezoid->u32DeltaL))) : (MS_S32)(pGENormTrapezoid->u32DeltaL);
1091 geTrapeBatchBlitObj.s32DeltaDstY0 = INT_TO_FIX32(0x1);
1092 geTrapeBatchBlitObj.s32DeltaDstX1 = (pGENormTrapezoid->u32DeltaR & (0x1<<(5+12))) ? (-(MS_S32)((MS_U32)((0x1<<(6+12))-pGENormTrapezoid->u32DeltaR))) : (MS_S32)(pGENormTrapezoid->u32DeltaR);
1093 geTrapeBatchBlitObj.s32DeltaDstY1 = INT_TO_FIX32(0x1);
1094 }
1095
1096 return GE_TrapezoidBlitEx(pGECtxLocal, &geTrapeBatchBlitObj);
1097 }
1098
GE_TrapezoidFillEx(GE_CTX_LOCAL * pGECtxLocal,GE_TrapeBatchFillObj * pTrapeBatchFillObj)1099 static GE_Result GE_TrapezoidFillEx(GE_CTX_LOCAL *pGECtxLocal, GE_TrapeBatchFillObj *pTrapeBatchFillObj)
1100 {
1101 MS_U32 u32FillIdx;
1102 GE_Rect geFillDst;
1103 MS_S32 s32ColorB, s32ColorG, s32ColorR, s32ColorA;
1104 MS_S32 s32FixDstX0, s32FixDstY0, s32FixDstX1, s32FixDstY1;
1105
1106 //Prepare Fix Type Src Color
1107 s32ColorB = INT_TO_FIX32((pTrapeBatchFillObj->u32ColorS & 0xFF));
1108 s32ColorG = INT_TO_FIX32(((pTrapeBatchFillObj->u32ColorS>>0x8) & 0xFF));
1109 s32ColorR = INT_TO_FIX32(((pTrapeBatchFillObj->u32ColorS>>0x10) & 0xFF));
1110 s32ColorA = INT_TO_FIX32(((pTrapeBatchFillObj->u32ColorS>>0x18) & 0xFF));
1111
1112 //Prepare Fix Type Dst
1113 s32FixDstX0 = INT_TO_FIX32(pTrapeBatchFillObj->u32DstX0);
1114 s32FixDstY0 = INT_TO_FIX32(pTrapeBatchFillObj->u32DstY0);
1115 s32FixDstX1 = INT_TO_FIX32(pTrapeBatchFillObj->u32DstX1);
1116 s32FixDstY1 = INT_TO_FIX32(pTrapeBatchFillObj->u32DstY1);
1117
1118 for(u32FillIdx=0; u32FillIdx<pTrapeBatchFillObj->u32TrapeHeight; u32FillIdx++)
1119 {
1120 //Prepare Src:
1121 pTrapeBatchFillObj->u32ColorS = ((FIX32_TO_INT(s32ColorB) & 0xFF)
1122 | ((FIX32_TO_INT(s32ColorG) & 0xFF)<<0x8)
1123 | ((FIX32_TO_INT(s32ColorR) & 0xFF)<<0x10)
1124 | ((FIX32_TO_INT(s32ColorA) & 0xFF)<<0x18));
1125
1126 //Prepare Dst:
1127 geFillDst.x = FIX32_TO_INT(s32FixDstX0);
1128 geFillDst.y = FIX32_TO_INT(s32FixDstY0);
1129 geFillDst.width = FIX32_TO_INT(s32FixDstX1) - geFillDst.x + 1;
1130 geFillDst.height = FIX32_TO_INT(s32FixDstY1) - geFillDst.y + 1;
1131
1132 //Fill Rect:
1133 MDrv_GE_FillRect((GE_Context *)pGECtxLocal, &geFillDst, pTrapeBatchFillObj->u32ColorS, pTrapeBatchFillObj->u32ColorE, pTrapeBatchFillObj->u32FillFlags);
1134
1135 //Delta change of Src ColorS:
1136 s32ColorB += pTrapeBatchFillObj->s32ColorDeltaB;
1137 s32ColorG += pTrapeBatchFillObj->s32ColorDeltaG;
1138 s32ColorR += pTrapeBatchFillObj->s32ColorDeltaR;
1139 s32ColorA += pTrapeBatchFillObj->s32ColorDeltaA;
1140
1141 //Delta change of Dst:
1142 s32FixDstX0 += pTrapeBatchFillObj->s32DeltaDstX0;
1143 s32FixDstY0 += pTrapeBatchFillObj->s32DeltaDstY0;
1144 s32FixDstX1 += pTrapeBatchFillObj->s32DeltaDstX1;
1145 s32FixDstY1 += pTrapeBatchFillObj->s32DeltaDstY1;
1146 }
1147
1148 return (E_GE_OK);
1149 }
1150
GE_TrapezoidFill(GE_CTX_LOCAL * pGECtxLocal,MS_BOOL bYTrapezoid,GE_Normalized_Trapezoid * pGENormTrapezoid,MS_U32 u32ColorS,MS_U32 u32ColorE,GE_ColorDelta * pColorDeltaX,GE_ColorDelta * pColorDeltaY)1151 static GE_Result GE_TrapezoidFill(GE_CTX_LOCAL *pGECtxLocal, MS_BOOL bYTrapezoid, GE_Normalized_Trapezoid *pGENormTrapezoid, MS_U32 u32ColorS, MS_U32 u32ColorE, GE_ColorDelta *pColorDeltaX, GE_ColorDelta *pColorDeltaY)
1152 {
1153 GE_TrapeBatchFillObj geTrapeBatchFillObj;
1154
1155 geTrapeBatchFillObj.u32FillFlags = 0x0;
1156 //Prepare Fill Color:
1157 geTrapeBatchFillObj.u32ColorS = u32ColorS;
1158 geTrapeBatchFillObj.u32ColorE = u32ColorE;
1159
1160 //Prepare & Translate Trapezoid BatchBlit Parames:
1161 if(bYTrapezoid)
1162 {
1163 //Trapezoid Height:
1164 geTrapeBatchFillObj.u32TrapeHeight = pGENormTrapezoid->u16X0 - pGENormTrapezoid->u16X1 + 1;
1165
1166 //Prepare Flag:
1167 if(NULL != pColorDeltaY)
1168 {
1169 geTrapeBatchFillObj.u32FillFlags = (E_GE_FLAG_RECT_GRADIENT_Y);
1170 }
1171
1172 //Prepare Src Delta:
1173 if(NULL != pColorDeltaX)
1174 {
1175 geTrapeBatchFillObj.s32ColorDeltaB = (pColorDeltaX->b & (0x1<<(7+12))) ? (-(MS_S32)((MS_U32)((0x1<<(1+7+12))-pColorDeltaX->b))) : (MS_S32)(pColorDeltaX->b);
1176 geTrapeBatchFillObj.s32ColorDeltaG = (pColorDeltaX->g & (0x1<<(7+12))) ? (-(MS_S32)((MS_U32)((0x1<<(1+7+12))-pColorDeltaX->g))) : (MS_S32)(pColorDeltaX->g);
1177 geTrapeBatchFillObj.s32ColorDeltaR = (pColorDeltaX->r & (0x1<<(7+12))) ? (-(MS_S32)((MS_U32)((0x1<<(1+7+12))-pColorDeltaX->r))) : (MS_S32)(pColorDeltaX->r);
1178 geTrapeBatchFillObj.s32ColorDeltaA = (pColorDeltaX->a & (0x1<<(4+11))) ? (-(MS_S32)((MS_U32)((0x1<<(1+4+11))-pColorDeltaX->a))) : (MS_S32)(pColorDeltaX->a);
1179 geTrapeBatchFillObj.s32ColorDeltaA <<= 1;
1180 }
1181 else
1182 {
1183 geTrapeBatchFillObj.s32ColorDeltaB = geTrapeBatchFillObj.s32ColorDeltaG =
1184 geTrapeBatchFillObj.s32ColorDeltaR = geTrapeBatchFillObj.s32ColorDeltaA = 0x0;
1185 }
1186
1187 //Prepare Dst:
1188 geTrapeBatchFillObj.u32DstX0 = pGENormTrapezoid->u16X0;
1189 geTrapeBatchFillObj.u32DstY0 = pGENormTrapezoid->u16Y0;
1190 geTrapeBatchFillObj.u32DstX1 = pGENormTrapezoid->u16X0;
1191 geTrapeBatchFillObj.u32DstY1 = pGENormTrapezoid->u16Y1;
1192 geTrapeBatchFillObj.s32DeltaDstX0 = -(INT_TO_FIX32(0x1));
1193 geTrapeBatchFillObj.s32DeltaDstY0 = (pGENormTrapezoid->u32DeltaL & (0x1<<(5+12))) ? (-(MS_S32)((MS_U32)((0x1<<(6+12))-pGENormTrapezoid->u32DeltaL))) : (MS_S32)(pGENormTrapezoid->u32DeltaL);
1194 geTrapeBatchFillObj.s32DeltaDstX1 = -(INT_TO_FIX32(0x1));
1195 geTrapeBatchFillObj.s32DeltaDstY1 = (pGENormTrapezoid->u32DeltaR & (0x1<<(5+12))) ? (-(MS_S32)((MS_U32)((0x1<<(6+12))-pGENormTrapezoid->u32DeltaR))) : (MS_S32)(pGENormTrapezoid->u32DeltaR);
1196 }
1197 else
1198 {
1199 //Trapezoid Height:
1200 geTrapeBatchFillObj.u32TrapeHeight = pGENormTrapezoid->u16Y1 - pGENormTrapezoid->u16Y0 + 1;
1201 //Prepare Flag:
1202 if(NULL != pColorDeltaX)
1203 {
1204 geTrapeBatchFillObj.u32FillFlags = (E_GE_FLAG_RECT_GRADIENT_X);
1205 }
1206 //Prepare Src Delta:
1207 if(NULL != pColorDeltaY)
1208 {
1209 geTrapeBatchFillObj.s32ColorDeltaB = (pColorDeltaY->b & (0x1<<(7+12))) ? (-(MS_S32)((MS_U32)((0x1<<(1+7+12))-pColorDeltaY->b))) : (MS_S32)(pColorDeltaY->b);
1210 geTrapeBatchFillObj.s32ColorDeltaG = (pColorDeltaY->g & (0x1<<(7+12))) ? (-(MS_S32)((MS_U32)((0x1<<(1+7+12))-pColorDeltaY->g))) : (MS_S32)(pColorDeltaY->g);
1211 geTrapeBatchFillObj.s32ColorDeltaR = (pColorDeltaY->r & (0x1<<(7+12))) ? (-(MS_S32)((MS_U32)((0x1<<(1+7+12))-pColorDeltaY->r))) : (MS_S32)(pColorDeltaY->r);
1212 geTrapeBatchFillObj.s32ColorDeltaA = (pColorDeltaY->a & (0x1<<(4+11))) ? (-(MS_S32)((MS_U32)((0x1<<(1+4+11))-pColorDeltaY->a))) : (MS_S32)(pColorDeltaY->a);
1213 geTrapeBatchFillObj.s32ColorDeltaA <<= 1;
1214 }
1215 else
1216 {
1217 geTrapeBatchFillObj.s32ColorDeltaB = geTrapeBatchFillObj.s32ColorDeltaG =
1218 geTrapeBatchFillObj.s32ColorDeltaR = geTrapeBatchFillObj.s32ColorDeltaA = 0x0;
1219 }
1220
1221 //Prepare Dst:
1222 geTrapeBatchFillObj.u32DstX0 = pGENormTrapezoid->u16X0;
1223 geTrapeBatchFillObj.u32DstY0 = pGENormTrapezoid->u16Y0;
1224 geTrapeBatchFillObj.u32DstX1 = pGENormTrapezoid->u16X1;
1225 geTrapeBatchFillObj.u32DstY1 = pGENormTrapezoid->u16Y0;
1226 geTrapeBatchFillObj.s32DeltaDstX0 = (pGENormTrapezoid->u32DeltaL & (0x1<<(5+12))) ? (-(MS_S32)((MS_U32)((0x1<<(6+12))-pGENormTrapezoid->u32DeltaL))) : (MS_S32)(pGENormTrapezoid->u32DeltaL);
1227 geTrapeBatchFillObj.s32DeltaDstY0 = INT_TO_FIX32(0x1);
1228 geTrapeBatchFillObj.s32DeltaDstX1 = (pGENormTrapezoid->u32DeltaR & (0x1<<(5+12))) ? (-(MS_S32)((MS_U32)((0x1<<(6+12))-pGENormTrapezoid->u32DeltaR))) : (MS_S32)(pGENormTrapezoid->u32DeltaR);
1229 geTrapeBatchFillObj.s32DeltaDstY1 = INT_TO_FIX32(0x1);
1230 }
1231
1232 return GE_TrapezoidFillEx(pGECtxLocal, &geTrapeBatchFillObj);
1233 }
1234 #endif
1235 //-------------------------------------------------------------------------------------------------
1236 // Global Functions
1237 //-------------------------------------------------------------------------------------------------
1238 //-------------------------------------------------------------------------------------------------
1239 /// Allocate semaphore resource for GE
1240 /// @param pGECtx \b IN: GE context
1241 /// @return @ref GE_Result
1242 //-------------------------------------------------------------------------------------------------
GE_Get_Resource(GE_Context * pGECtx,MS_BOOL bHWSemLock)1243 GE_Result GE_Get_Resource(GE_Context *pGECtx, MS_BOOL bHWSemLock)
1244 {
1245 GE_BeginDraw(pGECtx,bHWSemLock);
1246 return E_GE_OK;
1247 }
1248
1249 /******************************************************************************/
1250 ///To release GE control right from system for hk51
1251 /******************************************************************************/
1252 //-------------------------------------------------------------------------------------------------
1253 /// Release semaphore resource occupied by GE
1254 /// @param pGECtx \b IN: GE context
1255 /// @return @ref GE_Result
1256 //-------------------------------------------------------------------------------------------------
GE_Free_Resource(GE_Context * pGECtx,MS_BOOL bHWSemLock)1257 GE_Result GE_Free_Resource(GE_Context *pGECtx, MS_BOOL bHWSemLock)
1258 {
1259 GE_EndDraw(pGECtx,bHWSemLock);
1260 return E_GE_OK;
1261 }
1262
1263
MDrv_GE_Get_Semaphore(GE_Context * pGECtx,MS_U32 u32RPoolID)1264 GE_Result MDrv_GE_Get_Semaphore(GE_Context *pGECtx, MS_U32 u32RPoolID)
1265 {
1266 #if GE_RESOURCE_SEM
1267 void* pModule = NULL;
1268 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1269
1270 if(pGECtxLocal->ctxHeader.bGEMode4MultiProcessAccess ==TRUE)
1271 {
1272 if(u32RPoolID >=E_GE_POOL_ID_MAX)
1273 {
1274 GE_D_ERR("[%s %d]Unkown GE Pool ID!",__FUNCTION__,__LINE__);
1275 return E_GE_FAIL;
1276 }
1277
1278 UtopiaInstanceGetModule(pGECtxLocal->ctxHeader.pInstance, &pModule);
1279
1280 /*In order to store resource addr of each instance*/
1281 if(UtopiaResourceObtain(pModule, E_GE_POOL_ID_INTERNAL_REGISTER, &g_pGFXResource[u32RPoolID]) != UTOPIA_STATUS_SUCCESS)
1282 {
1283 GFX_CRITIAL_MSG(GE_D_ERR("[%s:%s:%d]UtopiaResourceObtainToInstant fail\n",__FILE__,__FUNCTION__,__LINE__));
1284 return E_GE_FAIL;
1285 }
1286 }
1287 #endif
1288 return E_GE_OK;
1289
1290 }
1291
MDrv_GE_Free_Semaphore(GE_Context * pGECtx,MS_U32 u32RPoolID)1292 GE_Result MDrv_GE_Free_Semaphore(GE_Context *pGECtx, MS_U32 u32RPoolID)
1293 {
1294 #if GE_RESOURCE_SEM
1295 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1296
1297 if(pGECtxLocal->ctxHeader.bGEMode4MultiProcessAccess ==TRUE)
1298 {
1299 if(u32RPoolID >=E_GE_POOL_ID_MAX)
1300 {
1301 GE_D_ERR("[%s %d]Unkown GE Pool ID!",__FUNCTION__,__LINE__);
1302 return E_GE_FAIL;
1303 }
1304
1305 UtopiaResourceRelease(g_pGFXResource[u32RPoolID]);
1306 }
1307 #endif
1308 return E_GE_OK;
1309 }
1310
1311 //-------------------------------------------------------------------------------------------------
1312 /// Reset GE setting
1313 /// @param pGECtx \b IN: GE context
1314 /// @return @ref GE_Result
1315 //-------------------------------------------------------------------------------------------------
MDrv_GE_Reset(GE_Context * pGECtx)1316 GE_Result MDrv_GE_Reset(GE_Context *pGECtx)
1317 {
1318 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1319
1320 GE_ENTRY(pGECtx);
1321
1322 // Reset some GE state settings
1323 GE_ResetState(&pGECtxLocal->halLocalCtx);
1324
1325 GE_RETURN(pGECtx,E_GE_OK);
1326 }
1327
1328
1329 //-------------------------------------------------------------------------------------------------
1330 /// Set GE dither
1331 /// @param pGECtx \b IN: GE context
1332 /// @param enable \b IN: enable and update setting
1333 /// @return @ref GE_Result
1334 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetDither(GE_Context * pGECtx,MS_BOOL enable)1335 GE_Result MDrv_GE_SetDither(GE_Context *pGECtx, MS_BOOL enable)
1336 {
1337 MS_U16 u16en;
1338 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1339
1340 GE_DBG("%s\n", __FUNCTION__);
1341 GE_ENTRY(pGECtx);
1342
1343 u16en = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_EN);
1344 if (enable)
1345 {
1346 u16en |= GE_EN_DITHER;
1347 }
1348 else
1349 {
1350 u16en &= ~GE_EN_DITHER;
1351 }
1352 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, u16en);
1353
1354 GE_RETURN(pGECtx,E_GE_OK);
1355 }
1356 //-------------------------------------------------------------------------------------------------
1357 /// Set GE One pixel Mode
1358 /// @param pGECtx \b IN: GE context
1359 /// @param enable \b IN: enable and update setting
1360 /// @return @ref GE_Result
1361 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetOnePixelMode(GE_Context * pGECtx,MS_BOOL enable)1362 GE_Result MDrv_GE_SetOnePixelMode(GE_Context *pGECtx, MS_BOOL enable)
1363 {
1364
1365 if ( pGECtx == NULL )
1366 {
1367 GE_D_ERR("\n%s, %d, 1st param. can't be null pointer\n", __FUNCTION__, __LINE__);
1368 return E_GE_FAIL;
1369 }
1370
1371 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1372 GE_Result geResult;
1373
1374 GE_DBG("%s\n", __FUNCTION__);
1375 GE_ENTRY(pGECtx);
1376
1377 geResult = GE_SetOnePixelMode(&pGECtxLocal->halLocalCtx, enable);
1378
1379 GE_RETURN(pGECtx, geResult);
1380 }
1381
1382
1383 //-------------------------------------------------------------------------------------------------
1384 /// Set GE source color key
1385 /// @param pGECtx \b IN: GE context
1386 /// @param enable \b IN: enable and update setting
1387 /// @param eCKOp \b IN: source color key mode
1388 /// @param ck_low \b IN: lower value of color key (E_GE_FMT_ARGB8888)
1389 /// @param ck_high \b IN: upper value of color key (E_GE_FMT_ARGB8888)
1390 /// @return @ref GE_Result
1391 /// @attention
1392 /// <b>[URANUS] <em>color key does not check alpha channel</em></b>
1393 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetSrcColorKey(GE_Context * pGECtx,MS_BOOL enable,GE_CKOp eCKOp,MS_U32 ck_low,MS_U32 ck_high)1394 GE_Result MDrv_GE_SetSrcColorKey(GE_Context *pGECtx, MS_BOOL enable, GE_CKOp eCKOp, MS_U32 ck_low, MS_U32 ck_high)
1395 {
1396 MS_U16 u16en=0, u16op;
1397 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1398
1399 GE_DBG("%s\n", __FUNCTION__);
1400 GE_ENTRY(pGECtx);
1401
1402 u16op = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_OP_MODE);
1403
1404 switch(eCKOp)
1405 {
1406 case E_GE_CK_EQ:
1407 u16en = GE_EN_SCK;
1408 u16op &= ~(GE_BIT0);
1409 break;
1410 case E_GE_CK_NE:
1411 u16en = GE_EN_SCK;
1412 u16op |= GE_BIT0;
1413 break;
1414 case E_GE_ALPHA_EQ:
1415 u16en = GE_EN_ASCK;
1416 u16op &= ~(GE_BIT2);
1417 break;
1418 case E_GE_ALPHA_NE:
1419 u16en = GE_EN_ASCK;
1420 u16op |= GE_BIT2;
1421 break;
1422 default:
1423 break;
1424 }
1425
1426 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_OP_MODE, u16op);
1427
1428 if (enable)
1429 {
1430 // Color key threshold
1431 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_SCK_LTH_L, ck_low & 0xFFFF);
1432 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_SCK_LTH_H, (ck_low >> 16));
1433 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_SCK_HTH_L, (ck_high & 0xFFFF));
1434 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_SCK_HTH_H, (ck_high >> 16));
1435 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, (GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_EN)|u16en));
1436 }
1437 else
1438 {
1439 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, (GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_EN)&(~u16en)));
1440 }
1441
1442 GE_RETURN(pGECtx,E_GE_OK);
1443 }
1444
1445
1446 //-------------------------------------------------------------------------------------------------
1447 /// Set GE destination color key
1448 /// @param pGECtx \b IN: GE context
1449 /// @param enable \b IN: enable and update setting
1450 /// @param eCKOp \b IN: source color key mode
1451 /// @param ck_low \b IN: lower value of color key (E_GE_FMT_ARGB8888)
1452 /// @param ck_high \b IN: upper value of color key (E_GE_FMT_ARGB8888)
1453 /// @return @ref GE_Result
1454 /// @attention
1455 /// <b>[URANUS] <em>color key does not check alpha channel</em></b>
1456 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetDstColorKey(GE_Context * pGECtx,MS_BOOL enable,GE_CKOp eCKOp,MS_U32 ck_low,MS_U32 ck_high)1457 GE_Result MDrv_GE_SetDstColorKey(GE_Context *pGECtx, MS_BOOL enable, GE_CKOp eCKOp, MS_U32 ck_low, MS_U32 ck_high)
1458 {
1459 MS_U16 u16en=0, u16op;
1460 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1461
1462 GE_DBG("%s\n", __FUNCTION__);
1463 GE_ENTRY(pGECtx);
1464
1465 u16op = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_OP_MODE);
1466
1467 switch(eCKOp)
1468 {
1469 case E_GE_CK_EQ:
1470 u16en = GE_EN_DCK;
1471 u16op &= ~(GE_BIT1);
1472 break;
1473 case E_GE_CK_NE:
1474 u16en = GE_EN_DCK;
1475 u16op |= GE_BIT1;
1476 break;
1477 case E_GE_ALPHA_EQ:
1478 u16en = GE_EN_DSCK;
1479 u16op &= ~(GE_BIT3);
1480 break;
1481 case E_GE_ALPHA_NE:
1482 u16en = GE_EN_DSCK;
1483 u16op |= GE_BIT3;
1484 break;
1485 default:
1486 break;
1487 }
1488
1489 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_OP_MODE, u16op);
1490
1491 if (enable)
1492 {
1493 // Color key threshold
1494 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_DCK_LTH_L, (ck_low & 0xFFFF));
1495 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_DCK_LTH_H, (ck_high >> 16));
1496 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_DCK_HTH_L, (ck_low & 0xFFFF));
1497 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_DCK_HTH_H, (ck_high >> 16));
1498 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, (GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_EN)|u16en));
1499 }
1500 else
1501 {
1502 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, (GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_EN)&(~u16en)));
1503 }
1504
1505 GE_RETURN(pGECtx,E_GE_OK);
1506 }
1507
1508
1509 //-------------------------------------------------------------------------------------------------
1510 /// Set GE I1,I2,I4 color palette
1511 /// @param pGECtx \b IN: GE context
1512 /// @param idx \b IN: index of palette
1513 /// @param color \b IN: intensity color format (E_GE_FMT_ARGB8888, E_GE_FMT_I8)
1514 /// @return @ref GE_Result
1515 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetIntensity(GE_Context * pGECtx,MS_U32 idx,MS_U32 color)1516 GE_Result MDrv_GE_SetIntensity(GE_Context *pGECtx, MS_U32 idx, MS_U32 color)
1517 {
1518 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1519
1520 GE_DBG("%s\n", __FUNCTION__);
1521 GE_ENTRY(pGECtx);
1522
1523 if (idx < 16)
1524 {
1525 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_C_L(idx), (color & 0xFFFF));
1526 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_C_H(idx), (color >> 16));
1527 }
1528 else
1529 {
1530 GE_RETURN(pGECtx,E_GE_FAIL_PARAM);
1531 }
1532
1533 GE_RETURN(pGECtx,E_GE_OK);
1534 }
1535 //-------------------------------------------------------------------------------------------------
1536 /// Get GE I1,I2,I4 color palette
1537 /// @param pGECtx \b IN: GE context
1538 /// @param idx \b IN: index of palette
1539 /// @param color \b IN: intensity color format (E_GE_FMT_ARGB8888, E_GE_FMT_I8)
1540 /// @return @ref GE_Result
1541 //-------------------------------------------------------------------------------------------------
MDrv_GE_GetIntensity(GE_Context * pGECtx,MS_U32 idx,MS_U32 * color)1542 GE_Result MDrv_GE_GetIntensity(GE_Context *pGECtx, MS_U32 idx, MS_U32 *color)
1543 {
1544 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1545
1546 GE_DBG("%s\n", __FUNCTION__);
1547 GE_ENTRY(pGECtx);
1548
1549 if (idx < 16)
1550 {
1551 *color =((MS_U32)GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_C_H(idx)))<<16|(MS_U32)GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_C_L(idx));
1552 }
1553 else
1554 {
1555 GE_RETURN(pGECtx,E_GE_FAIL_PARAM);
1556 }
1557
1558 GE_RETURN(pGECtx,E_GE_OK);
1559 }
1560
1561
1562 //-------------------------------------------------------------------------------------------------
1563 /// Set GE ROP2
1564 /// @param pGECtx \b IN: GE context
1565 /// @param enable \b IN: enable and update setting
1566 /// @param eRop2 \b IN: ROP2 op
1567 /// @return @ref GE_Result
1568 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetROP2(GE_Context * pGECtx,MS_BOOL enable,GE_Rop2 eRop2)1569 GE_Result MDrv_GE_SetROP2(GE_Context *pGECtx, MS_BOOL enable, GE_Rop2 eRop2)
1570 {
1571 MS_U16 u16en, u16rop2;
1572 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1573
1574 GE_DBG("%s\n", __FUNCTION__);
1575 GE_ENTRY(pGECtx);
1576
1577 u16en = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_EN);
1578 if (enable)
1579 {
1580 u16en |= GE_EN_ROP2;
1581
1582 u16rop2 = (GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_ROP2) & ~GE_ROP2_MASK) | eRop2;
1583 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_ROP2, u16rop2);
1584 }
1585 else
1586 {
1587 u16en &= ~GE_EN_ROP2;
1588 }
1589 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, u16en);
1590
1591 GE_RETURN(pGECtx,E_GE_OK);
1592 }
1593
1594
1595 //-------------------------------------------------------------------------------------------------
1596 /// Set GE line pattern style
1597 /// @param pGECtx \b IN: GE context
1598 /// @param enable \b IN: enable and update setting
1599 /// @param pattern \b IN: 0-0x3F bitmap to represent draw(1) or not draw(0)
1600 /// @param eRep \b IN: repeat pattern once, or 2,3,4 times
1601 /// @return @ref GE_Result
1602 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetLinePattern(GE_Context * pGECtx,MS_BOOL enable,MS_U8 pattern,GE_LinePatRep eRep)1603 GE_Result MDrv_GE_SetLinePattern(GE_Context *pGECtx,MS_BOOL enable, MS_U8 pattern, GE_LinePatRep eRep)
1604 {
1605 MS_U16 u16en, u16style;
1606 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1607
1608 GE_DBG("%s\n", __FUNCTION__);
1609 GE_ENTRY(pGECtx);
1610
1611 u16en = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_EN);
1612 if (enable)
1613 {
1614 u16en |= GE_EN_LINEPAT;
1615
1616 u16style = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_LINE_STYLE) & GE_LINEPAT_RST; // keep line pattern setting
1617 u16style |= ((pattern & GE_LINEPAT_MASK) | ((eRep << GE_LINEPAT_REP_SHFT) & GE_LINEPAT_REP_MASK));
1618 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_LINE_STYLE, u16style);
1619 }
1620 else
1621 {
1622 u16en &= ~GE_EN_LINEPAT;
1623
1624 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_LINE_STYLE, GE_LINEPAT_RST); // hardware auto clear
1625 }
1626 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, u16en);
1627
1628 GE_RETURN(pGECtx,E_GE_OK);
1629 }
1630
1631
1632 //-------------------------------------------------------------------------------------------------
1633 /// Reset GE line pattern for next line drawing
1634 /// @param pGECtx \b IN: GE context
1635 /// @return @ref GE_Result
1636 //-------------------------------------------------------------------------------------------------
MDrv_GE_ResetLinePattern(GE_Context * pGECtx)1637 GE_Result MDrv_GE_ResetLinePattern(GE_Context *pGECtx)
1638 {
1639 MS_U16 u16style;
1640 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1641
1642 GE_DBG("%s\n", __FUNCTION__);
1643 GE_ENTRY(pGECtx);
1644
1645 u16style = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_LINE_STYLE) | GE_LINEPAT_RST;
1646 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_LINE_STYLE, u16style);
1647
1648 GE_RETURN(pGECtx,E_GE_OK);
1649 }
1650
1651
1652 //-------------------------------------------------------------------------------------------------
1653 /// Set GE alpha blending of color output. <b><em>Cblend = (coef * Csrc) OP ((1-coef) * Cdst)</em></b>
1654 /// @param pGECtx \b IN: GE context
1655 /// @param enable \b IN: enable and update setting
1656 /// @param eBlendOp \b IN: coef and op for blending
1657 /// @return @ref GE_Result
1658 /// @attention
1659 /// <b>[URANUS] <em>It does not support ROP8 operation</em></b>
1660 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetAlphaBlend(GE_Context * pGECtx,MS_BOOL enable,GE_BlendOp eBlendOp)1661 GE_Result MDrv_GE_SetAlphaBlend(GE_Context *pGECtx,MS_BOOL enable, GE_BlendOp eBlendOp)
1662 {
1663 MS_U16 u16en;
1664 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1665
1666 GE_DBG("%s\n", __FUNCTION__);
1667 GE_ENTRY(pGECtx);
1668 #ifdef GE_SPLIT_SUPPORT
1669 bABL = enable;
1670 #endif
1671 u16en = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_EN);
1672 if (enable)
1673 {
1674 u16en |= GE_EN_BLEND;
1675
1676 if (GE_SetBlend(&pGECtxLocal->halLocalCtx, eBlendOp) != E_GE_OK)
1677 {
1678 GE_RETURN(pGECtx,E_GE_FAIL_PARAM);
1679 }
1680 }
1681 else
1682 {
1683 u16en &= ~GE_EN_BLEND;
1684 }
1685 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, u16en);
1686
1687 GE_RETURN(pGECtx,E_GE_OK);
1688 }
1689
1690 //-------------------------------------------------------------------------------------------------
1691 /// Set GE alpha blending of color output. <b><em>Cblend = (coef * Csrc) OP ((1-coef) * Cdst)</em></b>
1692 /// @param pGECtx \b IN: GE context
1693 /// @param eBlendOp \b IN: coef and op for blending
1694 /// @return @ref GE_Result
1695 /// @attention
1696 /// <b>[URANUS] <em>It does not support ROP8 operation</em></b>
1697 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetAlphaBlendCoef(GE_Context * pGECtx,GE_BlendOp eBlendOp)1698 GE_Result MDrv_GE_SetAlphaBlendCoef(GE_Context *pGECtx, GE_BlendOp eBlendOp)
1699 {
1700 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1701
1702 GE_DBG("%s\n", __FUNCTION__);
1703 GE_ENTRY(pGECtx);
1704
1705 if (GE_SetBlend(&pGECtxLocal->halLocalCtx, eBlendOp) != E_GE_OK)
1706 {
1707 GE_RETURN(pGECtx,E_GE_FAIL_PARAM);
1708 }
1709
1710 GE_RETURN(pGECtx,E_GE_OK);
1711 }
1712
1713 //-------------------------------------------------------------------------------------------------
1714 /// Query GFX supported DFB blending functions/flags.
1715 /// @param pU16SupportedBldFlags \b OUT: DFB Blending Functions/Flags supported by GFX.
1716 /// @return GFX_SUCCESS - Success
1717 /// @return GFX_FAIL - Failure
1718 //-------------------------------------------------------------------------------------------------
MDrv_GE_QueryDFBBldCaps(GE_Context * pGECtx,MS_U16 * pU16SupportedBldFlags)1719 GE_Result MDrv_GE_QueryDFBBldCaps(GE_Context *pGECtx, MS_U16 *pU16SupportedBldFlags)
1720 {
1721 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1722 GE_Result geResult;
1723
1724 GE_DBG("%s\n", __FUNCTION__);
1725
1726 geResult = GE_QueryDFBBldCaps(&pGECtxLocal->halLocalCtx, pU16SupportedBldFlags);
1727
1728 return geResult;
1729 }
1730
1731 //-------------------------------------------------------------------------------------------------
1732 /// Enable GFX DFB blending
1733 /// @param enable \b IN: true/false
1734 /// @return GFX_SUCCESS - Success
1735 /// @return GFX_FAIL - Failure
1736 //-------------------------------------------------------------------------------------------------
MDrv_GE_EnableDFBBlending(GE_Context * pGECtx,MS_BOOL enable)1737 GE_Result MDrv_GE_EnableDFBBlending(GE_Context *pGECtx, MS_BOOL enable)
1738 {
1739 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1740 GE_Result geResult;
1741
1742 GE_DBG("%s\n", __FUNCTION__);
1743 GE_ENTRY(pGECtx);
1744
1745 geResult = GE_EnableDFBBld(&pGECtxLocal->halLocalCtx, enable);
1746
1747 GE_RETURN(pGECtx, geResult);
1748 }
1749
1750 //-------------------------------------------------------------------------------------------------
1751 /// Set GE DFB blending Flags.
1752 /// @param u16DFBBldFlag \b IN: DFB Blending Flags. The Flags will be
1753 /// The combination of Flags
1754 /// [GFX_DFB_BLD_FLAG_COLORALPHA, GFX_DFB_BLD_FLAG_ALPHACHANNEL,
1755 /// GFX_DFB_BLD_FLAG_COLORIZE, GFX_DFB_BLD_FLAG_SRCPREMUL,
1756 /// GFX_DFB_BLD_FLAG_SRCPREMULCOL, GFX_DFB_BLD_FLAG_DSTPREMUL,
1757 /// GFX_DFB_BLD_FLAG_XOR, GFX_DFB_BLD_FLAG_DEMULTIPLY,
1758 /// GFX_DFB_BLD_FLAG_SRCALPHAMASK, GFX_DFB_BLD_FLAG_SRCCOLORMASK]
1759 /// @return GFX_SUCCESS - Success
1760 /// @return GFX_FAIL - Failure
1761 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetDFBBldFlags(GE_Context * pGECtx,MS_U16 u16DFBBldFlags)1762 GE_Result MDrv_GE_SetDFBBldFlags(GE_Context *pGECtx, MS_U16 u16DFBBldFlags)
1763 {
1764 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1765 GE_Result geResult;
1766
1767 GE_DBG("%s\n", __FUNCTION__);
1768 GE_ENTRY(pGECtx);
1769
1770 geResult = GE_SetDFBBldFlags(&pGECtxLocal->halLocalCtx, u16DFBBldFlags);
1771
1772 GE_RETURN(pGECtx, geResult);
1773 }
1774
1775 //-------------------------------------------------------------------------------------------------
1776 /// Set GFX DFB blending Functions/Operations.
1777 /// @param gfxSrcBldOP \b IN: source blending op
1778 /// @param gfxDstBldOP \b IN: dst blending op
1779 /// @return GFX_SUCCESS - Success
1780 /// @return GFX_FAIL - Failure
1781 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetDFBBldOP(GE_Context * pGECtx,GE_DFBBldOP geSrcBldOP,GE_DFBBldOP geDstBldOP)1782 GE_Result MDrv_GE_SetDFBBldOP(GE_Context *pGECtx, GE_DFBBldOP geSrcBldOP, GE_DFBBldOP geDstBldOP)
1783 {
1784 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1785 GE_Result geResult;
1786
1787 GE_DBG("%s\n", __FUNCTION__);
1788 GE_ENTRY(pGECtx);
1789
1790 geResult = GE_SetDFBBldOP(&pGECtxLocal->halLocalCtx, geSrcBldOP, geDstBldOP);
1791
1792 GE_RETURN(pGECtx, geResult);
1793 }
1794
1795 //-------------------------------------------------------------------------------------------------
1796 /// Set GFX DFB blending const color.
1797 /// @param u32ConstColor \b IN: DFB Blending constant color
1798 /// @return GFX_SUCCESS - Success
1799 /// @return GFX_FAIL - Failure
1800 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetDFBBldConstColor(GE_Context * pGECtx,GE_RgbColor geRgbColor)1801 GE_Result MDrv_GE_SetDFBBldConstColor(GE_Context *pGECtx, GE_RgbColor geRgbColor)
1802 {
1803 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1804 GE_Result geResult;
1805
1806 GE_DBG("%s\n", __FUNCTION__);
1807 GE_ENTRY(pGECtx);
1808
1809 geResult = GE_SetDFBBldConstColor(&pGECtxLocal->halLocalCtx, geRgbColor);
1810
1811 GE_RETURN(pGECtx, geResult);
1812 }
1813
1814 //-------------------------------------------------------------------------------------------------
1815 /// Set GFX DFB blending source colormask.
1816 /// @param u32ConstColor \b IN: DFB Blending constant color
1817 /// @return GFX_SUCCESS - Success
1818 /// @return GFX_FAIL - Failure
1819 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetDFBBldSrcColorMask(GE_Context * pGECtx,GE_RgbColor geRgbColor)1820 GE_Result MDrv_GE_SetDFBBldSrcColorMask(GE_Context *pGECtx, GE_RgbColor geRgbColor)
1821 {
1822 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1823 GE_Result geResult;
1824
1825 GE_DBG("%s\n", __FUNCTION__);
1826 GE_ENTRY(pGECtx);
1827
1828 geResult = GE_SetDFBBldSrcColorMask(&pGECtxLocal->halLocalCtx, geRgbColor);
1829
1830 GE_RETURN(pGECtx, geResult);
1831 }
1832
1833
1834 #ifdef CONFIG_GFX_TRAPZOID
MDrv_GE_EnableTrapezoidAA(GE_Context * pGECtx,MS_BOOL bEnable)1835 GE_Result MDrv_GE_EnableTrapezoidAA(GE_Context *pGECtx, MS_BOOL bEnable)
1836 {
1837 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1838 GE_Result geResult;
1839
1840 GE_DBG("%s\n", __FUNCTION__);
1841
1842 GE_ENTRY(pGECtx);
1843
1844 geResult = GE_EnableTrapezoidAA(&pGECtxLocal->halLocalCtx, bEnable);
1845
1846 GE_RETURN(pGECtx, geResult);
1847 }
1848
MDrv_GE_EnableTrapSubPixCorr(GE_Context * pGECtx,MS_BOOL bEnable)1849 GE_Result MDrv_GE_EnableTrapSubPixCorr(GE_Context *pGECtx, MS_BOOL bEnable)
1850 {
1851 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1852 GE_Result geResult;
1853
1854 GE_DBG("%s\n", __FUNCTION__);
1855
1856 GE_ENTRY(pGECtx);
1857
1858 geResult = GE_EnableTrapSubPixCorr(&pGECtxLocal->halLocalCtx, bEnable);
1859
1860 GE_RETURN(pGECtx, geResult);
1861 }
1862 #endif
1863
1864 //-------------------------------------------------------------------------------------------------
1865 /// Set GE clipping window
1866 /// @param pGECtx \b IN: GE context
1867 /// @param rect \b IN: pointer to RECT of clipping window
1868 /// @return @ref GE_Result
1869 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetClipWindow(GE_Context * pGECtx,GE_Rect * rect)1870 GE_Result MDrv_GE_SetClipWindow(GE_Context *pGECtx, GE_Rect *rect)
1871 {
1872 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1873
1874 GE_DBG("%s\n", __FUNCTION__);
1875 GE_ASSERT((rect), E_GE_FAIL_PARAM, "%s: Null pointer\n", __FUNCTION__);
1876
1877 GE_ENTRY(pGECtx);
1878
1879 pGECtxLocal->u16ClipL = rect->x;
1880 pGECtxLocal->u16ClipT = rect->y;
1881 pGECtxLocal->u16ClipR = (rect->x + rect->width - 1);
1882 pGECtxLocal->u16ClipB = (rect->y + rect->height - 1);
1883
1884 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CLIP_L, pGECtxLocal->u16ClipL);
1885 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CLIP_T, pGECtxLocal->u16ClipT);
1886 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CLIP_R, pGECtxLocal->u16ClipR);
1887 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CLIP_B, pGECtxLocal->u16ClipB);
1888
1889 GE_RETURN(pGECtx,E_GE_OK);
1890 }
1891
1892
1893 //-------------------------------------------------------------------------------------------------
1894 /// Get GE clipping window
1895 /// @param pGECtx \b IN: GE context
1896 /// @param rect \b IN: pointer to RECT of clipping window
1897 /// @return @ref GE_Result
1898 //-------------------------------------------------------------------------------------------------
MDrv_GE_GetClipWindow(GE_Context * pGECtx,GE_Rect * rect)1899 GE_Result MDrv_GE_GetClipWindow(GE_Context *pGECtx, GE_Rect *rect)
1900 {
1901 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1902
1903 GE_DBG("%s\n", __FUNCTION__);
1904 GE_ASSERT((rect), E_GE_FAIL_PARAM, "%s: Null pointer\n", __FUNCTION__);
1905
1906 GE_ENTRY(pGECtx);
1907
1908 rect->x = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_CLIP_L);
1909 rect->y = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_CLIP_T);
1910 rect->width = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_CLIP_R)-rect->x+1;
1911 rect->height = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_CLIP_B)-rect->y+1;
1912
1913 GE_RETURN(pGECtx,E_GE_OK);
1914 }
1915
1916
1917 //-------------------------------------------------------------------------------------------------
1918 /// Set GE bitblt italic style
1919 /// @param pGECtx \b IN: GE context
1920 /// @param x_offset \b IN: starting pixel to get italic effect
1921 /// @param y_offset \b IN: starting line to get italic effect
1922 /// @param delta \b IN: italic slope delta [s1.3]
1923 /// @return @ref GE_Result
1924 /// @note\n
1925 /// The italic effect can not perform with rotate process or mirror
1926 /// @sa MDrv_GE_BitBlt, E_GE_FLAG_BLT_ITALIC
1927 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetItalic(GE_Context * pGECtx,MS_U8 x_offset,MS_U8 y_offset,MS_U8 delta)1928 GE_Result MDrv_GE_SetItalic(GE_Context *pGECtx, MS_U8 x_offset, MS_U8 y_offset, MS_U8 delta)
1929 {
1930 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1931
1932 GE_DBG("%s\n", __FUNCTION__);
1933 GE_ENTRY(pGECtx);
1934
1935 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_ITALIC_OFFSET, (((MS_U16)y_offset<<GE_ITALIC_Y_SHFT) | x_offset));
1936 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_ITALIC_DELTA, delta&0x1F); // s1.3
1937
1938 GE_RETURN(pGECtx,E_GE_OK);
1939 }
1940
1941
1942 //-------------------------------------------------------------------------------------------------
1943 /// Set GE constant alpha value for any alpha operation
1944 /// @param pGECtx \b IN: GE context
1945 /// @param aconst \b IN: constant alpha value for output alpha and blending
1946 /// @return @ref GE_Result
1947 /// @sa MDrv_GE_SetAlphaBlend, MDrv_GE_SetAlphaSrc
1948 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetAlphaConst(GE_Context * pGECtx,MS_U8 aconst)1949 GE_Result MDrv_GE_SetAlphaConst(GE_Context *pGECtx, MS_U8 aconst)
1950 {
1951 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1952
1953 GE_DBG("%s\n", __FUNCTION__);
1954 GE_ENTRY(pGECtx);
1955 #ifdef GE_ALPHA_BLEND_PATCH
1956 u16GAlphaConst = (MS_U16)aconst;
1957 #endif
1958 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_ALPHA_CONST, (MS_U16)(aconst&0xff));
1959
1960 GE_RETURN(pGECtx,E_GE_OK);
1961 }
1962
1963
1964 //-------------------------------------------------------------------------------------------------
1965 /// Set GE alpha source for alpha output. <b><em>Aout</em></b>
1966 /// @param pGECtx \b IN: GE context
1967 /// @param eAlphaSrc \b IN: alpha channel comes from
1968 /// @return @ref GE_Result
1969 /// @note
1970 /// <b>(REQUIREMENT) <em>E_GE_ALPHA_ADST requires AlphaBlending(TRUE, )</em></b>
1971 /// @attention
1972 /// <b>[URANUS] <em>It does not support ROP8 operation</em></b>
1973 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetAlphaSrc(GE_Context * pGECtx,GE_AlphaSrc eAlphaSrc)1974 GE_Result MDrv_GE_SetAlphaSrc(GE_Context *pGECtx, GE_AlphaSrc eAlphaSrc)
1975 {
1976 GE_Result ret;
1977 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
1978
1979 GE_DBG("%s\n", __FUNCTION__);
1980 GE_ENTRY(pGECtx);
1981
1982 ret = GE_SetAlpha(&pGECtxLocal->halLocalCtx, eAlphaSrc);
1983
1984 GE_RETURN(pGECtx,ret);
1985 }
1986
1987
1988 //-------------------------------------------------------------------------------------------------
1989 /// Set GE alpha comparison before alpha output. <b><em>Aout = cmp(Aout, Adst)</em></b>
1990 /// @param pGECtx \b IN: GE context
1991 /// @param enable \b IN: enable and update setting
1992 /// @param eACmpOp \b IN: MAX / MIN
1993 /// @return @ref GE_Result
1994 /// @note
1995 /// <b>(REQUIREMENT) <em>It requires AlphaBlending(TRUE, )</em></b>
1996 /// @sa MDrv_GE_SetAlphaSrc
1997 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetAlphaCmp(GE_Context * pGECtx,MS_BOOL enable,GE_ACmpOp eACmpOp)1998 GE_Result MDrv_GE_SetAlphaCmp(GE_Context *pGECtx, MS_BOOL enable, GE_ACmpOp eACmpOp)
1999 {
2000 MS_U16 u16en, u16op;
2001 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
2002
2003 GE_DBG("%s\n", __FUNCTION__);
2004 GE_ENTRY(pGECtx);
2005
2006 u16en = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_EN);
2007 if (enable)
2008 {
2009 u16en |= GE_EN_ACMP;
2010
2011 u16op = (GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_OP_MODE) & ~GE_OP_ACMP_MIN) | ((eACmpOp<<GE_OP_ACMP_SHFT)&GE_OP_ACMP_MIN);
2012 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_OP_MODE, u16op);
2013 }
2014 else
2015 {
2016 u16en &= ~GE_EN_ACMP;
2017 }
2018 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, u16en);
2019
2020 GE_RETURN(pGECtx,E_GE_OK);
2021 }
2022
2023
2024 //-------------------------------------------------------------------------------------------------
2025 /// Set GE destination alpha test for doing alpha blending <b><em>Cout = Adst->[AL,AH] ? Csrc : Cblend</em></b>
2026 /// @param pGECtx \b IN: GE context
2027 /// @param enable \b IN: enable and update setting
2028 /// @param eATestOp \b IN: destination alpha test mode
2029 /// @param a_low \b IN: lower bound of alpha value
2030 /// @param a_high \b IN: upper bound of alpha value
2031 /// @return @ref GE_Result
2032 /// @note
2033 /// <b>(REQUIREMENT) <em>AlphaBlending(TRUE, )</em></b>
2034 /// @attention
2035 /// <b>[URANUS] <em>It does not support alpha test</em></b>
2036 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetAlphaTest(GE_Context * pGECtx,MS_BOOL enable,GE_ATestOp eATestOp,MS_U8 a_low,MS_U8 a_high)2037 GE_Result MDrv_GE_SetAlphaTest(GE_Context *pGECtx, MS_BOOL enable, GE_ATestOp eATestOp, MS_U8 a_low, MS_U8 a_high)
2038 {
2039 MS_U16 u16en, u16op;
2040 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
2041
2042
2043 GE_DBG("%s\n", __FUNCTION__);
2044 GE_ENTRY(pGECtx);
2045
2046 u16en = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_EN);
2047 if (enable)
2048 {
2049 u16en |= GE_EN_ATEST;
2050 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_ATEST_TH, ((MS_U16)a_low<<8) | (a_high));
2051
2052 u16op = (GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_OP_MODE)&~GE_OP_ATEST_NE) | (eATestOp << GE_OP_ATEST_SHFT);
2053 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_OP_MODE, u16op);
2054 }
2055 else
2056 {
2057 u16en &= ~GE_EN_ATEST;
2058 }
2059 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, u16en);
2060
2061 GE_RETURN(pGECtx,E_GE_OK);
2062
2063 }
2064
2065
2066 //-------------------------------------------------------------------------------------------------
2067 /// Set GE color to palette table
2068 /// @param pGECtx \b IN: GE context
2069 /// @param start \b IN: start index of palette (0 - GE_PALETTE_NUM)
2070 /// @param num \b IN: number of palette entry to set
2071 /// @param palette \b IN: user defined palette color table
2072 /// @return @ref GE_Result
2073 /// @attention
2074 /// <b>[URANUS] <em>It does not support palette</em></b>
2075 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetPalette(GE_Context * pGECtx,MS_U16 start,MS_U16 num,MS_U32 * palette)2076 GE_Result MDrv_GE_SetPalette(GE_Context *pGECtx, MS_U16 start, MS_U16 num, MS_U32 *palette)
2077 {
2078 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
2079 MS_U32 i;
2080
2081 GE_DBG("%s\n", __FUNCTION__);
2082 GE_ASSERT((palette), E_GE_FAIL_PARAM, "%s: Null pointer\n", __FUNCTION__);
2083
2084 if ((start + num) > GE_PALETTE_NUM)
2085 {
2086 return (E_GE_FAIL_PARAM);
2087 }
2088
2089 for (i = 0; i < num; i++)
2090 {
2091 pGECtxLocal->halLocalCtx.u32Palette[start+i] = palette[i];
2092 }
2093
2094 pGECtxLocal->halLocalCtx.bPaletteDirty = TRUE;
2095
2096 return (E_GE_OK);
2097 }
2098
2099
2100 //-------------------------------------------------------------------------------------------------
2101 /// Get GE color from palette table
2102 /// @param pGECtx \b IN: GE context
2103 /// @param start \b IN: start index of palette (0 - GE_PALETTE_NUM)
2104 /// @param num \b IN: number of palette entry to set
2105 /// @param palette \b OUT: user buffer to get palette data
2106 /// @return @ref GE_Result
2107 /// <b>[URANUS] <em>It does not support palette</em></b>
2108 //-------------------------------------------------------------------------------------------------
MDrv_GE_GetPalette(GE_Context * pGECtx,MS_U16 start,MS_U16 num,MS_U32 * palette)2109 GE_Result MDrv_GE_GetPalette(GE_Context *pGECtx, MS_U16 start, MS_U16 num, MS_U32 *palette)
2110 {
2111 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
2112 MS_U32 i;
2113 //MS_U32 palette[16]; //NOW ACQUIRE INDEX 0~15 with E_GE_READ_DIRECT mode
2114
2115 GE_DBG("%s\n", __FUNCTION__);
2116 GE_ASSERT((palette), E_GE_FAIL_PARAM, "%s: Null pointer\n", __FUNCTION__);
2117
2118 if ((num-start+1) > GE_PALETTE_NUM)
2119 {
2120 return (E_GE_FAIL_PARAM);
2121 }
2122
2123 // Wait command queue flush
2124 for (i = 0; i <(num-start+1); i++)
2125 {
2126 palette[i] = pGECtxLocal->halLocalCtx.u32Palette[start+i];
2127 }
2128
2129 return E_GE_OK;
2130 }
2131
2132
2133 //-------------------------------------------------------------------------------------------------
2134 /// Set GE YUV operation mode
2135 /// @param pGECtx \b IN: GE context
2136 /// @param mode \b IN: pointer to YUV setting structure.
2137 /// @return @ref GE_Result
2138 /// @attention
2139 /// <b>[URANUS] <em>It does not support RGB2YUV conversion</em></b>
2140 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetYUVMode(GE_Context * pGECtx,GE_YUVMode * mode)2141 GE_Result MDrv_GE_SetYUVMode(GE_Context *pGECtx, GE_YUVMode *mode)
2142 {
2143 MS_U16 u16YuvMode = 0,u16Reg = 0;
2144 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
2145
2146 GE_DBG("%s\n", __FUNCTION__);
2147 GE_ASSERT((mode), E_GE_FAIL_PARAM, "%s: Null pointer\n", __FUNCTION__);
2148
2149 GE_ENTRY(pGECtx);
2150 u16Reg = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_YUV_MODE);
2151 u16Reg &= ~(GE_YUV_CSC_MASK);
2152 u16YuvMode |= mode->rgb2yuv << GE_YUV_RGB2YUV_SHFT;
2153 u16YuvMode |= mode->out_range << GE_YUV_OUT_RANGE_SHFT;
2154 u16YuvMode |= mode->in_range << GE_YUV_IN_RANGE_SHFT;
2155
2156 #ifdef GE_UV_Swap_PATCH
2157 if( ((mode->src_fmt == E_GE_YUV_YVYU)&&(mode->dst_fmt == E_GE_YUV_YUYV))
2158 ||((mode->src_fmt == E_GE_YUV_YUYV)&&(mode->dst_fmt == E_GE_YUV_YVYU)))
2159 {
2160 mode->src_fmt = E_GE_YUV_YVYU;
2161 mode->dst_fmt = E_GE_YUV_YUYV;
2162 }
2163 #endif
2164
2165 u16YuvMode |= mode->src_fmt << GE_YUV_SRC_YUV422_SHFT;
2166 u16YuvMode |= mode->dst_fmt << GE_YUV_DST_YUV422_SHFT;
2167
2168 #ifdef GE_UV_FILTER_PATCH
2169 u16YuvMode |= 0x2;
2170 #endif
2171
2172 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_YUV_MODE, u16Reg|u16YuvMode);
2173
2174 GE_RETURN(pGECtx,E_GE_OK);
2175 }
2176
2177
2178 //-------------------------------------------------------------------------------------------------
2179 /// Set GE source buffer info
2180 /// @param pGECtx \b IN: GE context
2181 /// @param src_fmt \b IN: source buffer format
2182 /// @param pix_width \b IN: pixel width of source buffer (RESERVED)
2183 /// @param pix_height \b IN: pixel height of source buffer (RESERVED)
2184 /// @param addr \b IN: source buffer start address [23:0]
2185 /// @param pitch \b IN: source buffer linear pitch in byte unit
2186 /// @param flags \b IN: option flag of dst buffer <b>(RESERVED)</b>
2187 /// @return @ref GE_Result
2188 /// @attention
2189 /// <b>[URANUS] <em>E_GE_FMT_ARGB1555 is RGB555</em></b>
2190 /// <b>[URANUS] <em>E_GE_FMT_* should be 8-byte addr/pitch aligned to do stretch bitblt</em></b>
2191 /// @sa MDrv_GE_GetFmtCaps
2192 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetSrcBuffer(GE_Context * pGECtx,GE_BufFmt src_fmt,MS_U16 pix_width,MS_U16 pix_height,MS_PHY addr,MS_U16 pitch,MS_U32 flags)2193 GE_Result MDrv_GE_SetSrcBuffer(GE_Context *pGECtx, GE_BufFmt src_fmt, MS_U16 pix_width, MS_U16 pix_height, MS_PHY addr, MS_U16 pitch, MS_U32 flags)
2194 {
2195 GE_Result ret;
2196 GE_FmtCaps caps;
2197 MS_U16 u16fmt;
2198 MS_U8 miu=0;
2199 MS_U8 tlb_miu=0;
2200 MS_U16 reg_val=0;
2201 MS_PHY Phyoffset=0;
2202 MS_U32 tlb_start_entry=0;
2203 MS_PHY miu_interval=0;
2204 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
2205
2206 GE_DBG("%s\n", __FUNCTION__);
2207 GE_ENTRY(pGECtx);
2208
2209 // pix_width, pix_height: reserved for future use.
2210 src_fmt = (GE_BufFmt) (0xFF & src_fmt);
2211 ret = GE_GetFmtCaps(&pGECtxLocal->halLocalCtx, src_fmt, E_GE_BUF_SRC, &caps);
2212 if (ret != E_GE_OK)
2213 {
2214 GE_ERR("%s: format fail\n", __FUNCTION__);
2215 GE_RETURN(pGECtx,ret);
2216 }
2217 if (addr != ((addr + (caps.u8BaseAlign-1)) & ~(caps.u8BaseAlign-1)))
2218 {
2219 GE_ERR("%s: address fail\n", __FUNCTION__);
2220 GE_RETURN(pGECtx,E_GE_FAIL_ADDR);
2221 }
2222 if (pitch != ((pitch + (caps.u8PitchAlign-1)) & ~(caps.u8PitchAlign-1)))
2223 {
2224 GE_ERR("%s: pitch fail\n", __FUNCTION__);
2225 GE_RETURN(pGECtx,E_GE_FAIL_PITCH);
2226 }
2227 /*
2228 if (flags & E_GE_FLAG_BUF_TILE)
2229 {
2230 }
2231 */
2232
2233 #if 0
2234 if(E_GE_FMT_I8 == src_fmt)
2235 {
2236 pGECtxLocal->bSrcPaletteOn = TRUE;
2237 }
2238 else
2239 {
2240 pGECtxLocal->bSrcPaletteOn = FALSE;
2241 }
2242 #endif
2243 u16fmt = (GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_FMT) & ~GE_SRC_FMT_MASK) | ( GE_GetFmt(src_fmt) << GE_SRC_FMT_SHFT);
2244 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_FMT, u16fmt);
2245
2246 #ifdef GE_VQ_MIU_HANG_PATCH
2247 u8SrcMIU = _GFXAPI_MIU_ID(addr);
2248 #endif
2249 // Set source address
2250 GE_SetSrcBufMIUId(&pGECtxLocal->halLocalCtx, _GFXAPI_MIU_ID(addr));
2251
2252 pGECtxLocal->PhySrcAddr = _GFXAPI_PHYS_ADDR_IN_MIU(addr) | (addr & HAL_MIU1_BASE);
2253 #if !defined (MSOS_TYPE_NOS)
2254 if(pGECtxLocal->halLocalCtx.pGeChipPro->bSupportTLBMode &&(pGECtx->pBufInfo.tlbmode==E_GE_TLB_SRC||pGECtx->pBufInfo.tlbmode==E_GE_TLB_SRC_DST))
2255 {
2256 tlb_miu= _GFXAPI_MIU_ID(pGECtx->pBufInfo.tlbsrcaddr);
2257 if( tlb_miu > (pGECtxLocal->halLocalCtx.pGeChipPro->MIUSupportMaxNUM-1))
2258 {
2259 GE_D_ERR("[%s] TLB Entry Source MIU invalid (miu=%d)\n",__FUNCTION__,tlb_miu);
2260 GE_RETURN(pGECtx,E_GE_FAIL_ADDR);
2261 }
2262 if(!pGECtx->pBufInfo.tlbsrcaddr)
2263 {
2264 GE_D_ERR("[%s] TLB Entry Source addrees invalid(addr=0x%tx)\n",__FUNCTION__,(ptrdiff_t)pGECtx->pBufInfo.tlbsrcaddr);
2265 GE_RETURN(pGECtx,E_GE_FAIL_ADDR);
2266 }
2267 Phyoffset=_GFXAPI_PHYS_ADDR_IN_MIU(pGECtx->pBufInfo.tlbsrcaddr);
2268 if(pTLBSRCStartVA ==NULL)
2269 {
2270 if(MsOS_MPool_Mapping(tlb_miu, Phyoffset, TLB_ENRTY_SIZE, 1) == false)
2271 {
2272 GE_D_ERR("[%s] MsOS_MPool_Mapping fail\n",__FUNCTION__);
2273 return false;
2274 }
2275 GE_Get_MIU_INTERVAL(&pGECtxLocal->halLocalCtx,tlb_miu,&miu_interval);
2276 Phyoffset += miu_interval;
2277 pTLBSRCStartVA = (MS_VIRT*)MsOS_MPool_PA2KSEG1(Phyoffset);
2278 tlb_start_entry = *(pTLBSRCStartVA);
2279 }
2280 //[31:26]valid tag; [25:21]reserved; [20:19]MIU selection; [18:0]physical address
2281 tlb_start_entry = *( pTLBSRCStartVA + ((addr/PAGE_SIZE)*TLB_PER_ENTRY_SIZE)/sizeof(MS_U32) );
2282 addr = GE_ConvertAPIAddr2HAL(&pGECtxLocal->halLocalCtx, ((tlb_start_entry&0x001f0000)>>19), _GFXAPI_PHYS_ADDR_IN_MIU(addr));
2283 miu=((tlb_start_entry&0x001f0000)>>19);
2284 }
2285 else
2286 #endif
2287 {
2288 miu = _GFXAPI_MIU_ID(addr);
2289 addr = GE_ConvertAPIAddr2HAL(&pGECtxLocal->halLocalCtx, miu, _GFXAPI_PHYS_ADDR_IN_MIU(addr));
2290 }
2291
2292 if(miu>=2)
2293 {
2294 reg_val = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_YUV_MODE) | (1<<GE_SRC_BUFFER_MIU_H_SHFT);
2295 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_YUV_MODE, reg_val);
2296 }
2297 else
2298 {
2299 reg_val = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_YUV_MODE) & (~(1<<GE_SRC_BUFFER_MIU_H_SHFT));
2300 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_YUV_MODE, reg_val);
2301 }
2302 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_SRC_BASE_L, (addr & 0xFFFF));
2303 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_SRC_BASE_H, (addr >> 16));
2304
2305 // Set source pitch
2306 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_SRC_PITCH, pitch);
2307
2308 // Set buffer tile mode
2309 if (flags & E_GE_FLAG_BUF_TILE)
2310 {
2311 // if support tile mode
2312 ret = GE_SetSrcTile(&pGECtxLocal->halLocalCtx, TRUE);
2313 GE_RETURN(pGECtx,ret);
2314 }
2315 GE_SetSrcTile(&pGECtxLocal->halLocalCtx, FALSE);
2316
2317 GE_RETURN(pGECtx,E_GE_OK);
2318 }
2319
2320 //-------------------------------------------------------------------------------------------------
2321 /// Get PE destination buffer info
2322 /// @param pGECtx \b IN: GE context
2323 /// @param bufinfo \b IN: pointer to GE_BufInfo struct
2324 /// @return @ref GE_Result
2325 /// @attention
2326 /// <b>[URANUS] <em>E_GE_FMT_ARGB1555 is RGB555, E_GE_FMT_YUV422 can not be destination.</em></b>
2327 /// <b>[URANUS] <em>E_GE_FMT_* should be 8-byte addr/pitch aligned to do stretch bitblt</em></b>
2328 /// @sa @ref MDrv_GE_GetFmtCaps
2329 //-------------------------------------------------------------------------------------------------
MDrv_GE_GetBufferInfo(GE_Context * pGECtx,GE_BufInfo * bufinfo)2330 GE_Result MDrv_GE_GetBufferInfo(GE_Context *pGECtx, GE_BufInfo *bufinfo)
2331 {
2332
2333 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
2334 GE_DBG("%s\n", __FUNCTION__);
2335 GE_ENTRY(pGECtx);
2336
2337 //bufinfo->srcfmt = (GE_BufFmt)(GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_FMT) & GE_SRC_FMT_MASK);
2338 //bufinfo->dstfmt = (GE_BufFmt)((GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_FMT) & GE_DST_FMT_MASK) >> 8);
2339 bufinfo->srcfmt = pGECtx->pBufInfo.srcfmt;
2340 bufinfo->dstfmt = pGECtx->pBufInfo.dstfmt;
2341
2342 bufinfo->srcpit = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_SRC_PITCH);
2343 bufinfo->dstpit = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_DST_PITCH);
2344
2345 bufinfo->dstaddr = pGECtxLocal->PhyDstAddr;
2346 bufinfo->srcaddr = pGECtxLocal->PhySrcAddr;
2347
2348 GE_RETURN(pGECtx,E_GE_OK);
2349 }
2350
2351 //-------------------------------------------------------------------------------------------------
2352 /// Set GE destination buffer info
2353 /// @param pGECtx \b IN: GE context
2354 /// @param dst_fmt \b IN: source buffer format
2355 /// @param pix_width \b IN: pixel width of destination buffer (RESERVED)
2356 /// @param pix_height \b IN: pixel height of destination buffer (RESERVED)
2357 /// @param addr \b IN: destination buffer start address [23:0]
2358 /// @param pitch \b IN: destination buffer linear pitch in byte unit
2359 /// @param flags \b IN: option flag of dst buffer <b>(RESERVED)</b>
2360 /// @return @ref GE_Result
2361 /// @attention
2362 /// <b>[URANUS] <em>E_GE_FMT_ARGB1555 is RGB555, E_GE_FMT_YUV422 can not be destination.</em></b>
2363 /// <b>[URANUS] <em>E_GE_FMT_* should be 8-byte addr/pitch aligned to do stretch bitblt</em></b>
2364 /// @sa @ref MDrv_GE_GetFmtCaps
2365 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetDstBuffer(GE_Context * pGECtx,GE_BufFmt dst_fmt,MS_U16 pix_width,MS_U16 pix_height,MS_PHY addr,MS_U16 pitch,MS_U32 flags)2366 GE_Result MDrv_GE_SetDstBuffer(GE_Context *pGECtx, GE_BufFmt dst_fmt, MS_U16 pix_width, MS_U16 pix_height, MS_PHY addr, MS_U16 pitch, MS_U32 flags)
2367 {
2368 GE_Result ret;
2369 GE_FmtCaps caps;
2370 MS_U16 u16fmt;
2371 MS_U8 miu=0;
2372 MS_U8 tlb_miu=0;
2373 MS_U16 reg_val=0;
2374 MS_PHY Phyoffset=0;
2375 MS_U32 tlb_start_entry=0;
2376 MS_PHY miu_interval=0;
2377 MS_SIZE offset=0;
2378 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
2379
2380 GE_DBG("%s\n", __FUNCTION__);
2381 GE_ENTRY(pGECtx);
2382
2383 // pix_width, pix_height: reserved for future use.
2384 dst_fmt = (GE_BufFmt) (0xFF & dst_fmt);
2385
2386 ret = GE_GetFmtCaps(&pGECtxLocal->halLocalCtx, dst_fmt, E_GE_BUF_DST, &caps);
2387 if (ret != E_GE_OK)
2388 {
2389 GE_ERR("%s: format fail\n", __FUNCTION__);
2390 GE_RETURN(pGECtx,ret);
2391 }
2392 if (addr != ((addr + (caps.u8BaseAlign-1)) & ~(caps.u8BaseAlign-1)))
2393 {
2394 GE_ERR("%s: address fail\n", __FUNCTION__);
2395 GE_RETURN(pGECtx,E_GE_FAIL_ADDR);
2396 }
2397 if (pitch != ((pitch + (caps.u8PitchAlign-1)) & ~(caps.u8PitchAlign-1)))
2398 {
2399 GE_ERR("%s: pitch fail\n", __FUNCTION__);
2400 GE_RETURN(pGECtx,E_GE_FAIL_PITCH);
2401 }
2402
2403 #if 0
2404 if(E_GE_FMT_I8 == dst_fmt)
2405 {
2406 pGECtxLocal->bDstPaletteOn = TRUE;
2407 }
2408 else
2409 {
2410 pGECtxLocal->bDstPaletteOn = FALSE;
2411 }
2412 #endif
2413 u16fmt = (GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_FMT) & ~GE_DST_FMT_MASK) | ( GE_GetFmt(dst_fmt) << GE_DST_FMT_SHFT);
2414 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_FMT, u16fmt);
2415
2416 #ifdef GE_VQ_MIU_HANG_PATCH
2417 u8DstMIU = _GFXAPI_MIU_ID(addr);
2418 #endif
2419 // Set destination address
2420 GE_SetDstBufMIUId(&pGECtxLocal->halLocalCtx, _GFXAPI_MIU_ID(addr));
2421
2422 pGECtxLocal->PhyDstAddr = _GFXAPI_PHYS_ADDR_IN_MIU(addr) | (addr & HAL_MIU1_BASE);
2423 #if !defined (MSOS_TYPE_NOS)
2424 if(pGECtxLocal->halLocalCtx.pGeChipPro->bSupportTLBMode &&(pGECtx->pBufInfo.tlbmode==E_GE_TLB_DST||pGECtx->pBufInfo.tlbmode==E_GE_TLB_SRC_DST))
2425 {
2426 tlb_miu= _GFXAPI_MIU_ID(pGECtx->pBufInfo.tlbdstaddr);
2427 if(tlb_miu > (pGECtxLocal->halLocalCtx.pGeChipPro->MIUSupportMaxNUM-1))
2428 {
2429 GE_D_ERR("[%s] TLB Entry destination MIU addrees invalid(miu=%d)\n",__FUNCTION__,tlb_miu);
2430 GE_RETURN(pGECtx,E_GE_FAIL_ADDR);
2431 }
2432 if(!pGECtx->pBufInfo.tlbdstaddr)
2433 {
2434 GE_D_ERR("[%s] TLB Entry destination addrees invalid(addr=0x%tx)\n",__FUNCTION__,(ptrdiff_t)pGECtx->pBufInfo.tlbdstaddr);
2435 GE_RETURN(pGECtx,E_GE_FAIL_ADDR);
2436 }
2437 Phyoffset=_GFXAPI_PHYS_ADDR_IN_MIU(pGECtx->pBufInfo.tlbdstaddr);
2438 if(pTLBDSTStartVA ==NULL)
2439 {
2440 offset= (MS_SIZE)Phyoffset;
2441 if(MsOS_MPool_Mapping(tlb_miu, offset, TLB_ENRTY_SIZE, 1) == false)
2442 {
2443 GE_D_ERR("[%s] MsOS_MPool_Mapping fail\n",__FUNCTION__);
2444 return false;
2445 }
2446 GE_Get_MIU_INTERVAL(&pGECtxLocal->halLocalCtx,tlb_miu,&miu_interval);
2447 Phyoffset += miu_interval;
2448 pTLBDSTStartVA = (MS_VIRT*)MsOS_MPool_PA2KSEG1(Phyoffset);
2449 tlb_start_entry = *(pTLBDSTStartVA);
2450 }
2451 //[31:26]valid tag; [25:21]reserved; [20:19]MIU selection; [18:0]physical address
2452 tlb_start_entry = *( pTLBDSTStartVA + ((addr/PAGE_SIZE)*TLB_PER_ENTRY_SIZE)/sizeof(MS_U32) );
2453 addr = GE_ConvertAPIAddr2HAL(&pGECtxLocal->halLocalCtx, ((tlb_start_entry&0x001f0000)>>19), _GFXAPI_PHYS_ADDR_IN_MIU(addr));
2454 miu=((tlb_start_entry&0x001f0000)>>19);
2455 }
2456 else
2457 #endif
2458 {
2459 miu = _GFXAPI_MIU_ID(addr);
2460 addr = GE_ConvertAPIAddr2HAL(&pGECtxLocal->halLocalCtx, miu, _GFXAPI_PHYS_ADDR_IN_MIU(addr));
2461 }
2462
2463 if(miu>=2)
2464 {
2465 reg_val = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_YUV_MODE) | (1<<GE_DST_BUFFER_MIU_H_SHFT);
2466 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_YUV_MODE, reg_val);
2467 }
2468 else
2469 {
2470 reg_val = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_YUV_MODE) & (~(1<<GE_DST_BUFFER_MIU_H_SHFT));
2471 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_YUV_MODE, reg_val);
2472 }
2473 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_DST_BASE_L, (addr & 0xFFFF));
2474 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_DST_BASE_H, (addr >> 16));
2475
2476 // Set destination pitch
2477 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_DST_PITCH, pitch);
2478
2479 // Set buffer tile mode
2480 if (flags & E_GE_FLAG_BUF_TILE)
2481 {
2482 // if support tile mode
2483 ret = GE_SetDstTile(&pGECtxLocal->halLocalCtx, TRUE);
2484 GE_RETURN(pGECtx,ret);
2485 }
2486 GE_SetDstTile(&pGECtxLocal->halLocalCtx, FALSE);
2487
2488 GE_RETURN(pGECtx,E_GE_OK);
2489 }
2490
2491 //-------------------------------------------------------------------------------------------------
2492 /// Set GE destination buffer of two source buffer
2493 /// @param pGECtx \b IN: GE context
2494 /// @param dst_fmt \b IN: format of destination buffer of two source
2495 /// @param pSrc0Rect \b IN: source0 Rect of two source(RESERVED)
2496 /// @param pSrc1Rect \b IN: source1 Rect of two source(RESERVED)
2497 /// @param pDestRect \b IN: Destination Rect of two source(RESERVED)
2498 /// @param addr \b IN: destination buffer of two source start address [23:0]
2499 /// @param pitch \b IN: destination buffer of two source linear pitch in byte unit
2500 /// @param flags \b IN: option flag of dst buffer <b>(RESERVED)</b>
2501 /// @return @ref GE_Result
2502 /// @attention
2503 /// <b>[URANUS] <em>E_GE_FMT_ARGB1555 is RGB555, E_GE_FMT_YUV422 can not be destination.</em></b>
2504 /// <b>[URANUS] <em>E_GE_FMT_* should be 8-byte addr/pitch aligned to do stretch bitblt</em></b>
2505 /// @sa @ref MDrv_GE_GetFmtCaps
2506 //-------------------------------------------------------------------------------------------------
MDrv_GE_BitBltByTwoSourceBuffer(GE_Context * pGECtx,GE_BufFmt dst_fmt,GE_Rect * pSrc0Rect,GE_Rect * pSrc1Rect,GE_Rect * pDestRect,MS_PHY addr,MS_U16 pitch,MS_U32 flags,GE_ScaleInfo * scaleinfo)2507 GE_Result MDrv_GE_BitBltByTwoSourceBuffer(GE_Context *pGECtx, GE_BufFmt dst_fmt, GE_Rect *pSrc0Rect, GE_Rect *pSrc1Rect, GE_Rect *pDestRect, MS_PHY addr, MS_U16 pitch, MS_U32 flags, GE_ScaleInfo* scaleinfo)
2508 {
2509 GE_Result ret;
2510 GE_FmtCaps caps;
2511 MS_U16 u16fmt = 0;
2512 MS_U16 u16en = 0;
2513 GE_Point v0, v1;
2514 MS_U8 miu=0;
2515 MS_U16 reg_val=0;
2516 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
2517
2518 GE_ENTRY(pGECtx);
2519 if(FALSE == pGECtxLocal->halLocalCtx.pGeChipPro->bSupportTwoSourceBitbltMode)
2520 {
2521 GE_RETURN(pGECtx,E_GE_NOT_SUPPORT);
2522 }
2523 // pix_width, pix_height: reserved for future use.
2524 dst_fmt = (GE_BufFmt) (0xFF & dst_fmt);
2525
2526 ret = GE_GetFmtCaps(&pGECtxLocal->halLocalCtx, dst_fmt, E_GE_BUF_DST, &caps);
2527 if (ret != E_GE_OK)
2528 {
2529 GE_ERR("%s: format fail\n", __FUNCTION__);
2530 GE_RETURN(pGECtx,ret);
2531 }
2532 if (addr != ((addr + (caps.u8BaseAlign-1)) & ~(caps.u8BaseAlign-1)))
2533 {
2534 GE_ERR("%s: address fail\n", __FUNCTION__);
2535 GE_RETURN(pGECtx,E_GE_FAIL_ADDR);
2536 }
2537 if (pitch != ((pitch + (caps.u8PitchAlign-1)) & ~(caps.u8PitchAlign-1)))
2538 {
2539 GE_ERR("%s: pitch fail\n", __FUNCTION__);
2540 GE_RETURN(pGECtx,E_GE_FAIL_PITCH);
2541 }
2542
2543 //There are some HW limitations, check it
2544 if(flags & E_GE_FLAG_BLT_STRETCH)
2545 {
2546 MS_U16 src1fmt = (GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_FMT) & GE_DST_FMT_MASK) >> GE_DST_FMT_SHFT;
2547 MS_U16 destfmt = GE_GetFmt(dst_fmt);
2548 if(destfmt != src1fmt)
2549 {
2550 GE_ERR("[%s] Two source stretch bitblt HW limitation: src1 format and dest format must be the same. src1 format:%d, dest format:%d\n"
2551 ,__FUNCTION__,src1fmt,destfmt);
2552 GE_RETURN(pGECtx,E_GE_FAIL_STRETCH);
2553 }
2554 #ifdef GE_TwoSourceAlign
2555 MS_U16 alignValue = (GE_TwoSourceAlign / 8) / caps.u8BaseAlign;
2556 MS_U16 scr1x = pSrc1Rect->x % alignValue;
2557 MS_U16 destx = pDestRect->x % alignValue;
2558 if(scr1x != destx)
2559 {
2560 GE_ERR("[%s] Two source stretch bitblt HW limitation: src1 x and dest x must align %d bit position. src1 x:%d, dest x:%d\n"
2561 ,__FUNCTION__,GE_TwoSourceAlign,pSrc1Rect->x,pDestRect->x);
2562 GE_RETURN(pGECtx,E_GE_FAIL_STRETCH);
2563 }
2564 #endif
2565 }
2566
2567 GEWD_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, &u16en);
2568 u16en |= GE_EN_GE;
2569 GEWD_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, u16en);
2570
2571 GEWD_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_FMT,&u16fmt);
2572 u16fmt = (u16fmt & ~GE_DST_FMT_MASK) | ( GE_GetFmt(dst_fmt) << GE_DST_FMT_SHFT);
2573 //u16fmt = (GEWD_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_FMT) & ~GE_DST_FMT_MASK) | ( GE_GetFmt(dst_fmt) << GE_DST_FMT_SHFT);
2574 GEWD_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_FMT, u16fmt);
2575
2576 miu = _GFXAPI_MIU_ID(addr);
2577 addr = GE_ConvertAPIAddr2HAL(&pGECtxLocal->halLocalCtx, miu, _GFXAPI_PHYS_ADDR_IN_MIU(addr));
2578 if(miu>=2)
2579 {
2580 reg_val = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_YUV_MODE) | (1<<GE_DST_BUFFER_MIU_H_SHFT);
2581 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_YUV_MODE, reg_val);
2582 }
2583 else
2584 {
2585 reg_val = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_YUV_MODE) & (~(1<<GE_DST_BUFFER_MIU_H_SHFT));
2586 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_YUV_MODE, reg_val);
2587 }
2588 GEWD_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_DST_BASE_L, (addr & 0xFFFF));
2589 GEWD_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_DST_BASE_H, (addr >> 16));
2590
2591 // Set destination pitch
2592 GEWD_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_DST_PITCH, pitch);
2593
2594 v0.x = pDestRect->x;
2595 v0.y = pDestRect->y;
2596 v1.x = v0.x + pDestRect->width - 1;
2597 v1.y = v0.y + pDestRect->height - 1;
2598
2599 GEWD_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_X, v0.x);
2600 GEWD_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_Y, v0.y);
2601 GEWD_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_X, v1.x);
2602 GEWD_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_Y, v1.y);
2603
2604 GE_Rect src;
2605 GE_DstBitBltType dst;
2606 src.x = pSrc0Rect->x;
2607 src.y = pSrc0Rect->y;
2608 src.width = pSrc0Rect->width;
2609 src.height = pSrc0Rect->height;
2610 dst.dstblk.x = pSrc1Rect->x;
2611 dst.dstblk.y = pSrc1Rect->y;
2612 dst.dstblk.width = pSrc1Rect->width;
2613 dst.dstblk.height = pSrc1Rect->height;
2614
2615 ret = MDrv_GE_BitBltEX(pGECtx, &src, &dst, flags, scaleinfo);
2616 GEWD_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, &u16en);
2617 u16en &= ~GE_EN_GE;
2618 GEWD_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, u16en);
2619
2620 GE_RETURN(pGECtx,ret);
2621 }
2622
2623
2624 //-------------------------------------------------------------------------------------------------
2625 /// GE Primitive Drawing - LINE
2626 /// @param pGECtx \b IN: GE context
2627 /// @param v0 \b IN: pointer to start point of line
2628 /// @param v1 \b IN: pointer to end point of line
2629 /// @param color \b IN: color of LINE
2630 /// @param color2 \b IN: 2nd color of gradient
2631 /// @param flags \b IN: LINE drawing flags
2632 /// @return @ref GE_Result
2633 //-------------------------------------------------------------------------------------------------
MDrv_GE_DrawLine(GE_Context * pGECtx,GE_Point * v0,GE_Point * v1,MS_U32 color,MS_U32 color2,MS_U32 flags,MS_U32 width)2634 GE_Result MDrv_GE_DrawLine(GE_Context *pGECtx, GE_Point *v0, GE_Point *v1, MS_U32 color, MS_U32 color2, MS_U32 flags, MS_U32 width)
2635 {
2636 MS_U16 u16cmd = 0;
2637 MS_U16 u16cfg;
2638 //MS_U16 u16style;
2639 MS_U16 dw, dh, dminor, dmajor;
2640 MS_BOOL y_major = false;
2641 MS_U32 u32Start ;
2642 MS_U32 u32End ;
2643 MS_U32 i;
2644 MS_BOOL bDstXInv = FALSE;
2645 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
2646
2647
2648 GE_DBG("%s\n", __FUNCTION__);
2649 GE_ASSERT((v0), E_GE_FAIL_PARAM, "%s: NULL pointer\n", __FUNCTION__);
2650 GE_ASSERT((v1), E_GE_FAIL_PARAM, "%s: NULL pointer\n", __FUNCTION__);
2651
2652 GE_ENTRY(pGECtx);
2653
2654 #if DYNAMIC_POWER_ON_OFF
2655 MDrv_PWR_ClockTurnOn(E_PWR_MODULE_GE);
2656 #endif
2657
2658 #if 0//(SUPPORT_LINE_LAST_PATCH == 1 )
2659 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_LINE_STYLE, GE_LINEPAT_RST | 0x3f);
2660 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_LINE_STYLE, 0x3f);
2661 //#else
2662 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_LINE_STYLE, GE_LINE_LAST | GE_LINEPAT_RST | 0x3f);
2663 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_LINE_STYLE, GE_LINE_LAST | 0x3f);
2664 #endif
2665
2666 /*2010.01.11 mark for green key draw line of T079 DynamicLineArt Advanced issue.
2667 mheg5 app maybe give large dstination v1.x (over 4096) position to ge driver and use clip window
2668 to do this application.
2669 We should pass app invaild destination position checking mechanism here and just check clip widnow
2670 is vaild or not for app*/
2671 #if 0
2672 if ( (v0->x > 0x7FF) || (v0->y > 0x7FF) || (v1->x > 0x7FF) || (v1->y > 0x7FF) )
2673 {
2674 GE_ERR("%s v0, v1 out of range (>0x7FF)\n", __FUNCTION__);
2675 GE_RETURN(pGECtx,E_GE_NOT_DRAW);
2676 }
2677 #endif
2678 // fast clip check
2679 if (GE_FastClip(pGECtx, v0->x, v0->y, v1->x, v1->y) && (width==1))
2680 {
2681 GE_RETURN(pGECtx,E_GE_NOT_DRAW);
2682 }
2683
2684 dw = (v0->x >= v1->x) ? (v0->x - v1->x) : (v1->x - v0->x);
2685 dh = (v0->y >= v1->y) ? (v0->y - v1->y) : (v1->y - v0->y);
2686
2687 #if 0 // 1 pixel drawing should be allowed.
2688 if ( (dh == 0) && (dw == 0) )
2689 {
2690 GE_RETURN(pGECtx,E_GE_NOT_DRAW);
2691 }
2692 #endif
2693
2694 if ( (dh > dw) || (dw == 0) )
2695 {
2696 y_major = TRUE;
2697 }
2698
2699 GE_Restore_PaletteContext(pGECtxLocal);
2700
2701 // clear dirty attributes ---------------------------------------------------------------------
2702 // reset unused register
2703 GE_SetRotate(&pGECtxLocal->halLocalCtx, E_GE_ROTATE_0);
2704 u16cfg = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_CFG) & ~(GE_CFG_BLT_STRETCH | GE_CFG_BLT_ITALIC);
2705 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CFG, u16cfg);
2706 // clear dirty attributes ---------------------------------------------------------------------
2707
2708 // line delta
2709 if (y_major)
2710 {
2711 dmajor = dh;
2712 dminor = GE_Divide2Fixed(dw, dmajor, 1, 12); // s1.12
2713 if (v0->x > v1->x)
2714 {
2715 dminor = (MS_U16)(1<<(2+12)) - dminor; // negative
2716 }
2717 if (v0->y > v1->y)
2718 {
2719 u16cmd |= GE_DST_DIR_X_INV; // line always refer DIR_X
2720 }
2721 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_LINE_DELTA, GE_LINE_MAJOR_Y | (dminor << GE_LINE_DELTA_SHFT));
2722 }
2723 else // x major
2724 {
2725 dmajor = dw;
2726 dminor = GE_Divide2Fixed(dh, dmajor, 1, 12); // s1.12
2727 if (v0->y > v1->y)
2728 {
2729 dminor = (MS_U16)(1<<(2+12)) - dminor; // negative
2730 }
2731 if (v0->x > v1->x)
2732 {
2733 u16cmd |= GE_DST_DIR_X_INV;
2734 }
2735 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_LINE_DELTA, GE_LINE_MAJOR_X | (dminor << GE_LINE_DELTA_SHFT));
2736 }
2737
2738 // Line color
2739 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_C_L, (color & 0xFFFF));
2740 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_C_H, (color >> 16));
2741
2742 if (flags & E_GE_FLAG_LINE_GRADIENT)
2743 {
2744 GE_ColorDelta delta;
2745 GE_CalcColorDelta(color, color2, dmajor, &delta);
2746
2747 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_RDX_L, (delta.r & 0xFFFF));
2748 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_RDX_H, (delta.r >> 16));
2749
2750 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_GDX_L, (delta.g & 0xFFFF));
2751 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_GDX_H, (delta.g >> 16));
2752
2753 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_BDX_L, (delta.b & 0xFFFF));
2754 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_BDX_H, (delta.b >> 16));
2755
2756 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_ADX, (delta.a & 0xFFFF));
2757
2758 u16cmd |= GE_LINE_GRADIENT;
2759 }
2760
2761 // Draw Line
2762 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_X, v0->x);
2763 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_Y, v0->y);
2764 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_X, v1->x);
2765 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_Y, v1->y);
2766 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_LINE_LENGTH, dmajor);
2767
2768 //GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CMD, GE_PRIM_LINE | u16cmd);
2769
2770 // clear if line pattern reset
2771 //u16style = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_LINE_STYLE) & ~GE_LINEPAT_RST;
2772
2773 u32Start = v0->x;
2774 u32End = v1->x;
2775
2776 if(y_major)
2777 {
2778 #if 1//(SUPPORT_LINE_LAST_PATCH == 1 )
2779 if(v1->y <= v0->y)
2780 {
2781 if(v1->y >=2)
2782 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_Y, v1->y-2);
2783 else {
2784 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_Y, v1->y);
2785 }
2786 }
2787 else
2788 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_Y, v1->y+2);
2789 #endif
2790
2791 for(i=0;i<=width;i++)
2792 {
2793 #if 1//(SUPPORT_LINE_LAST_PATCH == 1 )
2794 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_LINE_LENGTH, dmajor+1);
2795 #else
2796 // PE_WriteReg(PE_REG_LENGTH, u32Height);
2797 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_LINE_LENGTH, dmajor);
2798 #endif
2799 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_X, u32Start);
2800 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_X, u32End);
2801 // GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_LINE_STYLE, u16style);
2802 bDstXInv = (u16cmd & (GE_DST_DIR_X_INV))?TRUE:FALSE;
2803 HAL_GE_AdjustDstWin(&pGECtxLocal->halLocalCtx,bDstXInv);
2804 #ifdef GE_VQ_MIU_HANG_PATCH
2805 if ((GE_IsVcmdqEnabled(pGECtx) == TRUE) &&
2806 (u8DstMIU != pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu)
2807 )
2808 {
2809 //printf("\33[0;36m %s:%d u8VCmdQMiu = %d u8SrcMIU = %d u8DstMIU = %d\33[m \n",__FUNCTION__,__LINE__,pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu,u8SrcMIU,u8DstMIU);
2810 MDrv_GE_WaitIdle(pGECtx);
2811 }
2812 #endif
2813 _GE_SEMAPHORE_ENTRY(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
2814 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CMD, GE_PRIM_LINE | u16cmd);
2815 _GE_SEMAPHORE_RETURN(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
2816
2817 #ifdef GE_VQ_MIU_HANG_PATCH
2818 if ((GE_IsVcmdqEnabled(pGECtx) == TRUE) &&
2819 (u8DstMIU != pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu)
2820 )
2821 {
2822 //printf("\33[0;36m %s:%d u8VCmdQMiu = %d u8SrcMIU = %d u8DstMIU = %d\33[m \n",__FUNCTION__,__LINE__,pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu,u8SrcMIU,u8DstMIU);
2823 MDrv_GE_WaitIdle(pGECtx);
2824 }
2825 #endif
2826
2827 u32Start++;
2828 u32End++;
2829 }
2830 }
2831 else
2832 {
2833 #if 1
2834 #if 1//(SUPPORT_LINE_LAST_PATCH == 1 )
2835 if(v1->x <= v0->x)
2836 {
2837 if(v1->x >=2)
2838 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_X, v1->x-2);
2839 else
2840 {
2841 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_X, v1->x);
2842 }
2843 }
2844 else
2845 // PE_WriteReg(PE_REG_PRI_V1_X, u32X2+2);
2846 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_X, v1->x+2);
2847 #endif
2848 #endif
2849 u32Start = v0->y;
2850 u32End = v1->y;
2851 for (i=0;i<=width;i++)
2852 {
2853 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_LINE_LENGTH, dmajor+1);
2854
2855 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_Y, u32Start);
2856 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_Y, u32End);
2857 // GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_LINE_STYLE, u16style);
2858 bDstXInv = (u16cmd & (GE_DST_DIR_X_INV))?TRUE:FALSE;
2859 HAL_GE_AdjustDstWin(&pGECtxLocal->halLocalCtx,bDstXInv);
2860 #ifdef GE_VQ_MIU_HANG_PATCH
2861 if ((GE_IsVcmdqEnabled(pGECtx) == TRUE) &&
2862 (u8DstMIU != pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu)
2863 )
2864 {
2865 //printf("\33[0;36m %s:%d u8VCmdQMiu = %d u8SrcMIU = %d u8DstMIU = %d\33[m \n",__FUNCTION__,__LINE__,pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu,u8SrcMIU,u8DstMIU);
2866 MDrv_GE_WaitIdle(pGECtx);
2867 }
2868 #endif
2869 _GE_SEMAPHORE_ENTRY(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
2870 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CMD, GE_PRIM_LINE | u16cmd);
2871 _GE_SEMAPHORE_RETURN(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
2872
2873 #ifdef GE_VQ_MIU_HANG_PATCH
2874 if ((GE_IsVcmdqEnabled(pGECtx) == TRUE) &&
2875 (u8DstMIU != pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu)
2876 )
2877 {
2878 //printf("\33[0;36m %s:%d u8VCmdQMiu = %d u8SrcMIU = %d u8DstMIU = %d\33[m \n",__FUNCTION__,__LINE__,pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu,u8SrcMIU,u8DstMIU);
2879 MDrv_GE_WaitIdle(pGECtx);
2880 }
2881 #endif
2882
2883 // PE_WriteReg(PE_REG_LENGTH, u32Width+1);
2884 // PE_WriteReg(PE_REG_PRI_V0_Y, u32Start);
2885 // PE_WriteReg(PE_REG_PRI_V1_Y, u32End);
2886 // PE_WriteReg(PE_REG_CMD, u32Value2|_u32Reg60hFlag);
2887 u32Start++;
2888 u32End++;
2889 }
2890 }
2891
2892
2893 #if DYNAMIC_POWER_ON_OFF
2894 GE_WaitIdle(&pGECtxLocal->halLocalCtx);
2895 MDrv_PWR_ClockTurnOff(E_PWR_MODULE_GE);
2896 #endif
2897
2898 GE_RETURN(pGECtx,E_GE_OK);
2899 }
2900
2901
2902 //-------------------------------------------------------------------------------------------------
2903 /// GE Primitive Drawing - RECT
2904 /// @param pGECtx \b IN: GE context
2905 /// @param rect \b IN: pointer to position of RECT
2906 /// @param color \b IN: color of RECT
2907 /// @param color2 \b IN: 2nd color of gradient
2908 /// @param flags \b IN: RECT drawing flags
2909 /// @return @ref GE_Result
2910 //-------------------------------------------------------------------------------------------------
MDrv_GE_FillRect(GE_Context * pGECtx,GE_Rect * rect,MS_U32 color,MS_U32 color2,MS_U32 flags)2911 GE_Result MDrv_GE_FillRect(GE_Context *pGECtx, GE_Rect *rect, MS_U32 color, MS_U32 color2, MS_U32 flags)
2912 {
2913 MS_U16 u16cmd = 0;
2914 MS_U16 u16cfg;
2915 MS_U16 u16fmt;
2916 MS_U16 u16fmt2;
2917 GE_ColorDelta delta;
2918 MS_U32 color_right_top = 0;
2919 MS_BOOL bDstXInv = FALSE;
2920 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
2921
2922 GE_DBG("%s\n", __FUNCTION__);
2923 GE_ASSERT((rect), E_GE_FAIL_PARAM, "%s: Null pointer\n", __FUNCTION__);
2924
2925 GE_ENTRY(pGECtx);
2926
2927 if ( (rect->width == 0) || (rect->height == 0) )
2928 {
2929 GE_RETURN(pGECtx,E_GE_FAIL_PARAM);
2930 }
2931 if (GE_FastClip(pGECtx, rect->x, rect->y, rect->x+rect->width-1, rect->y+rect->height-1))
2932 {
2933 GE_RETURN(pGECtx,E_GE_NOT_DRAW);
2934 }
2935
2936 #if DYNAMIC_POWER_ON_OFF
2937 MDrv_PWR_ClockTurnOn(E_PWR_MODULE_GE);
2938 #endif
2939
2940 GE_Restore_PaletteContext(pGECtxLocal);
2941
2942 // clear dirty attributes ---------------------------------------------------------------------
2943 // reset unused register
2944 GE_SetRotate(&pGECtxLocal->halLocalCtx, E_GE_ROTATE_0);
2945 u16cfg = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_CFG) & ~(GE_CFG_BLT_STRETCH | GE_CFG_BLT_ITALIC);
2946 if(*(&pGECtxLocal->halLocalCtx.pGeChipPro->bSupportSpiltMode))
2947 {
2948 #ifdef GE_SPLIT_MODE_PATCH
2949 //disable split mode
2950 u16cfg &= (~GE_CFG_RW_SPLIT);
2951 #else
2952 //enable split mode
2953 u16cfg |= GE_CFG_RW_SPLIT;
2954 #endif
2955 }
2956 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CFG, u16cfg);
2957 // clear dirty attributes ---------------------------------------------------------------------
2958
2959 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_X, rect->x);
2960 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_Y, rect->y);
2961 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_X, rect->x+rect->width-1);
2962 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_Y, rect->y+rect->height-1);
2963
2964 if(*(&pGECtxLocal->halLocalCtx.pGeChipPro->bFourPixelModeStable))
2965 {
2966
2967 //Fill Rect must set source width and height for 4P mode check
2968 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_BLT_SRC_W, rect->width);
2969 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_BLT_SRC_H, rect->height);
2970 //Fill Rect must set source color format same as dest color format for 4P mode check
2971 u16fmt = GE_ReadReg(&pGECtxLocal->halLocalCtx,REG_GE_FMT) & GE_DST_FMT_MASK;
2972 u16fmt2 = ((u16fmt >> GE_DST_FMT_SHFT) & GE_SRC_FMT_MASK);
2973 u16fmt |= u16fmt2;
2974 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_FMT, u16fmt);
2975 }
2976
2977 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_C_L, color & 0xFFFF);
2978 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_C_H, color >> 16);
2979
2980 //[TODO] should I set REG_GE_PRIM_ADX and REG_GE_PRIM_ADY?
2981
2982 if((flags&(E_GE_FLAG_RECT_GRADIENT_X|E_GE_FLAG_RECT_GRADIENT_Y))==(E_GE_FLAG_RECT_GRADIENT_X|E_GE_FLAG_RECT_GRADIENT_Y))
2983 {
2984 MS_U8 a0, r0, g0, b0;
2985 MS_U8 a1, r1, g1, b1;
2986 MS_U8 a2, r2, g2, b2;
2987
2988 // Get A,R,G,B
2989 //[TODO] special format
2990 b0 = (color) & 0xFF;
2991 g0 = (color >> 8) & 0xFF;
2992 r0 = (color >> 16) & 0xFF;
2993 a0 = (color >> 24);
2994 b2 = (color2) & 0xFF;
2995 g2 = (color2 >> 8) & 0xFF;
2996 r2 = (color2 >> 16) & 0xFF;
2997 a2 = (color2 >> 24);
2998 b1 = ((MS_S32)b2-b0)*(MS_S32)rect->width*rect->width/((MS_S32)rect->width*rect->width+(MS_S32)rect->height*rect->height)+(MS_S32)b0;
2999 g1 = ((MS_S32)g2-g0)*(MS_S32)rect->width*rect->width/((MS_S32)rect->width*rect->width+(MS_S32)rect->height*rect->height)+(MS_S32)g0;
3000 r1 = ((MS_S32)r2-r0)*(MS_S32)rect->width*rect->width/((MS_S32)rect->width*rect->width+(MS_S32)rect->height*rect->height)+(MS_S32)r0;
3001 a1 = ((MS_S32)a2-a0)*(MS_S32)rect->width*rect->width/((MS_S32)rect->width*rect->width+(MS_S32)rect->height*rect->height)+(MS_S32)a0;
3002 color_right_top = ((MS_U32)a1)<<24| ((MS_U32)r1)<<16|((MS_U32)g1)<<8|b1;
3003 }
3004 else if(flags&E_GE_FLAG_RECT_GRADIENT_X)
3005 color_right_top = color2;
3006 else if(flags&E_GE_FLAG_RECT_GRADIENT_Y)
3007 color_right_top = color;
3008
3009 if ( (flags & E_GE_FLAG_RECT_GRADIENT_X) && (rect->width > 1) )
3010 {
3011 GE_CalcColorDelta(color, color_right_top, rect->width-1, &delta);
3012 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_RDX_L, delta.r & 0xFFFF);
3013 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_RDX_H, delta.r >> 16);
3014 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_GDX_L, delta.g & 0xFFFF);
3015 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_GDX_H, delta.g >> 16);
3016 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_BDX_L, delta.b & 0xFFFF);
3017 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_BDX_H, delta.b >> 16);
3018 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_ADX, delta.a);
3019 u16cmd |= GE_RECT_GRADIENT_H;
3020 }
3021
3022 if ( (flags & E_GE_FLAG_RECT_GRADIENT_Y) && (rect->height > 1) )
3023 {
3024 GE_CalcColorDelta(color_right_top, color2, rect->height-1, &delta);
3025 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_RDY_L, delta.r & 0xFFFF);
3026 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_RDY_H, delta.r >> 16);
3027 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_GDY_L, delta.g & 0xFFFF);
3028 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_GDY_H, delta.g >> 16);
3029 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_BDY_L, delta.b & 0xFFFF);
3030 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_BDY_H, delta.b >> 16);
3031 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_ADY, delta.a);
3032 u16cmd |= GE_RECT_GRADIENT_V;
3033 }
3034
3035 #ifdef MSOS_TYPE_NOS
3036 if( (bDither == TRUE) && ((flags & E_GE_FLAG_RECT_GRADIENT_X) || (flags & E_GE_FLAG_RECT_GRADIENT_Y) ))
3037 MDrv_GE_SetDither(pGECtx,TRUE);
3038 else
3039 MDrv_GE_SetDither(pGECtx,FALSE);
3040 #endif
3041 bDstXInv = (u16cmd & (GE_DST_DIR_X_INV))?TRUE:FALSE;
3042 HAL_GE_AdjustDstWin(&pGECtxLocal->halLocalCtx,bDstXInv);
3043
3044 #ifdef GE_VQ_MIU_HANG_PATCH
3045 if ((GE_IsVcmdqEnabled(pGECtx) == TRUE) &&
3046 (u8DstMIU != pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu)
3047 )
3048 {
3049 //printf("\33[0;36m %s:%d u8VCmdQMiu = %d u8DstMIU = %d\33[m \n",__FUNCTION__,__LINE__,pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu,u8DstMIU);
3050 MDrv_GE_WaitIdle(pGECtx);
3051 }
3052 #endif
3053 _GE_SEMAPHORE_ENTRY(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
3054 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CMD, GE_PRIM_RECT | u16cmd);
3055 _GE_SEMAPHORE_RETURN(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
3056
3057 #ifdef GE_VQ_MIU_HANG_PATCH
3058 if ((GE_IsVcmdqEnabled(pGECtx) == TRUE) &&
3059 (u8DstMIU != pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu)
3060 )
3061 {
3062 //printf("\33[0;36m %s:%d u8VCmdQMiu = %d u8SrcMIU = %d u8DstMIU = %d\33[m \n",__FUNCTION__,__LINE__,pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu,u8SrcMIU,u8DstMIU);
3063 MDrv_GE_WaitIdle(pGECtx);
3064 }
3065 #endif
3066
3067 #ifdef MSOS_TYPE_NOS
3068 MDrv_GE_SetDither(pGECtx,bDither);
3069 #endif
3070
3071 /* move to devGE.c
3072 #if GE_PATCH_ENABLE
3073 //[PATCH] assign dummy cmd before other command (e.g. X,Y or COLOR, EN) push into queue.
3074 // Next reg_write will corrupted this RECT if it's still drawing at that time.
3075 GE_WriteReg(REG_GE_EN, GE_ReadReg(REG_GE_EN));
3076 //[PATCH]
3077 #endif
3078 */
3079
3080 #if DYNAMIC_POWER_ON_OFF
3081 GE_WaitIdle(&pGECtxLocal->halLocalCtx);
3082 MDrv_PWR_ClockTurnOff(E_PWR_MODULE_GE);
3083 #endif
3084
3085 GE_RETURN(pGECtx,E_GE_OK);
3086 }
3087
3088 #ifdef CONFIG_GFX_TRAPZOID
3089 //-------------------------------------------------------------------------------------------------
3090 /// GE Primitive Drawing - Trapezoid
3091 /// @param pGECtx \b IN: GE context
3092 /// @param pGeTrapezoid \b IN: pointer to position of RECT
3093 /// @param u32ColorS \b IN: color of RECT
3094 /// @param u32ColorE \b IN: 2nd color of gradient
3095 /// @param u32Flags \b IN: Trapezoid drawing flags
3096 /// @return @ref GE_Result
3097 //-------------------------------------------------------------------------------------------------
MDrv_GE_FillTrapezoid(GE_Context * pGECtx,GE_Trapezoid * pGeTrapezoid,MS_U32 u32ColorS,MS_U32 u32ColorE,MS_U32 u32Flags)3098 GE_Result MDrv_GE_FillTrapezoid(GE_Context *pGECtx, GE_Trapezoid *pGeTrapezoid, MS_U32 u32ColorS, MS_U32 u32ColorE, MS_U32 u32Flags)
3099 {
3100 GE_Result geResult;
3101 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
3102 GE_Normalized_Trapezoid geNormTrapezoid;
3103 GE_ColorDelta geColorDeltaX, geColorDeltaY;
3104 GE_ColorDelta *pGeColorDeltaX=NULL, *pGeColorDeltaY=NULL;
3105 MS_BOOL bYTrapezoid = (u32Flags & E_GE_FLAG_TRAPEZOID_Y) ? TRUE : FALSE;
3106
3107 GE_DBG("%s\n", __FUNCTION__);
3108 GE_ASSERT((pGeTrapezoid), E_GE_FAIL_PARAM, "%s: Null pointer\n", __FUNCTION__);
3109
3110 GE_ENTRY(pGECtx);
3111
3112 //check parameters:
3113 if(((pGeTrapezoid->u16Y0>=pGeTrapezoid->u16Y1)&&(bYTrapezoid==FALSE))
3114 || ((pGeTrapezoid->u16X0<=pGeTrapezoid->u16X1)&&(bYTrapezoid==TRUE))
3115 || (0==pGeTrapezoid->u16DeltaTop)
3116 || (0==pGeTrapezoid->u16DeltaBottom))
3117 {
3118 GE_RETURN(pGECtx, E_GE_FAIL_PARAM);
3119 }
3120
3121 if(GE_FastClipTrapezoid(pGECtx, pGeTrapezoid->u16X0, pGeTrapezoid->u16Y0, pGeTrapezoid->u16X1, pGeTrapezoid->u16Y1, pGeTrapezoid->u16DeltaTop, pGeTrapezoid->u16DeltaBottom, bYTrapezoid))
3122 {
3123 GE_RETURN(pGECtx,E_GE_NOT_DRAW);
3124 }
3125
3126 #if DYNAMIC_POWER_ON_OFF
3127 MDrv_PWR_ClockTurnOn(E_PWR_MODULE_GE);
3128 #endif
3129
3130 //Transfer Driver definition of Trapezoid to Hardware definition of trapezoid:
3131 GE_NormalizeTrapezoidDef(pGeTrapezoid, &geNormTrapezoid, bYTrapezoid);
3132
3133 //Prepare DeltaX, DeltaY:
3134 if(u32Flags & E_GE_FLAG_TRAPEZOID_GRADIENT_X)
3135 {
3136 pGeColorDeltaX = &geColorDeltaX;
3137 if(bYTrapezoid)
3138 {
3139 GE_CalcColorDelta(u32ColorS, u32ColorE, (pGeTrapezoid->u16X0-pGeTrapezoid->u16X1), pGeColorDeltaX);
3140 }
3141 else
3142 {
3143 GE_CalcColorDelta(u32ColorS, u32ColorE, (pGeTrapezoid->u16DeltaTop), pGeColorDeltaX);
3144 }
3145 }
3146
3147 if(u32Flags & E_GE_FLAG_TRAPEZOID_GRADIENT_Y)
3148 {
3149 pGeColorDeltaY = &geColorDeltaY;
3150 if(bYTrapezoid)
3151 {
3152 GE_CalcColorDelta(u32ColorS, u32ColorE, (pGeTrapezoid->u16DeltaTop), pGeColorDeltaY);
3153 }
3154 else
3155 {
3156 GE_CalcColorDelta(u32ColorS, u32ColorE, (pGeTrapezoid->u16Y1-pGeTrapezoid->u16Y0), pGeColorDeltaY);
3157 }
3158 }
3159
3160 GE_Restore_PaletteContext(pGECtxLocal);
3161
3162 //Actual Bitblit:
3163 geResult = GE_FillTrapezoid(&pGECtxLocal->halLocalCtx, bYTrapezoid, &geNormTrapezoid, u32ColorS, pGeColorDeltaX, pGeColorDeltaY);
3164 if(E_GE_OK != geResult)
3165 {
3166 geResult = GE_TrapezoidFill(pGECtxLocal, bYTrapezoid, &geNormTrapezoid, u32ColorS, u32ColorE, pGeColorDeltaX, pGeColorDeltaY);
3167 }
3168
3169 #if DYNAMIC_POWER_ON_OFF
3170 GE_WaitIdle();
3171 MDrv_PWR_ClockTurnOff(E_PWR_MODULE_GE);
3172 #endif
3173
3174 GE_RETURN(pGECtx, geResult);
3175 }
3176 #endif
3177 //-------------------------------------------------------------------------------------------------
3178 /// GE Primitive Drawing - BLT
3179 /// @param pGECtx \b IN: GE context
3180 /// @param src \b IN: source RECT of bitblt
3181 /// @param dst \b IN: destination RECT of bitblt
3182 /// @param flags \b IN: RECT drawing flags
3183 /// @param scaleinfo \b IN: Customed scale info
3184 /// @return @ref GE_Result
3185 /// @note\n
3186 /// FMT_I1,I2,I4,I8: should be 64-bit aligned in base and pitch to do stretch bitblt.\n
3187 /// FMT_YUV422: the rectangle should be YUV422 block aligned. (4 bytes for 2 pixels in horizontal)
3188 //-------------------------------------------------------------------------------------------------
MDrv_GE_BitBltEX(GE_Context * pGECtx,GE_Rect * src,GE_DstBitBltType * dst,MS_U32 flags,GE_ScaleInfo * scaleinfo)3189 GE_Result MDrv_GE_BitBltEX(GE_Context *pGECtx, GE_Rect *src, GE_DstBitBltType *dst, MS_U32 flags, GE_ScaleInfo* scaleinfo)
3190 {
3191 MS_U16 u16cmd = 0;
3192 MS_U16 u16cfg = 0;
3193 MS_U16 u16en = 0;
3194 MS_U16 temp;
3195 MS_BOOL bOverlap = FALSE;
3196 MS_BOOL bNonOnePixelMode = FALSE;
3197 GE_Point v0, v1, v2;
3198 MS_U8 u8Rot;
3199 PatchBitBltInfo patchBitBltInfo;
3200 MS_BOOL bDstXInv = FALSE;
3201 MS_U16 u16tmp,Srcfmt,Dstfmt;
3202 MS_U16 u16tmp_dy;
3203
3204 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
3205 #ifdef GE_ALPHA_BLEND_PATCH
3206 MS_BOOL bDisAlpha = FALSE;
3207 #endif
3208 GE_DBG("%s\n", __FUNCTION__);
3209 GE_ASSERT((src), E_GE_FAIL_PARAM, "%s: Null pointer\n", __FUNCTION__);
3210 GE_ASSERT((dst), E_GE_FAIL_PARAM, "%s: Null pointer\n", __FUNCTION__);
3211
3212 if (flags&(E_GE_FLAG_TRAPEZOID_X|E_GE_FLAG_TRAPEZOID_Y))
3213 {
3214 #ifdef CONFIG_GFX_TRAPZOID
3215 return MDrv_GE_BitBltEX_Trape(pGECtx,src, dst, flags, scaleinfo);
3216 #else
3217 return E_GE_NOT_SUPPORT;
3218 #endif
3219 }
3220
3221 GE_ENTRY(pGECtx);
3222
3223 #if DYNAMIC_POWER_ON_OFF
3224 MDrv_PWR_ClockTurnOn(E_PWR_MODULE_GE);
3225 #endif
3226
3227 if ( (src->width == 0) || (src->height == 0) || (dst->dstblk.width == 0) || (dst->dstblk.height == 0) )
3228 {
3229 GE_RETURN(pGECtx,E_GE_FAIL_PARAM);
3230 }
3231 if ( GE_FastClip(pGECtx,dst->dstblk.x, dst->dstblk.y, dst->dstblk.x+dst->dstblk.width-1, dst->dstblk.y+dst->dstblk.height-1) )
3232 {
3233 if (flags & (
3234 E_GE_FLAG_BLT_ITALIC |
3235 E_GE_FLAG_BLT_ROTATE_90 |
3236 E_GE_FLAG_BLT_ROTATE_180 |
3237 E_GE_FLAG_BLT_ROTATE_270 ))
3238 {
3239 // SKIP fast clipping
3240
3241 //[TODO] Do fast clipping precisely for rotation and italic
3242 }
3243 else
3244 {
3245 GE_RETURN(pGECtx,E_GE_NOT_DRAW);
3246 }
3247 }
3248
3249 //[TODO] check stretch bitblt base address and pitch alignment if we can prevent register
3250 // being READ in queue prolbme (ex. wait_idle or shadow_reg)
3251
3252 // Check overlap
3253 if (flags & E_GE_FLAG_BLT_OVERLAP)
3254 {
3255 if (flags & (
3256 E_GE_FLAG_BLT_STRETCH |
3257 E_GE_FLAG_BLT_ITALIC |
3258 E_GE_FLAG_BLT_MIRROR_H |
3259 E_GE_FLAG_BLT_MIRROR_V |
3260 E_GE_FLAG_BLT_ROTATE_90 |
3261 E_GE_FLAG_BLT_ROTATE_180 |
3262 E_GE_FLAG_BLT_ROTATE_270 ))
3263 {
3264 GE_RETURN(pGECtx,E_GE_FAIL_OVERLAP);
3265 }
3266
3267 //[TODO] Cechk overlap precisely
3268 bOverlap = GE_RectOverlap(pGECtxLocal, src, dst);
3269 }
3270
3271 // Check italic
3272 if (flags & E_GE_FLAG_BLT_ITALIC)
3273 {
3274 if (flags & (
3275 E_GE_FLAG_BLT_MIRROR_H |
3276 E_GE_FLAG_BLT_MIRROR_V |
3277 E_GE_FLAG_BLT_ROTATE_90 |
3278 E_GE_FLAG_BLT_ROTATE_180 |
3279 E_GE_FLAG_BLT_ROTATE_270 ))
3280 {
3281 GE_RETURN(pGECtx,E_GE_FAIL_ITALIC);
3282 }
3283 }
3284
3285 // clear dirty attributes ---------------------------------------------------------------------
3286 GE_SetRotate(&pGECtxLocal->halLocalCtx, E_GE_ROTATE_0);
3287 u16cfg = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_CFG) & ~(GE_CFG_BLT_STRETCH | GE_CFG_BLT_ITALIC);
3288 // clear dirty attributes ---------------------------------------------------------------------
3289
3290
3291 if(flags & E_GE_FLAG_BYPASS_STBCOEF)
3292 {
3293 if(scaleinfo == NULL)
3294 {
3295 GE_RETURN(pGECtx,E_GE_FAIL_PARAM);
3296 }
3297
3298 u16cfg |= GE_CFG_BLT_STRETCH;
3299 if (flags & E_GE_FLAG_STRETCH_NEAREST)
3300 {
3301 u16cmd |= GE_STRETCH_NEAREST;
3302 }
3303 u16cmd |= GE_STRETCH_CLAMP;
3304
3305 }
3306 else if (flags & E_GE_FLAG_BLT_STRETCH)
3307 {
3308
3309 u16cfg |= GE_CFG_BLT_STRETCH;
3310 if (flags & E_GE_FLAG_STRETCH_NEAREST)
3311 {
3312 u16cmd |= GE_STRETCH_NEAREST;
3313 }
3314 u16cmd |= GE_STRETCH_CLAMP;
3315
3316 }
3317 else
3318 {
3319 if ( (src->width != dst->dstblk.width) || (src->height != dst->dstblk.height) )
3320 {
3321 GE_RETURN(pGECtx,E_GE_FAIL_STRETCH);
3322 }
3323
3324 }
3325
3326 if( GE_SetBltScaleRatio(&pGECtxLocal->halLocalCtx, src, dst, (GE_Flag)flags, scaleinfo) == E_GE_FAIL_PARAM)
3327 GE_RETURN(pGECtx,E_GE_FAIL_PARAM);
3328
3329 u16tmp = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_FMT);
3330 Srcfmt = (u16tmp&GE_SRC_FMT_MASK)>>GE_SRC_FMT_SHFT;
3331 Dstfmt = (u16tmp&GE_DST_FMT_MASK)>>GE_DST_FMT_SHFT;
3332 if((GE_FMT_I8 == Srcfmt) && (GE_FMT_I8 != Dstfmt) )
3333 {
3334 pGECtxLocal->bSrcPaletteOn = TRUE;
3335 }
3336 else
3337 {
3338 pGECtxLocal->bSrcPaletteOn = FALSE;
3339 }
3340 GE_Restore_PaletteContext(pGECtxLocal);
3341
3342 v0.x = dst->dstblk.x;
3343 v0.y = dst->dstblk.y;
3344 v1.x = v0.x + dst->dstblk.width - 1;
3345 v1.y = v0.y + dst->dstblk.height - 1;
3346 v2.x = src->x;
3347 v2.y = src->y;
3348
3349
3350 if (bOverlap)
3351 {
3352 MS_DEBUG_MSG(GE_D_INFO("Overlap\n"));
3353
3354 if (v2.x < v0.x)
3355 {
3356 // right to left
3357 temp = v0.x;
3358 v0.x = v1.x;
3359 v1.x = temp;
3360 v2.x += src->width - 1;
3361 u16cmd |= GE_SRC_DIR_X_INV | GE_DST_DIR_X_INV;
3362 }
3363 if (v2.y < v0.y)
3364 {
3365 // bottom up
3366 temp = v0.y;
3367 v0.y = v1.y;
3368 v1.y = temp;
3369 v2.y += src->height - 1;
3370 u16cmd |= GE_SRC_DIR_Y_INV | GE_DST_DIR_Y_INV;
3371 }
3372 }
3373
3374 if (flags & E_GE_FLAG_BLT_MIRROR_H)
3375 {
3376 #if 0
3377 temp = v0.x;
3378 v0.x = v1.x;
3379 v1.x = temp;
3380 #endif
3381 //v2.x += src->width -1;// show repect for history, comment it
3382 u16cmd |= GE_SRC_DIR_X_INV;
3383 }
3384 if (flags & E_GE_FLAG_BLT_MIRROR_V)
3385 {
3386 #if 0
3387 temp = v0.y;
3388 v0.y = v1.y;
3389 v1.y = temp;
3390 #endif
3391 //v2.y += src->height -1;// show repect for history, comment it
3392 u16cmd |= GE_SRC_DIR_Y_INV;
3393 }
3394
3395 if (flags & E_GE_FLAG_BLT_DST_MIRROR_H)
3396 {
3397 temp = v0.x;
3398 v0.x = v1.x;
3399 v1.x = temp;
3400 u16cmd |= GE_DST_DIR_X_INV;
3401 }
3402 if (flags & E_GE_FLAG_BLT_DST_MIRROR_V)
3403 {
3404 temp = v0.y;
3405 v0.y = v1.y;
3406 v1.y = temp;
3407 u16cmd |= GE_DST_DIR_Y_INV;
3408 }
3409
3410 if (flags & E_GE_FLAG_BLT_ITALIC)
3411 {
3412 u16cfg |= GE_CFG_BLT_ITALIC;
3413 }
3414 if (flags & GE_FLAG_BLT_ROTATE_MASK) // deal with ALL rotation mode
3415 {
3416 GE_SetRotate(&pGECtxLocal->halLocalCtx, (GE_RotateAngle)((flags & E_GE_FLAG_BLT_ROTATE_270)>>GE_FLAG_BLT_ROTATE_SHFT));
3417 }
3418
3419 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_X, v0.x);
3420 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_Y, v0.y);
3421 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_X, v1.x);
3422 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_Y, v1.y);
3423 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V2_X, v2.x);
3424 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V2_Y, v2.y);
3425 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_BLT_SRC_W, src->width);
3426
3427 temp = src->height;
3428
3429 if (pGECtxLocal->halLocalCtx.bYScalingPatch)
3430 {
3431 if (temp>5)
3432 {
3433 temp-=5;
3434 }
3435 }
3436
3437 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_BLT_SRC_H, temp);
3438
3439 u8Rot = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_ROT_MODE ) & REG_GE_ROT_MODE_MASK;
3440
3441 // Set dst coordinate
3442 if (u8Rot == 0)
3443 {
3444 if (!bOverlap)
3445 {
3446 if(!(flags & E_GE_FLAG_BLT_DST_MIRROR_H))
3447 {
3448 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_X, v0.x);
3449 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_X, v0.x + dst->dstblk.width - 1);
3450 }
3451 if(!(flags & E_GE_FLAG_BLT_DST_MIRROR_V))
3452 {
3453 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_Y, v0.y);
3454 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_Y, v0.y + dst->dstblk.height- 1);
3455 }
3456 }
3457 }
3458 else if (u8Rot == 1)
3459 {
3460 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_X, v0.x + dst->dstblk.height - 1);
3461 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_Y, v0.y);
3462 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_X, v0.x + dst->dstblk.height + dst->dstblk.width - 2);
3463 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_Y, v0.y + dst->dstblk.height- 1);
3464 }
3465 else if (u8Rot == 2)
3466 {
3467 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_X, v0.x + dst->dstblk.width - 1);
3468 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_Y, v0.y + dst->dstblk.height - 1);
3469 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_X, v0.x + dst->dstblk.width + dst->dstblk.width - 2);
3470 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_Y, v0.y + dst->dstblk.height + dst->dstblk.height - 2);
3471 }
3472 else if (u8Rot == 3)
3473 {
3474 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_X, v0.x);
3475 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V0_Y, v0.y + dst->dstblk.width - 1);
3476 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_X, v0.x + dst->dstblk.width - 1);
3477 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_PRIM_V1_Y, v0.y + dst->dstblk.height + dst->dstblk.width - 2);
3478 }
3479
3480 u16cfg |= GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_CFG) & GE_CFG_CMDQ_MASK;
3481
3482 //enable split mode
3483 if(*(&pGECtxLocal->halLocalCtx.pGeChipPro->bSupportSpiltMode))
3484 {
3485 u16cfg |= GE_CFG_RW_SPLIT;
3486 }
3487
3488 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CFG, u16cfg);
3489
3490 // To check if 1p mode set to TRUE and Non-1p mode limitations
3491 u16en = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_EN);
3492
3493 patchBitBltInfo.flags = flags;
3494 patchBitBltInfo.src.width = src->width;
3495 patchBitBltInfo.src.height= src->height;
3496 patchBitBltInfo.dst.dstblk.width = dst->dstblk.width;
3497 patchBitBltInfo.dst.dstblk.height= dst->dstblk.height;
3498 patchBitBltInfo.scaleinfo = scaleinfo;
3499 bNonOnePixelMode = GE_NonOnePixelModeCaps(&pGECtxLocal->halLocalCtx, &patchBitBltInfo);
3500
3501 #if(GE_PITCH_256_ALIGNED_UNDER_4P_MODE == 1)
3502 //[Curry/Kano] Only dst pitch 256 aligned -> 4P mode is avalible.
3503 if(GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_SRC_PITCH) % 256)
3504 {
3505 bNonOnePixelMode = FALSE; // Must excuted under 1P mode
3506 }else if(GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_DST_PITCH) % 256)
3507 {
3508 bNonOnePixelMode = FALSE; // Must excuted under 1P mode
3509 }
3510 #endif
3511
3512 if(bNonOnePixelMode && (u16en & GE_EN_ONE_PIXEL_MODE))
3513 GE_SetOnePixelMode(&pGECtxLocal->halLocalCtx, FALSE);
3514 else if((!bNonOnePixelMode) && (!(u16en & GE_EN_ONE_PIXEL_MODE)))
3515 GE_SetOnePixelMode(&pGECtxLocal->halLocalCtx, TRUE);
3516
3517 #ifdef GE_ALPHA_BLEND_PATCH
3518 if( (u16GAlphaMode == 0x0) && (u16GAlphaConst == 0x0) )
3519 {
3520 GE_SetAlpha(&pGECtxLocal->halLocalCtx,E_GE_ALPHA_ROP8_INV_CONST);
3521 MDrv_GE_SetAlphaConst(pGECtx,0xFF);
3522 bDisAlpha = TRUE;
3523 }
3524 #endif
3525 u16tmp = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_BLT_SRC_DX);
3526 u16tmp_dy = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_BLT_SRC_DY);
3527 if(((flags&E_GE_FLAG_BLT_STRETCH)&&((u16tmp!=0x1000)||(u16tmp_dy!=0x1000)))||(u8Rot!=0))
3528 {
3529 HAL_GE_EnableCalcSrc_WidthHeight(&pGECtxLocal->halLocalCtx, FALSE);
3530 }
3531 else
3532 {
3533 HAL_GE_EnableCalcSrc_WidthHeight(&pGECtxLocal->halLocalCtx, TRUE);
3534 }
3535 bDstXInv = (u16cmd & (GE_DST_DIR_X_INV))?TRUE:FALSE;
3536 if(!u8Rot)
3537 {
3538 HAL_GE_AdjustDstWin(&pGECtxLocal->halLocalCtx,bDstXInv);
3539 }
3540 else
3541 {
3542 HAL_GE_AdjustRotateDstWin(&pGECtxLocal->halLocalCtx,u8Rot);
3543 }
3544
3545 //if srcfmt == dstfmt, dont use Dither
3546 u16tmp = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_FMT);
3547 Srcfmt = (u16tmp&GE_SRC_FMT_MASK)>>GE_SRC_FMT_SHFT;
3548 Dstfmt = (u16tmp&GE_DST_FMT_MASK)>>GE_DST_FMT_SHFT;
3549 if( (Srcfmt == Dstfmt)
3550 ||((Srcfmt == E_MS_FMT_ARGB1555)&&(Dstfmt == E_MS_FMT_ARGB1555_DST))
3551 ||((Srcfmt == E_MS_FMT_ARGB1555_DST)&&(Dstfmt == E_MS_FMT_ARGB1555))
3552 )
3553 {
3554 MDrv_GE_SetDither(pGECtx, FALSE);
3555 }
3556
3557 #ifdef GE_VQ_MIU_HANG_PATCH
3558 if ((GE_IsVcmdqEnabled(pGECtx) == TRUE) &&
3559 (u8DstMIU != pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu)
3560 )
3561 {
3562 //printf("\33[0;36m %s:%d u8VCmdQMiu = %d u8SrcMIU = %d u8DstMIU = %d\33[m \n",__FUNCTION__,__LINE__,pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu,u8SrcMIU,u8DstMIU);
3563 MDrv_GE_WaitIdle(pGECtx);
3564 }
3565 #endif
3566 _GE_SEMAPHORE_ENTRY(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
3567 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CMD, GE_PRIM_BITBLT | u16cmd);
3568 _GE_SEMAPHORE_RETURN(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
3569
3570 #ifdef GE_VQ_MIU_HANG_PATCH
3571 if ((GE_IsVcmdqEnabled(pGECtx) == TRUE) &&
3572 (u8DstMIU != pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu)
3573 )
3574 {
3575 //printf("\33[0;36m %s:%d u8VCmdQMiu = %d u8SrcMIU = %d u8DstMIU = %d\33[m \n",__FUNCTION__,__LINE__,pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu,u8SrcMIU,u8DstMIU);
3576 MDrv_GE_WaitIdle(pGECtx);
3577 }
3578 #endif
3579
3580 #ifdef GE_ALPHA_BLEND_PATCH
3581 if(bDisAlpha)
3582 {
3583 GE_SetAlpha(&pGECtxLocal->halLocalCtx,E_GE_ALPHA_CONST);
3584 MDrv_GE_SetAlphaConst(pGECtx,0x0);
3585 }
3586 #endif
3587
3588 //Backup
3589 if( u16en & GE_EN_ONE_PIXEL_MODE)
3590 GE_SetOnePixelMode(&pGECtxLocal->halLocalCtx, TRUE);
3591 else if(!(u16en & GE_EN_ONE_PIXEL_MODE))
3592 GE_SetOnePixelMode(&pGECtxLocal->halLocalCtx, FALSE);
3593
3594 /* move to devGE.c
3595 #if GE_PATCH_ENABLE
3596 //[PATCH] assign dummy cmd before other command (e.g. X,Y or COLOR, EN) push into queue.
3597 // Next reg_write will corrupted this RECT if it's still drawing at that time.
3598 GE_WriteReg(REG_GE_EN, GE_ReadReg(REG_GE_EN));
3599 //[PATCH]
3600 #endif
3601 */
3602
3603 #if DYNAMIC_POWER_ON_OFF
3604 GE_WaitIdle(&pGECtxLocal->halLocalCtx);
3605 MDrv_PWR_ClockTurnOff(E_PWR_MODULE_GE);
3606 #endif
3607
3608 GE_RETURN(pGECtx,E_GE_OK);
3609 }
3610 #ifdef CONFIG_GFX_TRAPZOID
3611 //-------------------------------------------------------------------------------------------------
3612 /// GE Primitive Drawing - Trapezoid BLT
3613 /// Case 1: HW supported Trapezoid, done with HAL Level GE Functions;
3614 /// Case 2: HW does not support Trapezoid, done with DRV Level GE Functions, implemented by Rect Bitblit;
3615 /// @param pGECtx \b IN: GE context
3616 /// @param pSrcRect \b IN: source Trapezoid of bitblt
3617 /// @param pDstRect \b IN: destination Trapezoid of bitblt
3618 /// @param u32Flags \b IN: RECT drawing flags
3619 /// @param pScaleinfo \b IN: customized scale info
3620 /// @return @ref GE_Result
3621 /// @note\n
3622 /// FMT_I1,I2,I4,I8: should be 64-bit aligned in base and pitch to do stretch bitblt.\n
3623 /// FMT_YUV422: the rectangle should be YUV422 block aligned. (4 bytes for 2 pixels in horizontal)
3624 //-------------------------------------------------------------------------------------------------
MDrv_GE_BitBltEX_Trape(GE_Context * pGECtx,GE_Rect * pSrcRect,GE_DstBitBltType * pDstRect,MS_U32 u32Flags,GE_ScaleInfo * pScaleinfo)3625 GE_Result MDrv_GE_BitBltEX_Trape(GE_Context *pGECtx,GE_Rect *pSrcRect, GE_DstBitBltType *pDstRect, MS_U32 u32Flags, GE_ScaleInfo* pScaleinfo)
3626 {
3627 GE_Result geResult;
3628 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
3629 GE_Trapezoid *pGeTrapezoid = &pDstRect->dsttrapeblk;
3630 GE_Normalized_Trapezoid geNormTrapezoid;
3631 GE_ScaleInfo geScaleinfo, *pGeScaleInfo = (u32Flags & E_GE_FLAG_BYPASS_STBCOEF) ? pScaleinfo : &geScaleinfo;
3632 MS_BOOL bYTrapezoid = (u32Flags & E_GE_FLAG_TRAPEZOID_Y) ? TRUE : FALSE;
3633
3634 GE_DBG("%s\n", __FUNCTION__);
3635
3636 GE_ENTRY(pGECtx);
3637
3638 //check parameters:
3639 if(NULL == pGeScaleInfo)
3640 {
3641 GE_RETURN(pGECtx, E_GE_FAIL_PARAM);
3642 }
3643
3644 if((pSrcRect->width == 0) || (pSrcRect->height == 0)
3645 || ((pGeTrapezoid->u16Y0>=pGeTrapezoid->u16Y1)&&(bYTrapezoid==FALSE))
3646 || ((pGeTrapezoid->u16X0<=pGeTrapezoid->u16X1)&&(bYTrapezoid==TRUE))
3647 || (0==pGeTrapezoid->u16DeltaTop)
3648 || (0==pGeTrapezoid->u16DeltaBottom))
3649 {
3650 GE_RETURN(pGECtx, E_GE_FAIL_PARAM);
3651 }
3652
3653 if(GE_FastClipTrapezoid(pGECtx, pGeTrapezoid->u16X0, pGeTrapezoid->u16Y0, pGeTrapezoid->u16X1, pGeTrapezoid->u16Y1, pGeTrapezoid->u16DeltaTop, pGeTrapezoid->u16DeltaBottom, bYTrapezoid))
3654 {
3655 if(u32Flags & (E_GE_FLAG_BLT_ITALIC))
3656 {
3657 // SKIP fast clipping
3658 //[TODO] Do fast clipping precisely for italic
3659 }
3660 else
3661 {
3662 GE_RETURN(pGECtx,E_GE_NOT_DRAW);
3663 }
3664 }
3665
3666 // Check overlap
3667 if(u32Flags & E_GE_FLAG_BLT_OVERLAP)
3668 {
3669 if(FALSE == GE_TrapezoidOverlap(pSrcRect, pGeTrapezoid))
3670 {
3671 u32Flags &= (~E_GE_FLAG_BLT_OVERLAP);
3672 }else
3673 {
3674 GE_RETURN(pGECtx, E_GE_FAIL_OVERLAP);
3675 }
3676 }
3677
3678 // Check italic
3679 if(u32Flags & E_GE_FLAG_BLT_ITALIC)
3680 {
3681 if(u32Flags & (
3682 E_GE_FLAG_BLT_MIRROR_H |
3683 E_GE_FLAG_BLT_MIRROR_V ))
3684 {
3685 GE_RETURN(pGECtx,E_GE_FAIL_ITALIC);
3686 }
3687 }
3688
3689 // Reset-Rotate: Rotate setting won't take effect for Trapezoid bitblit:
3690 u32Flags &= ~E_GE_FLAG_BLT_ROTATE_270;
3691
3692 #if DYNAMIC_POWER_ON_OFF
3693 MDrv_PWR_ClockTurnOn(E_PWR_MODULE_GE);
3694 #endif
3695
3696 //Transfer Driver definition of Trapezoid to Hardware definition of trapezoid:
3697 GE_NormalizeTrapezoidDef(pGeTrapezoid, &geNormTrapezoid, bYTrapezoid);
3698 //Set Scale Info:
3699 if(!(u32Flags & E_GE_FLAG_BYPASS_STBCOEF))
3700 {
3701 if(bYTrapezoid)
3702 {
3703 GE_CalcBltScaleRatio(&pGECtxLocal->halLocalCtx, pSrcRect->width, pSrcRect->height, (geNormTrapezoid.u16X0-geNormTrapezoid.u16X1+1), pGeTrapezoid->u16DeltaTop, pGeScaleInfo);
3704 }
3705 else
3706 {
3707 GE_CalcBltScaleRatio(&pGECtxLocal->halLocalCtx, pSrcRect->width, pSrcRect->height, pGeTrapezoid->u16DeltaTop, (geNormTrapezoid.u16Y1-geNormTrapezoid.u16Y0+1), pGeScaleInfo);
3708 }
3709 }
3710
3711 GE_Restore_PaletteContext(pGECtxLocal);
3712
3713 //Actual Bitblit:
3714 geResult = GE_BitBltEX_Trape(&pGECtxLocal->halLocalCtx, pSrcRect, &geNormTrapezoid, u32Flags, pGeScaleInfo);
3715 if(E_GE_OK != geResult)
3716 {
3717 geResult = GE_TrapezoidBlit(pGECtxLocal, pSrcRect, &geNormTrapezoid, u32Flags, pGeScaleInfo);
3718 }
3719
3720 #if DYNAMIC_POWER_ON_OFF
3721 GE_WaitIdle(&pGECtxLocal->halLocalCtx);
3722 MDrv_PWR_ClockTurnOff(E_PWR_MODULE_GE);
3723 #endif
3724
3725 GE_RETURN(pGECtx,(GE_Result)geResult);
3726 }
3727 #endif
3728
3729
3730 //-------------------------------------------------------------------------------------------------
3731 /// Wait GE engine idle
3732 /// @param pGECtx \b IN: GE context
3733 /// @return @ref GE_Result
3734 //-------------------------------------------------------------------------------------------------
MDrv_GE_WaitIdle(GE_Context * pGECtx)3735 GE_Result MDrv_GE_WaitIdle(GE_Context *pGECtx)
3736 {
3737 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
3738
3739 GE_DBG("%s\n", __FUNCTION__);
3740 GE_ENTRY(pGECtx);
3741
3742 GE_WaitIdle(&pGECtxLocal->halLocalCtx);
3743
3744 GE_RETURN(pGECtx,E_GE_OK);
3745 }
3746
3747 #if GE_LOCK_SUPPORT
3748 #if defined(MSOS_TYPE_LINUX) || defined(MSOS_TYPE_LINUX_KERNEL)
GE_AtExit(void * pInstance)3749 static void GE_AtExit(void* pInstance)
3750 {
3751 #if(GFX_UTOPIA20)
3752 GFX_INSTANT_PRIVATE* psGFXInstPriTmp;
3753 UtopiaInstanceGetPrivate(pInstance, (void**)&psGFXInstPriTmp);
3754 #endif
3755
3756 GE_CTX_LOCAL *pGECtxLocal = &g_drvGECtxLocal;
3757 #if GE_USE_HW_SEM
3758 MS_U16 GE_HWSemaphore_count =0;
3759 MS_U16 GE_GetHWSemaphoreID=0;
3760 #endif
3761
3762 if(pGECtxLocal->s32GE_Recursive_Lock_Cnt > 0)
3763 {
3764 pGECtxLocal->s32GE_Recursive_Lock_Cnt = 0;
3765 MsOS_ReleaseMutex(pGECtxLocal->s32GEMutex);
3766 #if GE_USE_HW_SEM
3767 while(MDrv_SEM_Free_Resource(GESEMID, pGECtxLocal->u32GESEMID) ==FALSE)
3768 {
3769 GE_HWSemaphore_count++;
3770 if(GE_HWSemaphore_count>10000)
3771 {
3772 MDrv_SEM_Get_ResourceID(GESEMID, &GE_GetHWSemaphoreID);
3773 GE_D_DBUG("\33[0;31m [Return While][%s][%d] GE_GetHWSemphoreID=%tx; u32GESEMID=%tx\33[m;\n",__FUNCTION__,__LINE__, (ptrdiff_t)GE_GetHWSemaphoreID, (ptrdiff_t)pGECtxLocal->u32GESEMID);
3774 GE_HWSemaphore_count =0;
3775 }
3776 }
3777 #endif
3778 }
3779 }
3780 #endif
3781 #endif
3782
MDrv_GE_Exit(void * pInstance)3783 void MDrv_GE_Exit(void* pInstance)
3784 {
3785 #if GE_LOCK_SUPPORT
3786 #if defined(MSOS_TYPE_LINUX) || defined(MSOS_TYPE_LINUX_KERNEL)
3787 GE_AtExit(pInstance);
3788 #else
3789 GE_D_DBUG("not enable MSOS_TYPE_LINUX\n");
3790 #endif
3791 #else
3792 GE_D_ERR("not enable GE_LOCK_SUPPORT\n");
3793 #endif
3794 }
3795
3796 //-------------------------------------------------------------------------------------------------
3797 /// GE DDI Initialization
3798 /// @param cfg \b IN: @ref GE_Config
3799 /// @param ppGECtx \b IN: GE context
3800 /// @return @ref GE_Result
3801 //-------------------------------------------------------------------------------------------------
MDrv_GE_Init(void * pInstance,GE_Config * cfg,GE_Context ** ppGECtx)3802 GE_Result MDrv_GE_Init(void* pInstance, GE_Config *cfg, GE_Context **ppGECtx)
3803 {
3804 MS_VIRT regaddr = 0x0;
3805 MS_PHY u32regsize = 0x0;
3806 GE_CTX_LOCAL *pGECtxLocal = NULL;
3807 GE_CTX_SHARED *pGEShared;
3808 MS_BOOL bNeedInitShared = FALSE;
3809
3810 GE_DBG("%s\n", __FUNCTION__);
3811 #if(GFX_UTOPIA20)
3812 GFX_INSTANT_PRIVATE* psGFXInstPriTmp;
3813 UtopiaInstanceGetPrivate(pInstance, (void**)&psGFXInstPriTmp);
3814 pGECtxLocal = &g_drvGECtxLocal;
3815 pGECtxLocal->ctxHeader.pInstance =pInstance;
3816 #else
3817 pGECtxLocal = &g_drvGECtxLocal;
3818 #endif
3819
3820 #if defined(MSOS_TYPE_LINUX) || defined(MSOS_TYPE_LINUX_KERNEL)
3821 MS_U32 u32ShmId;
3822 MS_VIRT VAddr;
3823 MS_U32 u32BufSize;
3824
3825 if (FALSE == MsOS_SHM_GetId((MS_U8*)"GE driver", sizeof(GE_CTX_SHARED), &u32ShmId, &VAddr, &u32BufSize, MSOS_SHM_QUERY)) // Richard: Query if there is ��IPC driver�� exist in share memory
3826 {
3827 if (FALSE == MsOS_SHM_GetId((MS_U8*)"GE driver", sizeof(GE_CTX_SHARED), &u32ShmId, &VAddr, &u32BufSize, MSOS_SHM_CREATE)) // Richard: Create ��IPC driver�� exist in share memory
3828 {
3829 GE_DBG("SHM allocation failed!\n");
3830 *ppGECtx = NULL;
3831 return E_GE_FAIL;
3832 }
3833 GE_DBG("[%s][%d] This is first initial 0x%08x\n", __FUNCTION__, __LINE__, VAddr); // Richard: The process first calling this function should print this out
3834 memset( (MS_U8*)VAddr, 0, sizeof(GE_CTX_SHARED));
3835 bNeedInitShared = TRUE;
3836
3837 }
3838 pGEShared = (GE_CTX_SHARED*)VAddr;
3839 #else
3840 pGEShared = &g_drvGECtxShared;
3841 bNeedInitShared = TRUE;
3842 memset( pGEShared, 0, sizeof(GE_CTX_SHARED));
3843 #endif
3844
3845 #if (GE_USE_HW_SEM && defined(MSOS_TYPE_OPTEE))
3846 pGECtxLocal->u32GESEMID = SEM_HK51ID;
3847 #else
3848 #ifdef __AEON__
3849 pGECtxLocal->u32GESEMID = SEM_MWMipsID;
3850 #else
3851 pGECtxLocal->u32GESEMID = SEM_HKAeonID;
3852 #endif
3853 #endif
3854 pGECtxLocal->u16GEPrevSEMID = pGECtxLocal->u32GESEMID;
3855 pGECtxLocal->bIsComp = cfg->bIsCompt;
3856 pGECtxLocal->bSrcPaletteOn = FALSE;
3857 pGECtxLocal->bDstPaletteOn = FALSE;
3858
3859 // need add lock for protect SHM.
3860
3861 pGECtxLocal->u32CTXInitMagic = 0x55aabeef;
3862
3863 pGECtxLocal->pSharedCtx = pGEShared;
3864 GE_Init_HAL_Context(&pGECtxLocal->halLocalCtx, &pGEShared->halSharedCtx, bNeedInitShared);
3865
3866 // save Init parameter
3867 pGEShared->bInit=TRUE;
3868 pGEShared->u32VCmdQSize=cfg->u32VCmdQSize;
3869 pGEShared->PhyVCmdQAddr=cfg->PhyVCmdQAddr;
3870 pGEShared->bIsHK=cfg->bIsHK;
3871 pGEShared->bIsCompt=cfg->bIsCompt;
3872
3873 pGECtxLocal->halLocalCtx.bIsComp = pGECtxLocal->bIsComp;
3874
3875 pGECtxLocal->u32GEClientId = ++pGEShared->u32GEClientAllocator;
3876 if(0 == pGECtxLocal->u32GEClientId)
3877 pGECtxLocal->u32GEClientId = ++pGEShared->u32GEClientAllocator;
3878
3879 pGECtxLocal->ctxHeader.u32GE_DRV_Version = GE_API_MUTEX;
3880 pGECtxLocal->ctxHeader.bGEMode4MultiProcessAccess = GE_SWTABLE;
3881 pGECtxLocal->ctxHeader.s32CurrentProcess = (MS_S32)getpid();
3882 pGECtxLocal->ctxHeader.s32CurrentThread = 0;
3883
3884 if (pGECtxLocal->ctxHeader.bGEMode4MultiProcessAccess ==FALSE)
3885 pGECtxLocal->pSharedCtx->halSharedCtx.bGE_DirectToReg =TRUE;
3886 else
3887 pGECtxLocal->pSharedCtx->halSharedCtx.bGE_DirectToReg =FALSE;
3888 *ppGECtx = (GE_Context *)pGECtxLocal;
3889
3890 if(!OSAL_GE_GetMapBase(®addr, &u32regsize))
3891 {
3892 GE_DBG("Get GE IOMAP Base faill!\n");
3893 return E_GE_FAIL;
3894 }
3895
3896 GE_Set_IOMap_Base(&pGECtxLocal->halLocalCtx, regaddr);
3897
3898 if (!OSAL_GE_GetMapBase2(®addr, &u32regsize))
3899 {
3900 GE_DBG("Get Chip bank IOMAP Base faill!\n");
3901 return E_GE_FAIL;
3902 }
3903 GE_Set_IOMap_Base2(&pGECtxLocal->halLocalCtx, regaddr);
3904
3905 pGECtxLocal->s32GE_Recursive_Lock_Cnt = 0;
3906 #if GE_LOCK_SUPPORT
3907 pGECtxLocal->s32GELock = -1;
3908
3909 pGECtxLocal->s32GEMutex = MsOS_CreateMutex(E_MSOS_FIFO, "GE_Mutex", MSOS_PROCESS_SHARED);
3910 if (pGECtxLocal->s32GEMutex < 0)
3911 {
3912 GE_ERR("%s Fail\n", __FUNCTION__);
3913 return E_GE_FAIL;
3914 }
3915
3916 #endif
3917
3918 #if (ENABLE_PWR)
3919 MDrv_PWR_ClockTurnOn(E_PWR_MODULE_GE);
3920 #endif
3921
3922
3923 GE_Get_Resource(*ppGECtx,TRUE);
3924 // Enable Command Queue
3925 (*ppGECtx)->pBufInfo.srcfmt = ((GE_BufFmt)E_GE_FMT_ARGB1555);
3926 (*ppGECtx)->pBufInfo.dstfmt = ((GE_BufFmt)E_GE_FMT_ARGB1555);
3927 GE_Init(&pGECtxLocal->halLocalCtx, cfg);
3928 //Init GE Palette from HW:
3929 GE_InitCtxHalPalette(&pGECtxLocal->halLocalCtx);
3930
3931 if (bNeedSetActiveCtrlMiu1)
3932 GE_SetActiveCtrlMiu1(&pGECtxLocal->halLocalCtx);
3933 // Default setting : To avoid GE issues commands too frequently when VC in enabled
3934 MDrv_GE_SetVCmd_W_Thread(*ppGECtx, 0x4);
3935 MDrv_GE_SetVCmd_R_Thread(*ppGECtx, 0x4);
3936
3937 pGECtxLocal->pSharedCtx->bNotFirstInit = TRUE;
3938
3939 GE_Free_Resource(*ppGECtx, TRUE);
3940 return E_GE_OK;
3941 }
3942
MDrv_GE_GetConfig(GE_Config * cfg)3943 GE_Result MDrv_GE_GetConfig(GE_Config *cfg)
3944 {
3945 MS_BOOL bNeedInitShared = FALSE;
3946 GE_CTX_SHARED *pGEShared;
3947
3948 #if defined(MSOS_TYPE_LINUX) || defined(MSOS_TYPE_LINUX_KERNEL)
3949 MS_U32 u32ShmId;
3950 MS_VIRT VAddr;
3951 MS_U32 u32BufSize;
3952
3953 if (FALSE == MsOS_SHM_GetId((MS_U8*)"GE driver", sizeof(GE_CTX_SHARED), &u32ShmId, &VAddr, &u32BufSize, MSOS_SHM_QUERY)) // Richard: Query if there is gIPC driverh exist in share memory
3954 {
3955 if (FALSE == MsOS_SHM_GetId((MS_U8*)"GE driver", sizeof(GE_CTX_SHARED), &u32ShmId, &VAddr, &u32BufSize, MSOS_SHM_CREATE)) // Richard: Create gIPC driverh exist in share memory
3956 {
3957 GE_DBG("SHM allocation failed!\n");
3958 return E_GE_FAIL;
3959 }
3960 GE_DBG("[%s][%d] This is first initial 0x%08x\n", __FUNCTION__, __LINE__, VAddr); // Richard: The process first calling this function should print this out
3961 memset( (MS_U8*)VAddr, 0, sizeof(GE_CTX_SHARED));
3962 bNeedInitShared = TRUE;
3963
3964 }
3965 pGEShared = (GE_CTX_SHARED*)VAddr;
3966 #else
3967 pGEShared = &g_drvGECtxShared;
3968 bNeedInitShared = TRUE;
3969 memset( pGEShared, 0, sizeof(GE_CTX_SHARED));
3970 #endif
3971
3972 if(FALSE==pGEShared->bInit)
3973 return E_GE_FAIL;
3974 cfg->u32VCmdQSize=pGEShared->u32VCmdQSize;
3975 cfg->PhyVCmdQAddr=pGEShared->PhyVCmdQAddr;
3976 cfg->bIsHK=pGEShared->bIsHK;
3977 cfg->bIsCompt=pGEShared->bIsCompt;
3978
3979 return E_GE_OK;
3980 }
3981
MDrv_GE_Chip_Proprity_Init(GE_Context * pGECtx,GE_CHIP_PROPERTY ** ppGeChipPro)3982 GE_Result MDrv_GE_Chip_Proprity_Init(GE_Context *pGECtx, GE_CHIP_PROPERTY **ppGeChipPro)
3983 {
3984 if ( pGECtx == NULL )
3985 {
3986 GE_D_ERR("\n%s, %d, 1st param. can't be null pointer\n", __FUNCTION__, __LINE__);
3987 return E_GE_FAIL;
3988 }
3989 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
3990
3991 GE_DBG("%s\n", __FUNCTION__);
3992 GE_ENTRY(pGECtx);
3993
3994 GE_Chip_Proprity_Init(&pGECtxLocal->halLocalCtx);
3995 *ppGeChipPro = pGECtxLocal->halLocalCtx.pGeChipPro;
3996
3997 GE_RETURN(pGECtx, E_GE_OK);
3998 }
3999
4000 //[RESERVED]
4001 //-------------------------------------------------------------------------------------------------
4002 /// Shutdown GE HW.
4003 /// @param pGECtx \b IN: GE context
4004 /// @param miu \b IN: miu being procted
4005 /// @param addr_low \b IN: low address of specified area
4006 /// @param addr_high \b IN: high address of specified area
4007 /// @param eWPType \b IN: GE protect operator
4008 /// @return @ref GE_Result
4009 //-------------------------------------------------------------------------------------------------
MDrv_GE_WriteProtect(GE_Context * pGECtx,MS_U8 miu,MS_PHY addr_low,MS_PHY addr_high,GE_WPType eWPType)4010 GE_Result MDrv_GE_WriteProtect(GE_Context *pGECtx, MS_U8 miu, MS_PHY addr_low, MS_PHY addr_high, GE_WPType eWPType)
4011 {
4012 GE_Result ret;
4013 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4014
4015 GE_DBG("%s\n", __FUNCTION__);
4016 GE_ENTRY(pGECtx);
4017
4018 if ((addr_high&0x07FFFFFF) < (addr_low&0x07FFFFFF))
4019 {
4020 GE_RETURN(pGECtx,E_GE_FAIL);
4021 }
4022
4023 ret = GE_WriteProtect(&pGECtxLocal->halLocalCtx, miu, addr_low, addr_high, eWPType);
4024
4025 GE_RETURN(pGECtx,ret);
4026 }
4027 //[RESERVED]
4028
4029
4030 //-------------------------------------------------------------------------------------------------
4031 /// Shutdown GE HW.
4032 /// @param pGECtx \b IN: GE context
4033 /// @return @ref GE_Result
4034 //-------------------------------------------------------------------------------------------------
MDrv_GE_PowerOff(GE_Context * pGECtx)4035 GE_Result MDrv_GE_PowerOff(GE_Context *pGECtx)
4036 {
4037 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4038
4039 GE_DBG("%s\n", __FUNCTION__);
4040 GE_ENTRY(pGECtx);
4041
4042 GE_WaitIdle(&pGECtxLocal->halLocalCtx);
4043 #if (ENABLE_PWR)
4044 MDrv_PWR_ClockTurnOff(E_PWR_MODULE_GE);
4045 #endif
4046
4047 GE_RETURN(pGECtx,E_GE_OK);
4048 }
4049
4050 //-------------------------------------------------------------------------------------------------
4051 /// Get GE buffer format capabilities
4052 /// @param pGECtx \b IN: GE context
4053 /// @param fmt \b IN: specified GE buffer format
4054 /// @param type \b IN: type of buffer
4055 /// @param caps \b OUT: pointer of GE_FmtCaps returned for specified format
4056 /// @return @ref GE_Result
4057 //-------------------------------------------------------------------------------------------------
MDrv_GE_GetFmtCaps(GE_Context * pGECtx,GE_BufFmt fmt,GE_BufType type,GE_FmtCaps * caps)4058 GE_Result MDrv_GE_GetFmtCaps(GE_Context *pGECtx, GE_BufFmt fmt, GE_BufType type, GE_FmtCaps *caps)
4059 {
4060 GE_Result ret;
4061 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4062
4063 GE_DBG("%s\n", __FUNCTION__);
4064 GE_ENTRY(pGECtx);
4065
4066 ret = GE_GetFmtCaps(&pGECtxLocal->halLocalCtx, fmt, type, caps);
4067
4068 GE_RETURN(pGECtx,ret);
4069 }
4070
4071
4072 //-------------------------------------------------------------------------------------------------
4073 /// Set GE alpha value of ARGB1555 mode.
4074 /// @param pGECtx \b IN: Pointer to GE context.
4075 /// @param coef \b IN: Alpha coef for ARGB1555.
4076 /// @return @ref GE_Result
4077 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetAlpha_ARGB1555(GE_Context * pGECtx,MS_U8 coef)4078 GE_Result MDrv_GE_SetAlpha_ARGB1555(GE_Context *pGECtx, MS_U8 coef)
4079 {
4080 MS_U16 u16tmp;
4081 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4082
4083 GE_DBG("%s\n", __FUNCTION__);
4084 GE_ENTRY(pGECtx);
4085
4086 u16tmp = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_BLEND);
4087 u16tmp |= (MS_U16)coef<<8; ///- Set Alpha for ARGB1555
4088 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_BLEND, u16tmp);
4089
4090 GE_RETURN(pGECtx,E_GE_OK);
4091 }
4092
4093
4094 //-------------------------------------------------------------------------------------------------
4095 /// Get GE alpha value of ARGB1555 mode.
4096 /// @param pGECtx \b IN: Pointer to GE context.
4097 /// @param coef \b OUT: Alpha coef for ARGB1555.
4098 /// @return @ref GE_Result
4099 //-------------------------------------------------------------------------------------------------
MDrv_GE_GetAlpha_ARGB1555(GE_Context * pGECtx,MS_U8 * coef)4100 GE_Result MDrv_GE_GetAlpha_ARGB1555(GE_Context *pGECtx, MS_U8* coef)
4101 {
4102 MS_U16 u16tmp;
4103 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4104
4105 GE_DBG("%s\n", __FUNCTION__);
4106 GE_ENTRY(pGECtx);
4107
4108 if(coef == NULL)
4109 GE_RETURN(pGECtx,E_GE_FAIL_PARAM);
4110
4111 u16tmp = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_BLEND);
4112
4113 *coef = (u16tmp >> 8) &0xff;
4114
4115 GE_RETURN(pGECtx,E_GE_OK);
4116 }
4117
4118
4119 //-------------------------------------------------------------------------------------------------
4120 /// Set GE TAGID value.
4121 /// The TAGID is taken as GE engine serialization.
4122 /// @param pGECtx \b IN: Pointer to GE context.
4123 /// @param u16tag \b IN: Tag value to be set.
4124 /// @return @ref GE_Result
4125 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetTAGID(GE_Context * pGECtx,MS_U16 u16tag)4126 GE_Result MDrv_GE_SetTAGID(GE_Context *pGECtx, MS_U16 u16tag)
4127 {
4128 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4129
4130 GE_ENTRY(pGECtx);
4131
4132 //GE hw will kick off cmd in pairs, so send tagID twice to force kick off
4133 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_TAG, u16tag);
4134 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_TAG, u16tag);
4135
4136 GE_RETURN(pGECtx,E_GE_OK);
4137 }
4138
4139 //-------------------------------------------------------------------------------------------------
4140 /// Get GE TAGID value.
4141 /// The TAGID is taken as GE engine serialization.
4142 /// @param pGECtx \b IN: Pointer to GE context.
4143 /// @param u16tag \b OUT: Tag value to be set.
4144 /// @return @ref GE_Result
4145 //-------------------------------------------------------------------------------------------------
MDrv_GE_GetTAGID(GE_Context * pGECtx,MS_U16 * u16tag)4146 GE_Result MDrv_GE_GetTAGID(GE_Context *pGECtx, MS_U16* u16tag)
4147 {
4148 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4149
4150 GE_ENTRY(pGECtx);
4151
4152 *u16tag = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_TAG);
4153
4154 GE_RETURN(pGECtx,E_GE_OK);
4155
4156 }
4157
4158 //-------------------------------------------------------------------------------------------------
4159 /// Wait GE TagID back
4160 /// @param pGECtx \b IN: Pointer to GE context.
4161 /// @param tagID \b IN: tag id number for wating
4162 /// @return @ref GE_Result
4163 //-------------------------------------------------------------------------------------------------
MDrv_GE_WaitTAGID(GE_Context * pGECtx,MS_U16 tagID)4164 GE_Result MDrv_GE_WaitTAGID(GE_Context *pGECtx, MS_U16 tagID)
4165 {
4166 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4167
4168 GE_ENTRY(pGECtx);
4169
4170 GE_WaitTAGID(&pGECtxLocal->halLocalCtx, tagID);
4171
4172 GE_RETURN(pGECtx,E_GE_OK);
4173 }
4174
4175 //-------------------------------------------------------------------------------------------------
4176 /// Polling GE TagID back
4177 /// @param pGECtx \b IN: Pointer to GE context.
4178 /// @param tagID \b IN: tag id number for wating
4179 /// @return @ref GE_Result
4180 //-------------------------------------------------------------------------------------------------
MDrv_GE_PollingTAGID(GE_Context * pGECtx,MS_U16 tagID)4181 GE_Result MDrv_GE_PollingTAGID(GE_Context *pGECtx, MS_U16 tagID)
4182 {
4183 GE_Result geResult = E_GE_FAIL;
4184
4185 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4186
4187 GE_ENTRY(pGECtx);
4188
4189 geResult = GE_PollingTAGID(&pGECtxLocal->halLocalCtx, tagID);
4190
4191 if (E_GE_OK == geResult)
4192 {
4193 GE_RETURN(pGECtx,E_GE_OK);
4194 }
4195 else
4196 {
4197 GE_RETURN(pGECtx,E_GE_FAIL);
4198 }
4199 }
4200
4201 //-------------------------------------------------------------------------------------------------
4202 /// Get Next GE TagID
4203 /// Get the TAGID in bStepTagBefore steps.
4204 /// @param pGECtx \b IN: GE context
4205 /// @param bStepTagBefore \b IN: Steps to the NEXT TAGID.
4206 /// @return tagID
4207 //-------------------------------------------------------------------------------------------------
MDrv_GE_GetNextTAGID(GE_Context * pGECtx,MS_BOOL bStepTagBefore,MS_U16 * u16NextTagID)4208 GE_Result MDrv_GE_GetNextTAGID(GE_Context *pGECtx, MS_BOOL bStepTagBefore, MS_U16* u16NextTagID)
4209 {
4210 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4211
4212 GE_ENTRY(pGECtx);
4213
4214 *u16NextTagID = GE_GetNextTAGID(&pGECtxLocal->halLocalCtx, bStepTagBefore);
4215
4216 GE_RETURN(pGECtx,E_GE_OK);
4217 }
4218
4219 //-------------------------------------------------------------------------------------------------
4220 /// Set next TagID Auto to HW
4221 /// Get the Next Tag ID auto and set it to HW.
4222 /// @param pGECtx \b IN: GE context
4223 /// @param tagID \b OUT: The Tag ID which has been sent to hw
4224 /// @return @ref GE_Result
4225 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetNextTAGID(GE_Context * pGECtx,MS_U16 * tagID)4226 GE_Result MDrv_GE_SetNextTAGID(GE_Context *pGECtx, MS_U16 *tagID)
4227 {
4228 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4229 GE_ENTRY(pGECtx);
4230
4231 *tagID = GE_GetNextTAGID(&pGECtxLocal->halLocalCtx, TRUE);
4232
4233 //GE hw will kick off cmd in pairs, so send tagID twice to force kick off
4234 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_TAG, *tagID);
4235 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_TAG, *tagID);
4236
4237 GE_RETURN(pGECtx, E_GE_OK);
4238 }
4239
4240 //-------------------------------------------------------------------------------------------------
4241 /// Set GE Dbglevel (0 => no dbg)
4242 /// @param pGECtx \b IN: GE context
4243 /// @param level \b IN: Debug level.
4244 /// @return @ref GE_Result
4245 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetDbgLevel(GE_Context * pGECtx,MS_U32 level)4246 GE_Result MDrv_GE_SetDbgLevel(GE_Context *pGECtx, MS_U32 level)
4247 {
4248
4249 GE_ENTRY(pGECtx);
4250 dbg_level = level;
4251 if(dbg_level ==0)
4252 {
4253 GE_RETURN(pGECtx,E_GE_OK);
4254 }
4255 else
4256 {
4257 GE_RETURN(pGECtx,E_GE_OK);
4258 }
4259 }
4260
4261 //-------------------------------------------------------------------------------------------------
4262 /// Get GE internal information
4263 /// @param pGECtx \b IN: GE context
4264 /// @param dbg \b OUT: Pointer to GE dbg info.
4265 /// @return @ref GE_Result
4266 //-------------------------------------------------------------------------------------------------
MDrv_GE_GetInfo(GE_Context * pGECtx,GE_DbgInfo * dbg)4267 GE_Result MDrv_GE_GetInfo(GE_Context *pGECtx, GE_DbgInfo* dbg)
4268 {
4269 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4270
4271 MS_U32 i = 0;
4272 MS_U16 semid;
4273 GE_ENTRY(pGECtx);
4274
4275 for(i =0;i<0x80;i++ )
4276 {
4277 if(GE_Map_Share_Reg(&pGECtxLocal->halLocalCtx,i)== E_GE_OK)
4278 dbg->gedump[i] = pGECtxLocal->halLocalCtx.pHALShared->u16ShareRegImage[i];
4279 else
4280 dbg->gedump[i] = pGECtxLocal->halLocalCtx.u16RegGETable[i];
4281 }
4282 #if GE_LOCK_SUPPORT
4283 semid = 0;
4284 #else
4285 MDrv_SEM_Get_ResourceID(GESEMID, &semid );
4286 #endif
4287 dbg->semstaus = semid;
4288 GE_RETURN(pGECtx,E_GE_OK);
4289
4290
4291 }
4292
4293 #ifdef CONFIG_UTOPIA_PROC_DBG_SUPPORT
MDrv_GE_GetGFXMdbInfo(GE_Context * pGECtx,MS_U64 * u64ReqHdl)4294 GE_Result MDrv_GE_GetGFXMdbInfo(GE_Context *pGECtx, MS_U64 *u64ReqHdl)
4295 {
4296 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4297 MS_U64 u64MiuSize = 0;
4298 MS_U16 i = 0;
4299 MS_U16 u16TmpReg = 0;
4300 MS_U16 u16REG_GE_EN = 0;
4301 MS_U16 u16REG_GE_CFG = 0;
4302 MS_U16 u16REG_GE_YUV_MODE = 0;
4303 MS_U16 u16REG_GE_VCMDQ_BASE_H = 0;
4304 MS_U16 u16REG_GE_VCMDQ_BASE_L = 0;
4305 MS_U16 u16REG_GE_VCMDQ_SIZE = 0;
4306 MS_U16 u16REG_GE_SRC_BASE_H = 0;
4307 MS_U16 u16REG_GE_SRC_BASE_L = 0;
4308 MS_U16 u16REG_GE_DST_BASE_H = 0;
4309 MS_U16 u16REG_GE_DST_BASE_L = 0;
4310
4311
4312 GE_ENTRY(pGECtx);
4313
4314 u16REG_GE_EN = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_EN + GE_TABLE_REGNUM);
4315 u16REG_GE_CFG = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_CFG + GE_TABLE_REGNUM);
4316 u16REG_GE_YUV_MODE =GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_YUV_MODE + GE_TABLE_REGNUM);
4317 u16REG_GE_VCMDQ_BASE_H = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_VCMDQ_BASE_H + GE_TABLE_REGNUM);
4318 u16REG_GE_VCMDQ_BASE_L = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_VCMDQ_BASE_L + GE_TABLE_REGNUM);
4319 u16REG_GE_VCMDQ_SIZE = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_VCMDQ_SIZE + GE_TABLE_REGNUM);
4320 u16REG_GE_SRC_BASE_H = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_SRC_BASE_H + GE_TABLE_REGNUM);
4321 u16REG_GE_SRC_BASE_L = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_SRC_BASE_L + GE_TABLE_REGNUM);
4322 u16REG_GE_DST_BASE_H = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_DST_BASE_H + GE_TABLE_REGNUM);
4323 u16REG_GE_DST_BASE_L = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_DST_BASE_L + GE_TABLE_REGNUM);
4324
4325 u64MiuSize = (1 << (9 + (u16REG_GE_VCMDQ_SIZE & GE_VCMDQ_SIZE_MASK))) * GE_WordUnit;
4326 u64MiuSize = (u64MiuSize >> 10);
4327
4328 MdbPrint(u64ReqHdl,"---------MStar GE Info---------\n\n");
4329 if(u16REG_GE_EN & GE_EN_GE)
4330 {
4331 MdbPrint(u64ReqHdl,"GE Init : True\n");
4332 }
4333 else
4334 {
4335 MdbPrint(u64ReqHdl,"GE Init : False\n");
4336 }
4337 if(u16REG_GE_EN & GE_EN_BURST)
4338 {
4339 MdbPrint(u64ReqHdl,"Burst Mode : Enable\n");
4340 }
4341 else
4342 {
4343 MdbPrint(u64ReqHdl,"Burst Mode : Disable\n");
4344 }
4345 if(u16REG_GE_CFG & GE_CFG_RW_SPLIT)
4346 {
4347 MdbPrint(u64ReqHdl,"Split Mode : Enable\n");
4348 }
4349 else
4350 {
4351 MdbPrint(u64ReqHdl,"Split Mode : Disable\n");
4352 }
4353 if(u16REG_GE_CFG & GE_CFG_CMDQ)
4354 {
4355 MdbPrint(u64ReqHdl,"Command Queue : Enable\n");
4356 }
4357 else
4358 {
4359 MdbPrint(u64ReqHdl,"Command Queue : Disable\n");
4360 }
4361 if(u16REG_GE_CFG & GE_CFG_VCMDQ)
4362 {
4363 MdbPrint(u64ReqHdl,"Virtual Command Queue : Enable\n");
4364 }
4365 else
4366 {
4367 MdbPrint(u64ReqHdl,"Virtual Command Queue : Disable\n");
4368 }
4369 MdbPrint(u64ReqHdl,"VCMDQ MIU : %d\n",((u16REG_GE_YUV_MODE & BIT(15)) >> 14) | ((u16REG_GE_VCMDQ_BASE_H & BIT(15)) >> 15));
4370 MdbPrint(u64ReqHdl,"VCMDQ Address : 0x%lx\n",(u16REG_GE_VCMDQ_BASE_H<<16) | u16REG_GE_VCMDQ_BASE_L);
4371 MdbPrint(u64ReqHdl,"VCMDQ Size : %d K\n",u64MiuSize);
4372 MdbPrint(u64ReqHdl,"Source MIU : %d\n",((u16REG_GE_YUV_MODE & BIT(14)) >> 13) | ((u16REG_GE_SRC_BASE_H & BIT(14)) >> 14));
4373 MdbPrint(u64ReqHdl,"Source Address : 0x%lx\n",(u16REG_GE_SRC_BASE_H<<16) | u16REG_GE_SRC_BASE_L);
4374 MdbPrint(u64ReqHdl,"Destination MIU : %d\n",((u16REG_GE_YUV_MODE & BIT(13)) >> 12) | ((u16REG_GE_DST_BASE_H & BIT(13)) >> 13));
4375 MdbPrint(u64ReqHdl,"Destination Address : 0x%lx\n",(u16REG_GE_DST_BASE_H<<16) | u16REG_GE_DST_BASE_L);
4376
4377
4378 MdbPrint(u64ReqHdl,"\nDump GE register:\n");
4379 for (i = 0; i < 0x80; i++)
4380 {
4381 u16TmpReg = GE_ReadReg(&pGECtxLocal->halLocalCtx, i + GE_TABLE_REGNUM);
4382 if(i % 0x08 == 0)
4383 {
4384 MdbPrint(u64ReqHdl," \n");
4385 MdbPrint(u64ReqHdl,"h%x", (MS_U8)(i & 0xf0) >> 4);
4386 MdbPrint(u64ReqHdl,"%x ", (MS_U8)(i & 0xf));
4387 }
4388 MdbPrint(u64ReqHdl,"%x", (u16TmpReg & 0xf000) >> 12);
4389 MdbPrint(u64ReqHdl,"%x", (u16TmpReg & 0xf00) >> 8);
4390 MdbPrint(u64ReqHdl,"%x", (u16TmpReg & 0xf0) >> 4);
4391 MdbPrint(u64ReqHdl,"%x ", (u16TmpReg & 0xf));
4392 }
4393 MdbPrint(u64ReqHdl," \n");
4394
4395 GE_RETURN(pGECtx,E_GE_OK);
4396 }
4397 #endif
4398
4399 //-------------------------------------------------------------------------------------------------
4400 /// Get GE internal information
4401 /// @param pGECtx \b IN: GE context
4402 /// @param bstatus \b OUT: Pointer to GE internal status
4403 /// @return @ref GE_Result
4404 //-------------------------------------------------------------------------------------------------
MDrv_GE_GetStatus(GE_Context * pGECtx,MS_BOOL * bstatus)4405 GE_Result MDrv_GE_GetStatus(GE_Context *pGECtx, MS_BOOL* bstatus)
4406 {
4407 GE_ENTRY(pGECtx);
4408
4409 *bstatus = TRUE;
4410
4411 GE_RETURN(pGECtx,E_GE_OK);
4412 }
4413
4414
4415 //-------------------------------------------------------------------------------------------------
4416 ///Enable GE Virtual Command Queue
4417 /// @param pGECtx \b IN: GE context
4418 /// @param blEnable \b IN: true: Enable, false: Disable
4419 /// @return @ref GE_Result
4420 //-------------------------------------------------------------------------------------------------
MDrv_GE_EnableVCmdQueue(GE_Context * pGECtx,MS_U16 blEnable)4421 GE_Result MDrv_GE_EnableVCmdQueue(GE_Context *pGECtx, MS_U16 blEnable)
4422 {
4423 MS_U16 u16tmp;
4424 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4425
4426 GE_ENTRY(pGECtx);
4427
4428 GE_WaitIdle(&pGECtxLocal->halLocalCtx);
4429
4430 u16tmp = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_CFG);
4431
4432 if (blEnable)
4433 {
4434 u16tmp |= GE_CFG_VCMDQ;
4435 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CFG, u16tmp);
4436 }
4437 else
4438 {
4439 u16tmp &= ~GE_CFG_VCMDQ;
4440 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_CFG, u16tmp);
4441 }
4442
4443
4444 GE_RETURN(pGECtx,E_GE_OK);
4445 }
4446
4447
4448 //-------------------------------------------------------------------------------------------------
4449 ///Set GE Virtual Command Queue spec
4450 /// @param pGECtx \b IN: GE context
4451 /// @param u32Addr \b IN: Start address of VCMQ buffer.
4452 /// @param enBufSize \b IN: Size of VCMQ buffer.
4453 /// @return @ref GE_Result
4454 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetVCmdBuffer(GE_Context * pGECtx,MS_PHY PhyAddr,GE_VcmqBufSize enBufSize)4455 GE_Result MDrv_GE_SetVCmdBuffer(GE_Context *pGECtx, MS_PHY PhyAddr, GE_VcmqBufSize enBufSize)
4456 {
4457 GE_Result ret;
4458 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4459
4460 GE_ENTRY(pGECtx);
4461
4462 GE_WaitIdle(&pGECtxLocal->halLocalCtx);
4463
4464 ret = GE_SetVCmdBuffer(&pGECtxLocal->halLocalCtx, PhyAddr, enBufSize);
4465
4466 GE_RETURN(pGECtx,ret);
4467 }
4468
4469
4470 //-------------------------------------------------------------------------------------------------
4471 ///Set GE Virtual Command Write threshold
4472 /// @param pGECtx \b IN: GE context
4473 /// @param u8W_Threshold \b IN: Threshold for VCMQ write.
4474 /// @return @ref GE_Result
4475 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetVCmd_W_Thread(GE_Context * pGECtx,MS_U8 u8W_Threshold)4476 GE_Result MDrv_GE_SetVCmd_W_Thread(GE_Context *pGECtx, MS_U8 u8W_Threshold)
4477 {
4478 MS_U16 u16tmp;
4479 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4480
4481 GE_ENTRY(pGECtx);
4482
4483 GE_WaitIdle(&pGECtxLocal->halLocalCtx);
4484
4485 u16tmp = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_TH);
4486
4487 u16tmp &= ~(GE_TH_CMDQ_MASK);
4488 u16tmp |= u8W_Threshold << 4;
4489
4490 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_TH, u16tmp);
4491
4492 GE_RETURN(pGECtx,E_GE_OK);
4493 }
4494
4495
4496 //-------------------------------------------------------------------------------------------------
4497 ///Set GE Virtual Command Read threshold
4498 /// @param pGECtx \b IN: GE context
4499 /// @param u8R_Threshold \b IN: Threshold for VCMQ read.
4500 /// @return @ref GE_Result
4501 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetVCmd_R_Thread(GE_Context * pGECtx,MS_U8 u8R_Threshold)4502 GE_Result MDrv_GE_SetVCmd_R_Thread(GE_Context *pGECtx, MS_U8 u8R_Threshold)
4503 {
4504 MS_U16 u16tmp;
4505 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4506
4507 GE_ENTRY(pGECtx);
4508
4509 GE_WaitIdle(&pGECtxLocal->halLocalCtx);
4510
4511 u16tmp = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_TH);
4512
4513 u16tmp &= ~(GE_TH_CMDQ2_MASK);
4514 u16tmp |= u8R_Threshold << 8;
4515
4516 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_TH, u16tmp);
4517
4518 GE_RETURN(pGECtx,E_GE_OK);
4519 }
4520
4521
4522 ////////////////////////////////////////////////////////////////////////////////
4523 /// @brief \b Function \b Name: MDrv_GE_GetLibVer
4524 /// @brief \b Function \b Description: Show the GE driver version
4525 /// @param pGECtx \b IN: GE context
4526 /// @param ppVersion \b OUT: Pointer to version string.
4527 /// @return @ref GE_Result
4528 ////////////////////////////////////////////////////////////////////////////////
MDrv_GE_GetLibVer(GE_Context * pGECtx,const MSIF_Version ** ppVersion)4529 GE_Result MDrv_GE_GetLibVer(GE_Context *pGECtx, const MSIF_Version **ppVersion)
4530 {
4531 // No mutex check, it can be called before Init
4532 if (!ppVersion)
4533 {
4534 return E_GE_FAIL;
4535 }
4536
4537 *ppVersion = &_drv_ge_version;
4538
4539 return E_GE_OK;
4540 }
4541
4542 ////////////////////////////////////////////////////////////////////////////////
4543 /// Configure GE SCK edge refine rtpe.
4544 /// @param pGECtx \b IN: GE context
4545 /// @param TYPE \b IN: Type for edge refine.
4546 /// @param CLR \b IN: 32-bit custom color if type is E_GE_REPLACE_KEY_2_CUS
4547 /// @return @ref GE_Result
4548 ///////////////////////////////////////////////////////////////////////////////
MDrv_GE_SetStrBltSckType(GE_Context * pGECtx,GE_StretchCKType TYPE,MS_U32 * CLR)4549 GE_Result MDrv_GE_SetStrBltSckType(GE_Context *pGECtx,GE_StretchCKType TYPE, MS_U32 *CLR)
4550 {
4551 MS_U16 u16tmp;
4552 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4553
4554 GE_ENTRY(pGECtx);
4555
4556 GE_WaitIdle(&pGECtxLocal->halLocalCtx);
4557
4558 u16tmp = GE_ReadReg(&pGECtxLocal->halLocalCtx,REG_GE_BLT_SCK_MODE);
4559
4560 u16tmp &= ~(GE_BLT_SCK_MODE_MASK);
4561
4562 switch(TYPE)
4563 {
4564 case E_GE_DONOTHING:
4565 u16tmp |=GE_BLT_SCK_BILINEAR;
4566 break;
4567
4568 case E_GE_NEAREST:
4569 u16tmp |=GE_BLT_SCK_NEAREST;
4570 break;
4571
4572 case E_GE_REPLACE_KEY_2_CUS:
4573 u16tmp |=GE_BLT_SCK_CONST;
4574 break;
4575 default:
4576 GE_D_DBUG("[%s] ERROR Stretch Type\n",__FUNCTION__);
4577 break;
4578 }
4579
4580 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_BLT_SCK_CONST_L, (*CLR)&0xffff);
4581 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_BLT_SCK_CONST_H, (*CLR)>>16);
4582 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_BLT_SCK_MODE, u16tmp);
4583
4584 GE_RETURN(pGECtx,E_GE_OK);
4585 }
4586
4587
4588
4589 ////////////////////////////////////////////////////////////////////////////////
4590 /// Get if GE is running as HK.
4591 /// The semaphore allocated by GE differs in HK and non-HK mode.
4592 /// @param pGECtx \b IN: GE context
4593 /// @param bIsHK \b OUT: true => running as HK, false => running as co-processor.
4594 /// @return @ref GE_Result
4595 ///////////////////////////////////////////////////////////////////////////////
MDrv_GE_Get_GetHK(GE_Context * pGECtx,MS_BOOL * bIsHK)4596 GE_Result MDrv_GE_Get_GetHK(GE_Context *pGECtx, MS_BOOL *bIsHK)
4597 {
4598 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4599
4600 GE_ENTRY(pGECtx);
4601
4602 if( SEM_HKAeonID == pGECtxLocal->u32GESEMID)
4603 *bIsHK = TRUE;
4604 else
4605 *bIsHK = FALSE;
4606
4607 GE_RETURN(pGECtx,E_GE_OK);
4608
4609 }
4610
4611 ////////////////////////////////////////////////////////////////////////////////
4612 /// Configure GE for running as HK or not.
4613 /// The semaphore allocated by GE differs in HK and non-HK mode.
4614 /// @param pGECtx \b IN: GE context
4615 /// @param bIsHK \b OUT: true => running as HK, false => running as co-processor.
4616 /// @return @ref GE_Result
4617 ///////////////////////////////////////////////////////////////////////////////
MDrv_GE_Set_SetHK(GE_Context * pGECtx,MS_BOOL bIsHK)4618 GE_Result MDrv_GE_Set_SetHK(GE_Context *pGECtx, MS_BOOL bIsHK)
4619 {
4620 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4621
4622 if(bIsHK)
4623 pGECtxLocal->u32GESEMID = SEM_HKAeonID;
4624 else
4625 pGECtxLocal->u32GESEMID = SEM_MWMipsID;
4626
4627 GE_ENTRY(pGECtx);
4628 GE_RETURN(pGECtx,E_GE_OK);
4629
4630 }
4631
4632
4633
4634 ////////////////////////////////////////////////////////////////////////////////
4635 /// Draw Oval. Oval is not directly supported by HW. Software implemented by DrawLine.
4636 /// @param pGECtx \b IN: GE context
4637 /// @param pOval \b IN: oval info
4638 /// @return @ref GE_Result
4639 ///////////////////////////////////////////////////////////////////////////////
MDrv_GE_DrawOval(GE_Context * pGECtx,GE_OVAL_FILL_INFO * pOval)4640 GE_Result MDrv_GE_DrawOval(GE_Context *pGECtx, GE_OVAL_FILL_INFO* pOval)
4641 {
4642 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4643
4644 GE_ENTRY(pGECtx);
4645
4646 MS_S32 x, y, c_x, c_y;
4647 MS_S32 Xchange, Ychange;
4648 MS_S32 EllipseError;
4649 MS_S32 TwoASquare, TwoBSquare;
4650 MS_S32 StoppingX, StoppingY;
4651 MS_U32 Xradius, Yradius;
4652
4653 MS_U16 u16Color0, u16Color1;
4654 MS_BOOL bDstXInv = FALSE;
4655
4656 GE_Restore_PaletteContext(pGECtxLocal);
4657
4658 Xradius = (pOval->dstBlock.width >> 1) - pOval->u32LineWidth;
4659 Yradius = (pOval->dstBlock.height >> 1) - pOval->u32LineWidth;
4660
4661 /* center of ellipse */
4662 c_x = pOval->dstBlock.x + Xradius + pOval->u32LineWidth;
4663 c_y = pOval->dstBlock.y + Yradius + pOval->u32LineWidth;
4664
4665 TwoASquare = (Xradius*Xradius) << 1;
4666 TwoBSquare = (Yradius*Yradius) << 1;
4667
4668 /*1st set of points*/
4669 x = Xradius-1; /*radius zero == draw nothing*/
4670 y = 0;
4671
4672 StoppingX = TwoBSquare*Xradius;
4673 StoppingY = 0;
4674
4675 Xchange = (TwoBSquare >> 1) - StoppingX;
4676 Ychange = TwoASquare >> 1;
4677
4678 EllipseError = 0;
4679
4680 #if 1//(SUPPORT_LINE_LAST_PATCH == 1 )
4681 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_LINE_STYLE, GE_LINEPAT_RST | 0x3f);
4682 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_LINE_STYLE, 0x3f);
4683 #else
4684 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_LINE_STYLE, GE_LINE_LAST | GE_LINEPAT_RST | 0x3f);
4685 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_LINE_STYLE, GE_LINE_LAST | 0x3f);
4686 #endif
4687
4688 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_LINE_DELTA, 0);
4689
4690 u16Color0 = (((MS_U16)(pOval->color.g)) << 8)+ (MS_U16)pOval->color.b;
4691 u16Color1 = (((MS_U16)(pOval->color.a)) << 8)+ (MS_U16)pOval->color.r;
4692
4693 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_C_L, u16Color0);
4694 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_C_H, u16Color1);
4695
4696 /*Plot 2 ellipse scan lines for iteration*/
4697 while (StoppingX > StoppingY)
4698 {
4699 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V0_X, c_x - x);
4700 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V1_X, c_x + x);
4701 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V0_Y, c_y + y);
4702 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V1_Y, c_y + y + 1);
4703 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_LINE_LENGTH, (x << 1) + 1);
4704 HAL_GE_AdjustDstWin(&pGECtxLocal->halLocalCtx,bDstXInv);
4705 #ifdef GE_VQ_MIU_HANG_PATCH
4706 if ((GE_IsVcmdqEnabled(pGECtx) == TRUE) &&
4707 (u8DstMIU != pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu)
4708 )
4709 {
4710 //printf("\33[0;36m %s:%d u8VCmdQMiu = %d u8SrcMIU = %d u8DstMIU = %d\33[m \n",__FUNCTION__,__LINE__,pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu,u8SrcMIU,u8DstMIU);
4711 MDrv_GE_WaitIdle(pGECtx);
4712 }
4713 #endif
4714 _GE_SEMAPHORE_ENTRY(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
4715 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_CMD, GE_PRIM_LINE);
4716 _GE_SEMAPHORE_RETURN(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
4717
4718 #ifdef GE_VQ_MIU_HANG_PATCH
4719 if ((GE_IsVcmdqEnabled(pGECtx) == TRUE) &&
4720 (u8DstMIU != pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu)
4721 )
4722 {
4723 //printf("\33[0;36m %s:%d u8VCmdQMiu = %d u8SrcMIU = %d u8DstMIU = %d\33[m \n",__FUNCTION__,__LINE__,pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu,u8SrcMIU,u8DstMIU);
4724 MDrv_GE_WaitIdle(pGECtx);
4725 }
4726 #endif
4727
4728 //GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V0_X, c_x - x);
4729 //GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V1_X, c_x + x);
4730 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V0_Y, c_y - y);
4731 #if 1 //(SUPPORT_LINE_LAST_PATCH == 1 )
4732 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V1_Y, c_y - y + 1);
4733 //GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_LINE_LENGTH, 2*x + 1);
4734 #else
4735 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V1_Y, c_y - y );
4736 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_LINE_LENGTH, 2*x );
4737 #endif
4738 HAL_GE_AdjustDstWin(&pGECtxLocal->halLocalCtx,bDstXInv);
4739 #ifdef GE_VQ_MIU_HANG_PATCH
4740 if ((GE_IsVcmdqEnabled(pGECtx) == TRUE) &&
4741 (u8DstMIU != pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu)
4742 )
4743 {
4744 //printf("\33[0;36m %s:%d u8VCmdQMiu = %d u8SrcMIU = %d u8DstMIU = %d\33[m \n",__FUNCTION__,__LINE__,pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu,u8SrcMIU,u8DstMIU);
4745 MDrv_GE_WaitIdle(pGECtx);
4746 }
4747 #endif
4748 _GE_SEMAPHORE_ENTRY(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
4749 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_CMD, GE_PRIM_LINE);
4750 _GE_SEMAPHORE_RETURN(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
4751
4752 #ifdef GE_VQ_MIU_HANG_PATCH
4753 if ((GE_IsVcmdqEnabled(pGECtx) == TRUE) &&
4754 (u8DstMIU != pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu)
4755 )
4756 {
4757 //printf("\33[0;36m %s:%d u8VCmdQMiu = %d u8SrcMIU = %d u8DstMIU = %d\33[m \n",__FUNCTION__,__LINE__,pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu,u8SrcMIU,u8DstMIU);
4758 MDrv_GE_WaitIdle(pGECtx);
4759 }
4760 #endif
4761
4762 ++y;
4763 StoppingY += TwoASquare;
4764 EllipseError += Ychange;
4765 Ychange += TwoASquare;
4766 if (( (EllipseError << 1) + Xchange) > 0)
4767 {
4768 --x;
4769 StoppingX -= TwoBSquare;
4770 EllipseError += Xchange;
4771 Xchange += TwoBSquare;
4772 }
4773 }
4774
4775 /*2nd set of points*/
4776 x = 0;
4777 y = Yradius-1; /*radius zero == draw nothing*/
4778 StoppingX = 0;
4779 StoppingY = TwoASquare*Yradius;
4780 Xchange = TwoBSquare >> 1;
4781 Ychange = (TwoASquare >> 1) - StoppingY;
4782 EllipseError = 0;
4783
4784 /*Plot 2 ellipse scan lines for iteration*/
4785 while (StoppingX < StoppingY)
4786 {
4787 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V0_X, c_x - x);
4788 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V1_X, c_x + x);
4789 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V0_Y, c_y + y);
4790 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V1_Y, c_y + y + 1);
4791 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_LINE_LENGTH, (x << 1) + 1);
4792 // GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_CMD, GE_PRIM_LINE|_u32Reg60hFlag);
4793 HAL_GE_AdjustDstWin(&pGECtxLocal->halLocalCtx,bDstXInv);
4794 #ifdef GE_VQ_MIU_HANG_PATCH
4795 if ((GE_IsVcmdqEnabled(pGECtx) == TRUE) &&
4796 (u8DstMIU != pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu)
4797 )
4798 {
4799 //printf("\33[0;36m %s:%d u8VCmdQMiu = %d u8SrcMIU = %d u8DstMIU = %d\33[m \n",__FUNCTION__,__LINE__,pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu,u8SrcMIU,u8DstMIU);
4800 MDrv_GE_WaitIdle(pGECtx);
4801 }
4802 #endif
4803 _GE_SEMAPHORE_ENTRY(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
4804 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_CMD, GE_PRIM_LINE);
4805 _GE_SEMAPHORE_RETURN(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
4806
4807 #ifdef GE_VQ_MIU_HANG_PATCH
4808 if ((GE_IsVcmdqEnabled(pGECtx) == TRUE) &&
4809 (u8DstMIU != pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu)
4810 )
4811 {
4812 //printf("\33[0;36m %s:%d u8VCmdQMiu = %d u8SrcMIU = %d u8DstMIU = %d\33[m \n",__FUNCTION__,__LINE__,pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu,u8SrcMIU,u8DstMIU);
4813 MDrv_GE_WaitIdle(pGECtx);
4814 }
4815 #endif
4816
4817 //GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V0_X, c_x - x);
4818 //GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V1_X, c_x + x);
4819 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V0_Y, c_y - y);
4820 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V1_Y, c_y - y + 1);
4821 //GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_LINE_LENGTH, 2*x + 1);
4822 // GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_CMD, GE_PRIM_LINE|_u32Reg60hFlag);
4823 HAL_GE_AdjustDstWin(&pGECtxLocal->halLocalCtx,bDstXInv);
4824 #ifdef GE_VQ_MIU_HANG_PATCH
4825 if ((GE_IsVcmdqEnabled(pGECtx) == TRUE) &&
4826 (u8DstMIU != pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu)
4827 )
4828 {
4829 //printf("\33[0;36m %s:%d u8VCmdQMiu = %d u8SrcMIU = %d u8DstMIU = %d\33[m \n",__FUNCTION__,__LINE__,pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu,u8SrcMIU,u8DstMIU);
4830 MDrv_GE_WaitIdle(pGECtx);
4831 }
4832 #endif
4833 _GE_SEMAPHORE_ENTRY(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
4834 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_CMD, GE_PRIM_LINE);
4835 _GE_SEMAPHORE_RETURN(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
4836
4837 #ifdef GE_VQ_MIU_HANG_PATCH
4838 if ((GE_IsVcmdqEnabled(pGECtx) == TRUE) &&
4839 (u8DstMIU != pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu)
4840 )
4841 {
4842 //printf("\33[0;36m %s:%d u8VCmdQMiu = %d u8SrcMIU = %d u8DstMIU = %d\33[m \n",__FUNCTION__,__LINE__,pGECtxLocal->halLocalCtx.pHALShared->u8VCmdQMiu,u8SrcMIU,u8DstMIU);
4843 MDrv_GE_WaitIdle(pGECtx);
4844 }
4845 #endif
4846
4847 ++x;
4848 StoppingX += TwoBSquare;
4849 EllipseError += Xchange;
4850 Xchange += TwoBSquare;
4851 if (((EllipseError << 1) + Ychange) > 0)
4852 {
4853 --y;
4854 StoppingY -= TwoASquare;
4855 EllipseError += Ychange;
4856 Ychange += TwoASquare;
4857 }
4858 }
4859
4860 GE_RETURN(pGECtx,E_GE_OK);
4861 }
4862
4863 ////////////////////////////////////////////////////////////////////////////////
4864 /// Power State Setting
4865 /// @param pGECtx \b IN: GE context
4866 /// @param u16PowerState \b IN: Power State
4867 /// @return @ref GE_Result
4868 ///////////////////////////////////////////////////////////////////////////////
4869 #if defined(MSOS_TYPE_LINUX_KERNEL)
4870 #define STR_RIU_MAP str_va_mmio_base
4871 #define STR_RIU ((unsigned short volatile *) STR_RIU_MAP)
4872 #define STR_GE_REG(addr) STR_RIU[ ((addr*2) + 0x2800UL)]
4873 #define STR_GETLB_REG(addr) STR_RIU[ ((addr*2) + 0x62800UL)]
4874 #define STR_CLK_REG(addr) STR_RIU[ ((addr*2) + 0x0B00UL)]
4875 #define STR_GE_CMDQ_FREECNT() ((STR_GE_REG(REG_GE_STAT)&GE_STAT_CMDQ_MASK)>>GE_STAT_CMDQ_SHFT)
4876
4877 MS_VIRT str_va_mmio_base;
4878
MDrv_GESTR_DumpReg(void)4879 static void MDrv_GESTR_DumpReg(void)
4880 {
4881 MS_U32 i;
4882
4883 printk("Dump GE register:\n");
4884 for (i = 0; i < 0x80; i++)
4885 {
4886 if(i % 0x08 == 0) {
4887 printk(" \n");
4888 printk("h%02x ", (MS_U8)i );
4889 }
4890 printk("%04x ", STR_GE_REG(i) );
4891 }
4892 printk(" \n");
4893 }
4894
MDrv_GESTR_WaitIdle(void)4895 MS_U32 MDrv_GESTR_WaitIdle(void)
4896 {
4897 MS_U32 waitcount = 0;
4898
4899 // Wait level-2 command queue flush
4900 while (((STR_GE_REG(REG_GE_STAT)&GE_STAT_CMDQ2_MASK)>>GE_STAT_CMDQ2_SHFT) != GE_STAT_CMDQ2_MAX)
4901 {
4902 if (waitcount >= 1000)
4903 {
4904 printk("[GE] Wait Idle: %tx\n",(ptrdiff_t)STR_GE_CMDQ_FREECNT());
4905 waitcount = 0;
4906 MDrv_GESTR_DumpReg();
4907 break;
4908 }
4909 waitcount++;
4910 MsOS_DelayTask(1);
4911 }
4912
4913 waitcount = 0;
4914 // Wait GE idle
4915 while (STR_GE_REG(REG_GE_STAT) & GE_STAT_BUSY)
4916 {
4917 if (waitcount >= 1000)
4918 {
4919 printk("[GE] Wait Busy: %tx\n",(ptrdiff_t)STR_GE_CMDQ_FREECNT());
4920 waitcount = 0;
4921 MDrv_GESTR_DumpReg();
4922 }
4923 waitcount++;
4924 MsOS_DelayTask(1);
4925 }
4926 return 0;
4927 }
4928
MDrv_GESTR_SetPalette(MS_U32 * GEPalette)4929 MS_U32 MDrv_GESTR_SetPalette(MS_U32 *GEPalette)
4930 {
4931 int i;
4932
4933 for(i=0; i<GE_PALETTE_NUM; i++)
4934 {
4935 STR_GE_REG(REG_GE_CLUT_H) = (ByteSwap16(GEPalette[i]) & 0xFFFF);
4936 STR_GE_REG(REG_GE_CLUT_L) = (ByteSwap16(GEPalette[i]>>16));
4937 STR_GE_REG(REG_GE_CLUT_CTRL) = ((i & GE_CLUT_CTRL_IDX_MASK) | GE_CLUT_CTRL_WR);
4938 }
4939 return 0;
4940 }
4941
4942 #endif
4943
MDrv_GE_SetPowerState(GE_Context * pGECtx,EN_POWER_MODE u16PowerState,void * pModule)4944 GE_Result MDrv_GE_SetPowerState(GE_Context *pGECtx, EN_POWER_MODE u16PowerState, void* pModule)
4945 {
4946 GE_Config cfg;
4947 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
4948
4949 memset(&cfg, 0 , sizeof(GE_Config));
4950 switch(u16PowerState)
4951 {
4952 case E_POWER_SUSPEND:
4953 pGECtxLocal->PhyVcmdqAddr = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_VCMDQ_BASE_L);
4954 pGECtxLocal->PhyVcmdqAddr |= GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_VCMDQ_BASE_H)<<16;
4955 pGECtxLocal->u16VcmdqMiuMsb = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_YUV_MODE);
4956 pGECtxLocal->u16VcmdqSize = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_VCMDQ_SIZE);
4957 break;
4958 case E_POWER_RESUME:
4959 GE_Init(&pGECtxLocal->halLocalCtx, &cfg);
4960 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_VCMDQ_BASE_L, pGECtxLocal->PhyVcmdqAddr & 0xffff);
4961 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_VCMDQ_BASE_H, pGECtxLocal->PhyVcmdqAddr >>16);
4962 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_YUV_MODE, pGECtxLocal->u16VcmdqMiuMsb);
4963 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_VCMDQ_SIZE, pGECtxLocal->u16VcmdqSize);
4964 //Init GE Palette from HW:
4965 GE_InitCtxHalPalette(&pGECtxLocal->halLocalCtx);
4966 if (bNeedSetActiveCtrlMiu1)
4967 GE_SetActiveCtrlMiu1(&pGECtxLocal->halLocalCtx);
4968 break;
4969 default:
4970 break;
4971 }
4972 return E_GE_OK;
4973 }
4974
MDrv_GE_STR_SetPowerState(EN_POWER_MODE u16PowerState,void * pModule)4975 GE_Result MDrv_GE_STR_SetPowerState(EN_POWER_MODE u16PowerState, void* pModule)
4976 {
4977 #if defined(MSOS_TYPE_LINUX_KERNEL)
4978 MS_U8 i=0UL;
4979 MS_VIRT u32MMIOBaseAdr=0xFFFF;
4980 MS_PHY u32NonPMBankSize=0xFFFF;
4981
4982 GE_STR_SAVE_AREA* pGFX_STRPrivate=NULL;
4983 UtopiaModuleGetSTRPrivate(pModule, (void**)&pGFX_STRPrivate);
4984 if( !MDrv_MMIO_GetBASE(&str_va_mmio_base, &u32NonPMBankSize, MS_MODULE_GE))
4985 {
4986 MS_CRITICAL_MSG(printf("Get GE IOMap failure\n"));
4987 MS_ASSERT(0);
4988 return FALSE;
4989 }
4990
4991 switch(u16PowerState)
4992 {
4993 case E_POWER_SUSPEND:
4994 {
4995 //wait idle
4996 MDrv_GESTR_WaitIdle();
4997 //store reg
4998 for(i =0;i<GE_TABLE_REGNUM;i++ )
4999 {
5000 pGFX_STRPrivate->GE0_Reg[i] = STR_GE_REG(i);
5001 pGFX_STRPrivate->GETLB_Reg[i] = STR_GETLB_REG(i);
5002 }
5003 //disable power
5004 pGFX_STRPrivate->GECLK_Reg = STR_CLK_REG(CHIP_GE_CLK);
5005 }
5006 break;
5007 case E_POWER_RESUME:
5008 {
5009 //enable power
5010 STR_CLK_REG(CHIP_GE_CLK) = pGFX_STRPrivate->GECLK_Reg;
5011 //resume palette
5012 MDrv_GESTR_SetPalette(pGFX_STRPrivate->GEPalette);
5013 for(i=0;i<GE_TABLE_REGNUM; i++)
5014 {
5015 //resume reg
5016 STR_GETLB_REG(i) = pGFX_STRPrivate->GETLB_Reg[i];
5017 if(i == REG_GE_CMD )
5018 continue;
5019 STR_GE_REG(i) = pGFX_STRPrivate->GE0_Reg[i];
5020
5021 }
5022 }
5023 break;
5024 default:
5025 break;
5026 }
5027 #endif
5028 return E_GE_OK;
5029 }
5030 //-------------------------------------------------------------------------------------------------
5031 ///Set GE Clock
5032 /// @param pGECtx \b IN: GE context
5033 /// @param bEnable \b IN: Enable GE clock or not.
5034 /// @return @ref GE_Result
5035 //-------------------------------------------------------------------------------------------------
MDrv_GE_SetClock(GE_Context * pGECtx,MS_BOOL bEnable)5036 GE_Result MDrv_GE_SetClock(GE_Context *pGECtx, MS_BOOL bEnable)
5037 {
5038 MS_U16 u16tmp = 0;
5039 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
5040
5041 GE_ENTRY(pGECtx);
5042
5043 GE_WaitIdle(&pGECtxLocal->halLocalCtx);
5044
5045 if (bEnable)
5046 {
5047 GE_SetClock(&pGECtxLocal->halLocalCtx, TRUE);
5048 u16tmp = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_EN);
5049 u16tmp |= GE_EN_GE;
5050 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, u16tmp);
5051 }
5052 else
5053 {
5054 u16tmp = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_EN);
5055 u16tmp &= ~GE_EN_GE;
5056 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, u16tmp);
5057 GE_SetClock(&pGECtxLocal->halLocalCtx, FALSE);
5058 }
5059
5060 GE_RETURN(pGECtx,E_GE_OK);
5061 }
_GE_TextOutPatch(GE_Context * pGECtx)5062 MS_BOOL _GE_TextOutPatch(GE_Context *pGECtx)
5063 {
5064 GE_ENTRY(pGECtx);
5065 #ifdef GE_TEXTOUT_BLEND_PATCH
5066 GE_RETURN(pGECtx,TRUE);
5067 #else
5068 GE_RETURN(pGECtx,FALSE);
5069 #endif
5070 }
5071
MDrv_GE_SetTLBMode(GE_Context * pGECtx,GE_TLB_Mode tlb_type)5072 GE_Result MDrv_GE_SetTLBMode(GE_Context *pGECtx, GE_TLB_Mode tlb_type)
5073 {
5074 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
5075
5076 GE_ENTRY(pGECtx);
5077
5078 GE_SetTLBMode(&pGECtxLocal->halLocalCtx, tlb_type);
5079 GE_RETURN(pGECtx,E_GE_OK);
5080 }
5081
MDrv_GE_GetTLBSRCADDR(GE_Context * pGECtx,MS_PHY * addr)5082 GE_Result MDrv_GE_GetTLBSRCADDR(GE_Context *pGECtx, MS_PHY* addr)
5083 {
5084 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
5085
5086 GE_ENTRY(pGECtx);
5087 GE_GetTLBSRCADDR(&pGECtxLocal->halLocalCtx,addr);
5088
5089 GE_RETURN(pGECtx,E_GE_OK);
5090 }
5091
MDrv_GE_GetTLBDSTADDR(GE_Context * pGECtx,MS_PHY * addr)5092 GE_Result MDrv_GE_GetTLBDSTADDR(GE_Context *pGECtx, MS_PHY* addr)
5093 {
5094 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
5095
5096 GE_ENTRY(pGECtx);
5097 GE_GetTLBDSTADDR(&pGECtxLocal->halLocalCtx,addr);
5098
5099 GE_RETURN(pGECtx,E_GE_OK);
5100 }
5101
MDrv_GE_SetTLBSrcBaseAddr(GE_Context * pGECtx,MS_PHY phyaddr)5102 GE_Result MDrv_GE_SetTLBSrcBaseAddr(GE_Context *pGECtx, MS_PHY phyaddr)
5103 {
5104 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
5105
5106 GE_ENTRY(pGECtx);
5107
5108 GE_SetTLBSrcBaseAddr(&pGECtxLocal->halLocalCtx, phyaddr);
5109 GE_RETURN(pGECtx,E_GE_OK);
5110 }
5111
MDrv_GE_SetTLBDstBaseAddr(GE_Context * pGECtx,MS_PHY phyaddr)5112 GE_Result MDrv_GE_SetTLBDstBaseAddr(GE_Context *pGECtx, MS_PHY phyaddr)
5113 {
5114 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
5115
5116 GE_ENTRY(pGECtx);
5117
5118 GE_SetTLBDstBaseAddr(&pGECtxLocal->halLocalCtx, phyaddr);
5119 GE_RETURN(pGECtx,E_GE_OK);
5120 }
5121
MDrv_GE_TLBFlushTable(GE_Context * pGECtx,MS_BOOL bEnable)5122 GE_Result MDrv_GE_TLBFlushTable(GE_Context *pGECtx,MS_BOOL bEnable)
5123 {
5124 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
5125
5126 GE_ENTRY(pGECtx);
5127
5128 GE_FlushTLBTable(&pGECtxLocal->halLocalCtx,bEnable);
5129 GE_RETURN(pGECtx,E_GE_OK);
5130 }
5131
MDrv_GE_SetTLBTag(GE_Context * pGECtx,MS_U16 tag)5132 GE_Result MDrv_GE_SetTLBTag(GE_Context *pGECtx,MS_U16 tag)
5133 {
5134 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
5135
5136 GE_ENTRY(pGECtx);
5137
5138 GE_SetTLBTag(&pGECtxLocal->halLocalCtx,tag);
5139 GE_RETURN(pGECtx,E_GE_OK);
5140 }
5141
MDrv_GE_StopTLBFlush(GE_Context * pGECtx)5142 GE_Result MDrv_GE_StopTLBFlush(GE_Context *pGECtx)
5143 {
5144 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
5145
5146 GE_ENTRY(pGECtx);
5147
5148 GE_StopFlushTLB(&pGECtxLocal->halLocalCtx);
5149 GE_RETURN(pGECtx,E_GE_OK);
5150 }
5151
MDrv_GE_SetBurstMiuLen(GE_Context * pGECtx,MS_BOOL bEnable,MS_U32 u32BurstLen)5152 GE_Result MDrv_GE_SetBurstMiuLen(GE_Context *pGECtx,MS_BOOL bEnable,MS_U32 u32BurstLen)
5153 {
5154 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
5155
5156 GE_ENTRY(pGECtx);
5157 HAL_GE_SetBurstMiuLen(&pGECtxLocal->halLocalCtx,bEnable,u32BurstLen);
5158 GE_RETURN(pGECtx,E_GE_OK);
5159 }
MDrv_GE_RestoreRegInfo(GE_Context * pGECtx,GE_RESTORE_REG_ACTION eRESTORE_ACTION,MS_U16 * value)5160 GE_Result MDrv_GE_RestoreRegInfo(GE_Context *pGECtx,GE_RESTORE_REG_ACTION eRESTORE_ACTION, MS_U16 *value)
5161 {
5162 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
5163
5164 GE_ENTRY(pGECtx);
5165
5166 switch(eRESTORE_ACTION)
5167 {
5168 case E_GE_SAVE_REG_GE_EN:
5169 *value = GE_ReadReg(&pGECtxLocal->halLocalCtx, REG_GE_EN);
5170 break;
5171 case E_GE_RESTORE_REG_GE_EN:
5172 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, *value);
5173 break;
5174 case E_GE_DISABLE_REG_EN:
5175 GE_WriteReg(&pGECtxLocal->halLocalCtx, REG_GE_EN, (*value & ~(GE_EN_ASCK | GE_EN_DSCK | GE_EN_SCK | GE_EN_DCK | GE_EN_BLEND | GE_EN_DFB_BLD | GE_EN_DITHER)));
5176 break;
5177 default:
5178 break;
5179 }
5180
5181 GE_RETURN(pGECtx,E_GE_OK);
5182 }
5183
5184 //-------------------------------------------------------------------------------------------------
5185 ///GE performance test function
5186 //-------------------------------------------------------------------------------------------------
5187 #if (GE_PERFORMANCE_TEST)
5188 #define CLK_Reg(address) (*((volatile MS_U32 *)(REG_CLK_BASE + ((address)<<2) )))
5189 #define REG_ADDR(addr) (*((volatile MS_U16*)(pGECtxLocal->halLocalCtx.va_mmio_base2 + ((addr) << 1))))
5190 #define REG_CLK_BASE (pGECtxLocal->halLocalCtx.va_mmio_base2+0x201600)
5191
5192 #define REG_WR(_reg_, _val_) do{ REG_ADDR(_reg_) = (_val_); }while(0)
5193 #define REG_RR(_reg_) ({ REG_ADDR(_reg_);})
5194 #define REG_PIU_TIMER0(_x_) (0x003020UL | (_x_ << 1))
5195
5196 #define REG_GE_MIUCLIENT (0x1006F4UL)
5197
5198 #define MIU_LOG 0UL //miu flow rate enable --> we could use this to check GE miu_request percentage
5199
5200 #define REG_MIU0_CTRL (0x10121AUL)
5201 #define REG_MIU0_CNT (0x10121CUL)
5202
5203 #define REG_MIU1_CTRL (0x10061AUL)
5204 #define REG_MIU1_CNT (0x10061CUL)
5205
5206 #define REG_MIU0_GROUP0_MASK (0x101246UL)
5207 #define REG_MIU0_GROUP1_MASK (0x101266UL)
5208 #define REG_MIU0_GROUP2_MASK (0x101286UL)
5209 #define REG_MIU0_GROUP3_MASK (0x1012A6UL)
5210
5211 #define REG_MIU1_GROUP0_MASK (0x100646UL)
5212 #define REG_MIU1_GROUP1_MASK (0x100666UL)
5213 #define REG_MIU1_GROUP2_MASK (0x100686UL)
5214 #define REG_MIU1_GROUP3_MASK (0x1006A6UL)
5215
5216
5217 #define MAX_TEST_NUM 9UL
5218 MS_S32 test_rect_w[MAX_TEST_NUM] = { 10,100,100,100,500,500,1280, 1920, 3840};
5219 MS_S32 test_rect_h[MAX_TEST_NUM] = {100, 10,100,500,100,500, 720, 1080, 2160};
5220
5221 //MS_S32 test_rect_w[MAX_TEST_NUM] = { 1280,1280,1280,100,500,500,1280};
5222 //MS_S32 test_rect_h[MAX_TEST_NUM] = {720, 720,720,500,100,500, 720};
5223
5224 #define BLTCNT 1000UL
5225 #define CMD_BLT 0x40UL
5226 #define CMD_FILL 0x30UL
5227
5228 #define GE_TEST_CMD CMD_BLT
5229 #define GE_1P_MODE 1UL
5230
5231 #define GE_MIU_SEL 0x000UL //0: miu0 0x8000: miu1
5232
5233 #define NORMAL_BLT 0x0UL
5234 #define Stretch_BLT 0x1UL
5235 #define BLENDING_BLT 0x4UL
5236
5237 #define STRETCH_RATIO 1.2
5238 #define GE_STRETCH BLENDING_BLT
5239
5240 #define GE_ARGB8888 0x1UL
5241 #define GE_ARGB4444 0x10UL
5242 #define TEST_CASE GE_ARGB8888 | GE_ARGB4444
5243
5244 //---------------------------------------------------------------------------
5245 ///Verify GE bitblt performance
5246 /// @param pGECtx \b IN: GE context
5247 /// @param bEnable \b IN: Enable GE clock or not.
5248 /// @return @ref GE_Result
5249 //---------------------------------------------------------------------------
MDrv_GE_BitbltPerformance(GE_Context * pGECtx)5250 GE_Result MDrv_GE_BitbltPerformance(GE_Context *pGECtx)
5251 {
5252 GE_CTX_LOCAL *pGECtxLocal = (GE_CTX_LOCAL*)pGECtx;
5253 char c;
5254 MS_U16 GEstatus;
5255 MS_BOOL bBusy,bBusy2,bBusy3;
5256 MS_U16 rect_w,rect_h;
5257 MS_U16 stretch_w, stretch_h;
5258 MS_U8 test_idx = 0;
5259 MS_U16 GE_Mode = (GE_1P_MODE<<15) | GE_EN_GE;
5260 MS_U16 GE_Cmd = GE_TEST_CMD;
5261 MS_U8 GE_Stretch_En = GE_STRETCH;
5262 MS_U16 GE_Burst = 0x0000;
5263 MS_U16 GE_Spilt = 0x0000;
5264 MS_U16 GE_BASE = GE_MIU_SEL;
5265 MS_U16 GE_BASE_H = GE_MIU_SEL;
5266 MS_U16 GE_THRESHOLD = 0x7;
5267 MS_U16 pitch=0;
5268 MS_BOOL bPitchAlign=TRUE;
5269 #if (MIU_LOG)
5270 MS_U16 GE_GROUP = MIU1_GEGROUP;
5271 MS_U16 GE_group_client;
5272 #endif
5273 GE_D_INFO("GE_EN:%x\n",GE_Mode);
5274
5275 GE_ENTRY(pGECtx);
5276
5277 #if 0 //Enhance GE performance(i.e for agate)
5278 REG_WR(0x1012FE, 0x011E); //priority 2>3>1>0
5279 REG_WR(0x101240, 0x8011); //disable flow control group 0/1/2
5280 REG_WR(0x101260, 0x8011);
5281 REG_WR(0x101280, 0x8011);
5282
5283 REG_WR(0x1012FC, 0xA400); //FIFO32
5284 REG_WR(0x101228, 0x4090); //PACK enable
5285 #endif
5286 #if 0 //Enhance GE performance(i.e for A3)
5287 REG_WR(0x1012FE, 0x00D2); //priority 2>0>1>3
5288 REG_WR(0x101240, 0x8011); //disable flow control
5289 REG_WR(0x101260, 0x8011);
5290 REG_WR(0x101280, 0x8011);
5291
5292 REG_WR(0x1012FC, 0xA400); //FIFO32
5293 REG_WR(0x101228, 0x4000); //PACK enable
5294
5295 REG_WR(0x101246, 0xffff);
5296 REG_WR(0x101248, 0x0000);
5297 REG_WR(0x101266, 0xffff);
5298 REG_WR(0x101268, 0x0000);
5299 #endif
5300 pGECtxLocal->pSharedCtx->halSharedCtx.bGE_DirectToReg =TRUE;
5301
5302 //=======================Get conditions======Start=================================//
5303 GE_D_INFO("\n[MIU Sel] Type '0'(miu0) or '1'(miu1) or '2'(miu2) to sel MIU Base\n");
5304 c = getchar();
5305 if (c=='2')
5306 {
5307 GE_BASE_H = 0x6000;
5308 GE_BASE = 0x0000; //miu2
5309 }
5310 else if (c=='1')
5311 {
5312 GE_BASE_H = 0x0000;
5313 GE_BASE = 0x8000; //miu1
5314 }
5315 else
5316 {
5317 GE_BASE_H = 0x0000;
5318 GE_BASE = 0x0000; //miu0
5319 }
5320
5321 c = getchar();
5322
5323 GE_D_INFO("[1P/4P(8P) mode] Type '1'(1P) or '4'(4P/8P) to sel engine mode\n");
5324 c = getchar();
5325 if (c=='1')
5326 GE_Mode = (GE_1P_MODE<<15) | GE_EN_GE;
5327 else
5328 GE_Mode = ((!GE_1P_MODE)<<15) | GE_EN_GE;
5329 c = getchar();
5330
5331 GE_D_INFO("[BLT mode] Type 'b'(Bitblt) or 'f'(Rectfill) to sel BLT mode\n");
5332 c = getchar();
5333 if (c=='f')
5334 GE_Cmd = CMD_FILL;
5335 else
5336 GE_Cmd = CMD_BLT;
5337 c = getchar();
5338
5339 GE_D_INFO("[BLT Type] Type 'n'(Normal_BLT) or 's'(Stretch_BLT) or 'b'(Blending_BLT) to sel BLT type\n");
5340 c = getchar();
5341 if (c == 's')
5342 GE_Stretch_En = Stretch_BLT;
5343 else if(c == 'b')
5344 GE_Stretch_En = BLENDING_BLT;
5345 else
5346 GE_Stretch_En = NORMAL_BLT;
5347 c = getchar();
5348
5349 GE_D_INFO("[THRESHOLD] Type '7'(0x7) or 'f'(0xf) or Others to set engine threshold\n\n");
5350 c = getchar();
5351
5352 if (c=='f')
5353 GE_THRESHOLD = 0xF;
5354 else if(c =='7')
5355 GE_THRESHOLD = 0x7;
5356 else
5357 GE_THRESHOLD = 0xD;
5358
5359 #ifdef GE_EN_BURST
5360 c = getchar();
5361 GE_D_INFO("[Burst Type] Type 'b'(Burst) or 'n'(ormal) to speed up\n");
5362 c = getchar();
5363 if (c == 'b')
5364 GE_Burst = 0x4000;
5365 else
5366 GE_Burst = 0x0000;
5367 #endif
5368
5369 if(*(&pGECtxLocal->halLocalCtx.pGeChipPro->bSupportSpiltMode))
5370 {
5371 c = getchar();
5372 GE_D_INFO("[Spilt Type] Type 's'(Spilt) or 'n'(ormal) to speed up\n");
5373 c = getchar();
5374 if (c == 's')
5375 GE_Spilt = 0x4000;
5376 else
5377 GE_Spilt = 0x0000;
5378 }
5379 //=======================Get conditions====End======================================//
5380
5381
5382 GE_D_INFO("%s start\n",__FUNCTION__);
5383
5384 rect_w = test_rect_w[test_idx];
5385 rect_h = test_rect_h[test_idx];
5386
5387 if(GE_Stretch_En == Stretch_BLT)
5388 {
5389
5390 GE_D_INFO("Enable Stretch Blt\n");
5391 stretch_w = rect_w * STRETCH_RATIO;
5392 stretch_h = rect_h * STRETCH_RATIO;
5393 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_CFG, GE_CFG_BLT_STRETCH | GE_CFG_CMDQ);
5394
5395 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_BLT_DST_X_OFST, 0x1000);
5396 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_BLT_DST_Y_OFST, 0x1000);
5397
5398 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_BLT_SRC_DX, (rect_w * 4096)/stretch_w);
5399 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_BLT_SRC_DY, (rect_h * 4096)/stretch_h);
5400
5401 }
5402 else if(GE_Stretch_En == BLENDING_BLT)
5403 {
5404 GE_D_INFO("enable alpha blending\n");
5405 GE_Mode |= BLENDING_BLT;
5406 MDrv_GE_SetAlphaBlend(pGECtx,TRUE,E_GE_BLEND_ROP8_SRCOVER);
5407 stretch_w = rect_w;
5408 stretch_h = rect_h;
5409
5410 }
5411 else
5412 {
5413 GE_D_INFO("Normal Case\n");
5414 stretch_w = rect_w;
5415 stretch_h = rect_h;
5416 }
5417
5418
5419 CLK_Reg(0x48) = 0x0;
5420 //REG_WR(0x100B90, 0x00); //enable miu counter
5421
5422
5423 #if 0
5424 REG_WR(REG_MIU0_GROUP0_MASK, 0xFFF8); //enable miu counter
5425 REG_WR(REG_MIU0_GROUP1_MASK, 0xFFFF); //enable miu counter
5426 REG_WR(REG_MIU0_GROUP2_MASK, 0xFFFE); //enable miu counter
5427 REG_WR(REG_MIU0_GROUP3_MASK, 0xFFFE); //enable miu counter
5428
5429 REG_WR(REG_MIU1_GROUP0_MASK, 0xFFF8); //enable miu counter
5430 REG_WR(REG_MIU1_GROUP1_MASK, 0xFFFF); //enable miu counter
5431 REG_WR(REG_MIU1_GROUP2_MASK, 0xFFFE); //enable miu counter
5432 REG_WR(REG_MIU1_GROUP3_MASK, 0xFFFE); //enable miu counter
5433 #endif
5434
5435 MS_U32 i, u32Timer,avgtime,u32Timer_ms;
5436 MS_U64 Total_Byte;
5437
5438 TEST_START:
5439
5440 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_EN, GE_Mode|GE_Burst); //Burst
5441
5442 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_CFG, GE_ReadReg(&pGECtxLocal->halLocalCtx,REG_GE_CFG)|GE_Spilt); //Spilt
5443
5444 if(GE_ReadReg(&pGECtxLocal->halLocalCtx,REG_GE_EN)& 0x4000)
5445 GE_D_INFO("\33[0\34m Burst Enable \33[m\n");
5446 else
5447 GE_D_INFO("\33[0\34m Burst Disable \33[m\n");
5448
5449
5450 if(GE_ReadReg(&pGECtxLocal->halLocalCtx,REG_GE_CFG)& 0x4000)
5451 GE_D_INFO("\33[0\34m Spilt Enable \33[m\n");
5452 else
5453 GE_D_INFO("\33[0\34m Spilt Disable \33[m\n");
5454
5455 //GE_WriteReg(&pGECtxLocal->halLocalCtx,GE_REG_FMT_BLT, 0x1);
5456 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_TH, GE_THRESHOLD);
5457
5458 /*src/dst miu info*/
5459 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_YUV_MODE, (GE_ReadReg(&pGECtxLocal->halLocalCtx,REG_GE_YUV_MODE)&0x9fff)|GE_BASE_H);
5460
5461 /*src info*/
5462 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_SRC_BASE_L, 0x2000);
5463 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_SRC_BASE_H, 0x3B8 | GE_BASE);
5464
5465 if(bPitchAlign)
5466 {
5467 if (((stretch_w*4)%GE_WordUnit)==0)
5468 {
5469 pitch=stretch_w*4;
5470 GE_D_INFO("[alignment]SRC pitch=%d\n",pitch);
5471 }
5472 else
5473 {
5474 pitch=(((stretch_w)/GE_WordUnit)+1)*4*GE_WordUnit;
5475 GE_D_INFO("[Not alignment]SRC pitch=%d\n",pitch);
5476 }
5477 }
5478 else
5479 pitch=stretch_w*4;
5480
5481 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_SRC_PITCH, pitch);
5482 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_BLT_SRC_W, rect_w);
5483 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_BLT_SRC_H, rect_h);
5484
5485
5486 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V2_X, 0);
5487 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V2_Y, 0);
5488
5489 /*dst info*/
5490 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_DST_BASE_L, 0x6000);
5491 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_DST_BASE_H, 0xBF0 | GE_BASE );
5492
5493 if(bPitchAlign)
5494 {
5495 if (((stretch_w*4)%GE_WordUnit)==0)
5496 {
5497 pitch=stretch_w*4;
5498 GE_D_INFO("[alignment]DST pitch=%d\n",pitch);
5499 }
5500 else
5501 {
5502 pitch=(((stretch_w)/GE_WordUnit)+1)*4*GE_WordUnit;
5503 GE_D_INFO("[Not alignment]DST pitch=%d\n",pitch);
5504 }
5505 }
5506 else
5507 pitch=stretch_w*4;
5508
5509 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_DST_PITCH, pitch);
5510
5511 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V0_X, 0);
5512 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V0_Y, 0);
5513 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V1_X, stretch_w-1);
5514 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_PRIM_V1_Y, stretch_h-1);
5515
5516 /*set clip win*/
5517 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_CLIP_L, 0);
5518 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_CLIP_R, rect_w-1);
5519 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_CLIP_T, 0);
5520 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_CLIP_B, rect_h-1);
5521
5522 /*Set burst length*/
5523 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_DBG, 0x1000);
5524
5525 /*set color format*/
5526 //ARGB8888
5527 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_FMT,( GE_GetFmt(E_GE_FMT_ARGB8888) + ( GE_GetFmt(E_GE_FMT_ARGB8888)<<8 )));
5528
5529 GE_D_INFO("=== cnt:%d MIU_SEL_L_bit:0x%x MIU_SEL_H_bit:0x%x===\n\n",BLTCNT,GE_BASE,GE_BASE_H);
5530
5531
5532 #if (MIU_LOG)
5533 if(GE_GROUP == 0x7A) //group2 -- A5/A3/A2
5534 {
5535 GE_group_client = 0x2000;
5536 }
5537 else if(GE_GROUP == 0x7B) //group 3 -- others
5538 {
5539 GE_group_client = 0x3000;
5540 }
5541
5542 if(GE_BASE == 0)
5543 {
5544 REG_WR(REG_MIU0_CTRL, 0x50 | GE_group_client); //enable miu counter
5545 REG_WR(REG_MIU0_CTRL, 0x51 | GE_group_client); //enable miu counter
5546 }
5547 else
5548 {
5549 REG_WR(REG_MIU1_CTRL, 0x50 | GE_group_client); //enable miu counter
5550 REG_WR(REG_MIU1_CTRL, 0x51 | GE_group_client); //enable miu counter
5551 }
5552 #endif
5553
5554 REG_WR(REG_PIU_TIMER0(0x02), 0xFFFF);
5555 REG_WR(REG_PIU_TIMER0(0x03), 0xFFFF);
5556
5557 REG_WR(REG_PIU_TIMER0(0x00), 0x0);
5558 REG_WR(REG_PIU_TIMER0(0x00), 0x1);
5559 for (i=0; i<BLTCNT; i++)
5560 {
5561 GEstatus = GE_ReadReg(&pGECtxLocal->halLocalCtx,REG_GE_STAT);
5562 if(((GEstatus & GE_STAT_CMDQ2_MASK)>>GE_STAT_CMDQ2_SHFT) <= 2)
5563 {
5564 do
5565 {
5566 GEstatus = GE_ReadReg(&pGECtxLocal->halLocalCtx,REG_GE_STAT);
5567 if(((GEstatus & GE_STAT_CMDQ2_MASK)>>GE_STAT_CMDQ2_SHFT)> 2 )
5568 {
5569 break;
5570 }
5571 }while(1);
5572 }
5573
5574 _GE_SEMAPHORE_ENTRY(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
5575 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_CMD, GE_Cmd);
5576 _GE_SEMAPHORE_RETURN(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
5577
5578 #if (MIU_LOG)
5579 if(i%100 == 0)
5580 {
5581 if(GE_BASE == 0)
5582 GE_D_INFO("i:%d MIU0: %x\n",i,REG_RR(REG_MIU0_CNT));
5583 else
5584 GE_D_INFO("i:%d MIU1: %x\n",i,REG_RR(REG_MIU1_CNT));
5585
5586 }
5587 #endif
5588 }
5589
5590 do
5591 {
5592 GEstatus = GE_ReadReg(&pGECtxLocal->halLocalCtx,REG_GE_STAT);
5593 bBusy = (MS_BOOL)GEstatus & GE_STAT_BUSY;
5594 if(bBusy == 0)
5595 {
5596 GEstatus = GE_ReadReg(&pGECtxLocal->halLocalCtx,REG_GE_STAT);
5597 bBusy2 = (MS_BOOL)GEstatus & GE_STAT_BUSY;
5598 if(bBusy2 == 0)
5599 {
5600 GEstatus = GE_ReadReg(&pGECtxLocal->halLocalCtx,REG_GE_STAT);
5601 bBusy3 = (MS_BOOL)GEstatus & GE_STAT_BUSY;
5602 printf("GE idle:%d\n",bBusy3);
5603 break;
5604 }
5605 }
5606 }while(bBusy != 0);
5607
5608
5609 u32Timer = ((MS_U32)REG_RR(REG_PIU_TIMER0(0x04))) | ((MS_U32)REG_RR(REG_PIU_TIMER0(0x05)) << 16);
5610 u32Timer_ms = ((u32Timer))/12/1000;
5611
5612 if(GE_Cmd == CMD_BLT)
5613 {
5614 GE_D_INFO("\nMHal_GOP_BLTTest ARGB8888 cnt:%u total time:%lu us\n",BLTCNT, u32Timer/12);
5615 GE_D_INFO(" MHal_GOP_BLTTest ARGB8888 time:%d ms\n", u32Timer_ms);
5616 }
5617 else
5618 {
5619 GE_D_INFO("\n GE_RectFill ARGB8888 cnt:%u total time:%lu us\n",BLTCNT, u32Timer/12);
5620 GE_D_INFO("GE_RectFill ARGB8888 time:%d ms\n", u32Timer_ms);
5621 }
5622
5623 Total_Byte = (stretch_w * stretch_h * 4);
5624 GE_D_INFO("Rect: [%d x %d] Size:%llu (%llu MB)\n",stretch_w,stretch_h,Total_Byte,(MS_U64)(Total_Byte*BLTCNT/1024/1024));
5625
5626 avgtime = (((((MS_U64)(Total_Byte*BLTCNT)/(MS_U64)((u32Timer_ms)))*1000)/1024)/1024); //XTAL = 12MHz
5627
5628 GE_D_INFO("\n\33[0;31m=== ARGB8888 Result: %d MB/s ===\33[m\n\n",(MS_U32)avgtime);
5629
5630
5631
5632 //ARGB4444
5633 GE_D_INFO("cnt:%d\n",BLTCNT);
5634 if(bPitchAlign)
5635 {
5636 if (((stretch_w*2)%GE_WordUnit)==0)
5637 {
5638 pitch=stretch_w*2;
5639 GE_D_INFO("[alignment]SRC pitch=%d\n",pitch);
5640 }
5641 else
5642 {
5643 pitch=(((stretch_w)/GE_WordUnit)+1)*2*GE_WordUnit;
5644 GE_D_INFO("[Not alignment]SRC pitch=%d\n",pitch);
5645 }
5646 }
5647 else
5648 pitch=stretch_w*2;
5649
5650 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_SRC_PITCH, pitch);
5651
5652 if(bPitchAlign)
5653 {
5654 if (((stretch_w*2)%GE_WordUnit)==0)
5655 {
5656 pitch=stretch_w*2;
5657 GE_D_INFO("[alignment]DST pitch=%d\n",pitch);
5658 }
5659 else
5660 {
5661 pitch=(((stretch_w)/GE_WordUnit)+1)*GE_WordUnit;
5662 GE_D_INFO("[Not alignment]DST pitch=%d\n",pitch);
5663 }
5664 }
5665 else
5666 pitch=stretch_w*2;
5667
5668 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_DST_PITCH, pitch);
5669 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_FMT, (GE_GetFmt(E_GE_FMT_ARGB4444)+ (GE_GetFmt(E_GE_FMT_ARGB4444)<<8)));
5670
5671 REG_WR(REG_PIU_TIMER0(0x00), 0x0);
5672 REG_WR(REG_PIU_TIMER0(0x00), 0x1);
5673 for (i=0; i<BLTCNT; i++)
5674 {
5675 #if 1
5676 GEstatus = GE_ReadReg(&pGECtxLocal->halLocalCtx,REG_GE_STAT);
5677 //printf("GEStatus:%x\n",GEstatus);
5678
5679 if(((GEstatus & GE_STAT_CMDQ2_MASK)>>GE_STAT_CMDQ2_SHFT) <= 2)
5680 {
5681 //printf("fifo full\n");
5682 do
5683 {
5684 GEstatus = GE_ReadReg(&pGECtxLocal->halLocalCtx,REG_GE_STAT);
5685 if(((GEstatus & GE_STAT_CMDQ2_MASK)>>GE_STAT_CMDQ2_SHFT)> 2 )
5686 {
5687 //printf("continue\n");
5688 break;
5689 }
5690 }while(1);
5691 }
5692 #endif
5693
5694 //GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_CMD, 0x40);
5695 _GE_SEMAPHORE_ENTRY(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
5696 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_CMD, GE_Cmd);
5697 _GE_SEMAPHORE_RETURN(pGECtx,E_GE_POOL_ID_INTERNAL_REGISTER);
5698 }
5699
5700 do
5701 {
5702 GEstatus = GE_ReadReg(&pGECtxLocal->halLocalCtx,REG_GE_STAT);
5703 bBusy = (MS_BOOL)GEstatus & GE_STAT_BUSY;
5704 if(bBusy == 0)
5705 {
5706 GEstatus = GE_ReadReg(&pGECtxLocal->halLocalCtx,REG_GE_STAT);
5707 bBusy2 = (MS_BOOL)GEstatus & GE_STAT_BUSY;
5708 if(bBusy2 == 0)
5709 {
5710 GEstatus = GE_ReadReg(&pGECtxLocal->halLocalCtx,REG_GE_STAT);
5711 bBusy3 = (MS_BOOL)GEstatus & GE_STAT_BUSY;
5712 GE_D_INFO("GE idle:%d\n",bBusy3);
5713 break;
5714 }
5715 }
5716 }while(bBusy != 0);
5717
5718 u32Timer = ((MS_U32)REG_RR(REG_PIU_TIMER0(0x04))) |
5719 ((MS_U32)REG_RR(REG_PIU_TIMER0(0x05)) << 16);
5720
5721 u32Timer_ms = ((u32Timer))/12/1000;
5722
5723
5724 if(GE_Cmd == CMD_BLT)
5725 {
5726 GE_D_INFO("\nGE_BLTTest ARGB4444 cnt:%u total time:%lu us\n",BLTCNT, u32Timer/12);
5727 GE_D_INFO("GE_BLTTest ARGB4444 time:%d sec\n", u32Timer_ms);
5728 }
5729 else
5730 {
5731 GE_D_INFO("\n GE_RectFill ARGB4444 cnt:%u total time:%lu us\n",BLTCNT, u32Timer/12);
5732 GE_D_INFO("GE_RectFill ARGB4444 time:%d ms\n", u32Timer_ms);
5733 }
5734
5735 Total_Byte = (stretch_w * stretch_h * 2);
5736 GE_D_INFO("Rect: [%d x %d] Size:%llu (%llu MB)\n",stretch_w,stretch_h,Total_Byte,(MS_U64)(Total_Byte*BLTCNT/1024/1024));
5737
5738 avgtime = (((((Total_Byte*BLTCNT)/((u32Timer_ms)))*1000)/1024)/1024); //XTAL = 12MHz
5739 GE_D_INFO("\n\33[0;32m=== ARGB4444 Result: %d MB/s ===\33[m\n\n",(MS_U32)avgtime);
5740
5741
5742
5743 test_idx++;
5744
5745 if(test_idx == MAX_TEST_NUM)
5746 {
5747 GE_D_INFO("End of Test\n");
5748 while(1);
5749 }
5750
5751 GE_D_INFO("Reset Enging\n");
5752 GE_WriteReg(&pGECtxLocal->halLocalCtx,REG_GE_EN, 0x0);
5753
5754 rect_w = test_rect_w[test_idx];
5755 rect_h = test_rect_h[test_idx];
5756
5757 if(GE_Stretch_En == Stretch_BLT)
5758 {
5759
5760 GE_D_INFO("Enable Stretch Blt\n");
5761 stretch_w = rect_w * STRETCH_RATIO;
5762 stretch_h = rect_h * STRETCH_RATIO;
5763 }
5764 else
5765 {
5766 stretch_w = rect_w;
5767 stretch_h = rect_h;
5768 }
5769 GE_D_INFO(" Test Case :%d Rect [ %d x %d ] to [%d x %d]\n",test_idx,rect_w,rect_h,stretch_w,stretch_h);
5770 MsOS_DelayTask(100);
5771
5772 goto TEST_START;
5773
5774 GE_RETURN(pGECtx,E_GE_OK);
5775 }
5776 #endif
5777
5778
5779 #endif //_DRV_GE_C_
5780
5781
5782
5783