xref: /utopia/UTPA2-700.0.x/modules/cpu/drv/cpu/drvCPU.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 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    drvCPU.c
98 /// @brief  System Driver Interface
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101 
102 
103 //-------------------------------------------------------------------------------------------------
104 //  Include Files
105 //-------------------------------------------------------------------------------------------------
106 #include <string.h> //for memcpy, memset
107 
108 #include "MsCommon.h"
109 #include "MsVersion.h"
110 #include "MsIRQ.h"
111 #include "MsOS.h"
112 
113 #include "regCHIP.h"
114 #include "halCHIP.h"
115 
116 #include "drvMMIO.h"
117 #include "drvCPU.h"
118 #include "halCPU.h"
119 #include "regCPU.h"
120 #if (CPU_UTOPIA20)
121 #include "utopia.h"
122 #endif
123 
124 #include "ULog.h"
125 
126 //-------------------------------------------------------------------------------------------------
127 //  Driver Compiler Options
128 //-------------------------------------------------------------------------------------------------
129 
130 //-------------------------------------------------------------------------------------------------
131 //  Local Defines
132 //-------------------------------------------------------------------------------------------------
133 #define TAG_CPU "CPU"
134 
135 #define COPRO_DBG_FUNC()             if (_coproDbgLevel >= E_COPRO_DBGLV_ALL) \
136                                         {ULOGD(TAG_CPU, "\t====   %s   ====\n", __FUNCTION__);}
137 #define COPRO_DBG_INFO(x, args...)   if (_coproDbgLevel >= E_COPRO_DBGLV_INFO ) \
138                                         {ULOGI(TAG_CPU, x, ##args);}
139 #define COPRO_DBG_ERR(x, args...)    if (_coproDbgLevel >= E_COPRO_DBGLV_ERR_ONLY) \
140                                         {ULOGE(TAG_CPU, x, ##args);}
141 #define CPU_DEBUGINFO(x) //x
142 
143 //-------------------------------------------------------------------------------------------------
144 //  Local Structurs
145 //-------------------------------------------------------------------------------------------------
146 
147 //-------------------------------------------------------------------------------------------------
148 //  Global Variables
149 //-------------------------------------------------------------------------------------------------
150 
151 //MST_PANEL_INFO_t  g_Panel_Info;
152 MS_U8 u8QueueClass;
153 MS_U8 parasize, *TmpQueue, QueueSize, QueueLength, u8Temp;
154 MS_U8 u8WritePtr, u8ReadPtr, u8QLen;
155 
156 //-------------------------------------------------------------------------------------------------
157 //  Local Variables
158 //-------------------------------------------------------------------------------------------------
159 MS_BOOL g_bBEON_HOST = FALSE;
160 MS_BOOL bWait_MMAP_Receive=FALSE;
161 
162 #if (CPU_UTOPIA20)
163 void* pInstantCpu = NULL;
164 void* pAttributeCpu = NULL;
165 #endif
166 
167 // Uart driver info
168 #if !defined(CONFIG_FRC)//frcr2_integration###
169 static COPRO_DrvInfo                 _frcr2Info =
170                                     {
171                                         .Init = FALSE,
172                                         .u32Addr = 0,
173                                     };
174 static COPRO_DrvStatus               _frcr2Status =
175                                     {
176                                         .HwBusy = FALSE,
177                                     };
178 #endif
179 static COPRO_DrvInfo                 _coproInfo =
180                                     {
181                                         .Init = FALSE,
182                                         .u32Addr = 0,
183                                     };
184 
185 static COPRO_DrvStatus               _coproStatus =
186                                     {
187                                         .HwBusy = FALSE,
188                                     };
189 
190 static MSIF_Version _coproVersion = {
191     .DDI = { COPRO_DRV_VERSION },
192 };
193 
194 static COPRO_DbgLv _coproDbgLevel = E_COPRO_DBGLV_ERR_ONLY;
195 
196 //-------------------------------------------------------------------------------------------------
197 //  Debug Functions
198 //-------------------------------------------------------------------------------------------------
199 
200 
201 //-------------------------------------------------------------------------------------------------
202 //  Local Functions
203 //-------------------------------------------------------------------------------------------------
204 
205 
206 //-------------------------------------------------------------------------------------------------
207 //  Global Functions
208 //-------------------------------------------------------------------------------------------------
_MDrv_CPU_Disable(void)209 void _MDrv_CPU_Disable(void)
210 {
211     _coproStatus.HwBusy = TRUE;
212     HAL_COPRO_Disable();
213     _coproStatus.HwBusy = FALSE;
214 }
215 
_MDrv_CPU_Enable(MS_U32 u32_ADR)216 void _MDrv_CPU_Enable(MS_U32 u32_ADR)
217 {
218     _coproStatus.HwBusy = TRUE;
219     _coproInfo.u32Addr = u32_ADR;
220     HAL_COPRO_Enable(u32_ADR);
221     _coproStatus.HwBusy = FALSE;
222 }
223 
_MDrv_CPU_SetHost(MS_BOOL bHost)224 void _MDrv_CPU_SetHost(MS_BOOL bHost)
225 {
226      g_bBEON_HOST = bHost;
227 }
228 
_MDrv_CPU_InitFront(void)229 void _MDrv_CPU_InitFront(void)
230 {
231     if(MDrv_COPRO_GetBase()==FALSE)
232     {
233         MS_DEBUG_MSG(COPRO_DBG_ERR("MDrv_COPRO_Init Fail\n"));
234         return;
235     }
236 
237     HAL_COPRO_Init_Front();
238 	_coproInfo.Init = FALSE;
239     _coproStatus.HwBusy = FALSE;
240 }
241 
_MDrv_CPU_InitEnd(MS_U32 u32_ADR)242 void _MDrv_CPU_InitEnd(MS_U32 u32_ADR)
243 {
244     HAL_COPRO_Init_End(u32_ADR);
245     // Driver Initialization
246     _coproInfo.Init = TRUE;
247     _coproInfo.u32Addr = u32_ADR;
248     _coproStatus.HwBusy = FALSE;
249 }
250 
_MDrv_CPU_GetInfo(void)251 const COPRO_DrvInfo* _MDrv_CPU_GetInfo(void)
252 {
253     return (&_coproInfo);
254 }
255 
_MDrv_CPU_GetLibVer(const MSIF_Version ** ppVersion)256 COPRO_Result _MDrv_CPU_GetLibVer(const MSIF_Version **ppVersion)
257 {
258     // No mutex check, it can be called before Init
259     if (!ppVersion)
260     {
261         return E_COPRO_FAIL;
262     }
263 
264     *ppVersion = &_coproVersion;
265 
266     return E_COPRO_OK;
267 }
268 
_MDrv_CPU_GetStatus(COPRO_DrvStatus * pStatus)269 COPRO_Result _MDrv_CPU_GetStatus(COPRO_DrvStatus *pStatus)
270 {
271     memcpy(pStatus, &_coproStatus, sizeof(COPRO_DrvStatus));
272     return E_COPRO_OK;
273 }
274 
_MDrv_CPU_SetDbgLevel(MS_U8 level)275 void _MDrv_CPU_SetDbgLevel(MS_U8 level)
276 {
277     _coproDbgLevel = (COPRO_DbgLv)level;
278 }
279 
280 
_MDrv_CPU_GetBase(void)281 MS_VIRT _MDrv_CPU_GetBase(void)
282 {
283     MS_PHY u32NonPMBankSize;
284     MS_VIRT u32NonPMBankAddr = 0;
285 
286     _coproStatus.HwBusy = TRUE;
287 
288     ///-Disable aeon
289     if( !MDrv_MMIO_GetBASE( &u32NonPMBankAddr, &u32NonPMBankSize, MS_MODULE_HW))
290     {
291         MS_DEBUG_MSG(COPRO_DBG_ERR("_COPRO_Init: IOMap failure\n"));
292     }
293     else
294     {
295         HAL_COPRO_RegSetBase(u32NonPMBankAddr);
296         MS_DEBUG_MSG(COPRO_DBG_ERR("_COPRO_Init: u32RiuBaseAdd = %lx\n", u32NonPMBankAddr));
297     }
298     _coproStatus.HwBusy = FALSE;
299 
300     return u32NonPMBankAddr;
301 }
302 
_MDrv_CPU_QueryClock(void)303 MS_U32 _MDrv_CPU_QueryClock(void)
304 {
305     return HAL_CPU_QueryClock();
306 }
307 
308 
309 //#####################################################
310 ////////////////////////////////////////////////////////////////////////////////
311 /// @brief \b Function \b Name: MDrv_CPU_GetVerString()
312 /// @brief \b Function \b Description: This function shows the version of
313 ///                                    cpu driver version
314 /// @param <IN>        \b None :
315 /// @param <OUT>       \b *pVerString : pointer to a U8 string to
316 ///                                     store the CPU driver version
317 /// @param <RET>       \b None :
318 /// @param <GLOBAL>    \b VER  : Library version string
319 ////////////////////////////////////////////////////////////////////////////////
MDrv_COPRO_GetInfo(void)320 const COPRO_DrvInfo* MDrv_COPRO_GetInfo(void)
321 {
322     return _MDrv_CPU_GetInfo();
323 }
324 
MDrv_COPRO_GetLibVer(const MSIF_Version ** ppVersion)325 COPRO_Result MDrv_COPRO_GetLibVer(const MSIF_Version **ppVersion)
326 {
327     return _MDrv_CPU_GetLibVer(ppVersion);
328 }
329 
330 ////////////////////////////////////////////////////////////////////////////////
331 /// @brief \b Function \b Name: MDrv_COPRO_GetStatus
332 /// @brief \b Function \b Description: Get status
333 /// @param  <IN>     \b pStatus : a pointer to status
334 /// @param  <OUT>    \b pStatus : get the status from the pointer
335 /// @param  <RET>    \b COPRO_Result :
336 ////////////////////////////////////////////////////////////////////////////////
MDrv_COPRO_GetStatus(COPRO_DrvStatus * pStatus)337 COPRO_Result MDrv_COPRO_GetStatus(COPRO_DrvStatus *pStatus)
338 {
339   #if (CPU_UTOPIA20)
340     PCPU_GETSTATUS_PARAM pGetStatusParam = NULL;
341 
342     MS_BOOL bFlagClose = FALSE;
343     if (pInstantCpu==NULL)
344     {
345         if(UtopiaOpen(MODULE_CPU, &pInstantCpu, 0, pAttributeCpu) !=  UTOPIA_STATUS_SUCCESS)
346         {
347             MS_DEBUG_MSG(COPRO_DBG_ERR("Open CPU fail\n"));
348             return E_COPRO_FAIL;
349         }
350         bFlagClose = TRUE;
351     }
352 
353     pGetStatusParam = (PCPU_GETSTATUS_PARAM)malloc(sizeof(CPU_GETSTATUS_PARAM));
354     if (pGetStatusParam==NULL)
355     {
356         return E_COPRO_FAIL;
357     }
358     pGetStatusParam->pStatus = pStatus;
359     if (UtopiaIoctl(pInstantCpu,MDrv_CMD_CPU_GetStatus,(void*)pGetStatusParam) != UTOPIA_STATUS_SUCCESS)
360     {
361         MS_DEBUG_MSG(COPRO_DBG_ERR("Ioctl MDrv_CMD_CPU_GetStatus failure\n"));
362     }
363 
364     free(pGetStatusParam);
365 
366     if (bFlagClose)
367     {
368         if(UtopiaClose(pInstantCpu) != UTOPIA_STATUS_SUCCESS)
369         {
370             MS_DEBUG_MSG(COPRO_DBG_ERR("close CPU fail\n"));
371         }
372         pInstantCpu = 0;
373     }
374 
375     return E_COPRO_OK;
376   #else
377     return _MDrv_CPU_GetStatus(pStatus);
378   #endif
379 }
380 
381 ////////////////////////////////////////////////////////////////////////////////
382 /// @brief \b Function \b Name: MDrv_COPRO_SetDbgLevel
383 /// @brief \b Function \b Description: Seet debug level
384 /// @param  <IN>     \b level : debug level
385 /// @param  <OUT>    \b None :
386 /// @param  <RET>    \b None :
387 ////////////////////////////////////////////////////////////////////////////////
MDrv_COPRO_SetDbgLevel(MS_U8 u8Level)388 void MDrv_COPRO_SetDbgLevel(MS_U8 u8Level)
389 {
390   #if (CPU_UTOPIA20)
391     PCPU_SETDBGLEVEL_PARAM pSetDbgLevelParam = NULL;
392     if (pInstantCpu==NULL)
393     {
394         return;
395     }
396     pSetDbgLevelParam = (PCPU_SETDBGLEVEL_PARAM)malloc(sizeof(CPU_SETDBGLEVEL_PARAM));
397     if (pSetDbgLevelParam==NULL)
398     {
399         return;
400     }
401     pSetDbgLevelParam->u8Level = u8Level;
402     if (UtopiaIoctl(pInstantCpu,MDrv_CMD_CPU_SetDbgLevel,(void*)pSetDbgLevelParam) != UTOPIA_STATUS_SUCCESS)
403     {
404         MS_DEBUG_MSG(COPRO_DBG_ERR("Ioctl MDrv_CMD_CPU_SetDbgLevel failure\n"));
405     }
406     free(pSetDbgLevelParam);
407   #else
408     _MDrv_CPU_SetDbgLevel(u8Level);
409   #endif
410 }
411 
412 ////////////////////////////////////////////////////////////////////////////////
413 /// @brief \b Function \b Name: MDrv_SetBEON_Host
414 /// @brief \b Function \b Description: Set BEON as Host
415 /// @param  <IN>     \b bHost : TRUE : BEON is Host, FALSE : BEON is not host
416 /// @param  <OUT>    \b None :
417 /// @param  <RET>    \b None :
418 ////////////////////////////////////////////////////////////////////////////////
MDrv_SetBEON_Host(MS_BOOL bHost)419 void MDrv_SetBEON_Host(MS_BOOL bHost)
420 {
421   #if (CPU_UTOPIA20)
422     PCPU_SETHOST_PARAM pSetHostParam = NULL;
423     if (pInstantCpu==NULL)
424     {
425         return;
426     }
427     pSetHostParam = (PCPU_SETHOST_PARAM)malloc(sizeof(CPU_SETHOST_PARAM));
428     if (pSetHostParam==NULL)
429     {
430         return;
431     }
432     pSetHostParam->bHost = bHost;
433     if (UtopiaIoctl(pInstantCpu,MDrv_CMD_CPU_SetHost,(void*)pSetHostParam) != UTOPIA_STATUS_SUCCESS)
434     {
435         MS_DEBUG_MSG(COPRO_DBG_ERR("Ioctl MDrv_CMD_CPU_SetHost failure\n"));
436     }
437     free(pSetHostParam);
438   #else
439      _MDrv_CPU_SetHost(bHost);
440   #endif
441 }
442 
443 ////////////////////////////////////////////////////////////////////////////////
444 /// @brief \b Function \b Name: MDrv_COPRO_Disable
445 /// @brief \b Function \b Description: Reset & disable co-processor
446 /// @param  <IN>     \b None :
447 /// @param  <OUT>    \b None :
448 /// @param  <RET>    \b None :
449 ////////////////////////////////////////////////////////////////////////////////
MDrv_COPRO_Disable(void)450 void MDrv_COPRO_Disable(void)
451 {
452   #if (CPU_UTOPIA20)
453     if (pInstantCpu==NULL)
454     {
455         return;
456     }
457     if (UtopiaIoctl(pInstantCpu,MDrv_CMD_CPU_Disable,(void*)NULL) != UTOPIA_STATUS_SUCCESS)
458     {
459         MS_DEBUG_MSG(COPRO_DBG_ERR("Ioctl MDrv_CMD_CPU_Disable failure\n"));
460     }
461   #else
462     _MDrv_CPU_Disable();
463   #endif
464 }
465 
466 ////////////////////////////////////////////////////////////////////////////////
467 /// @brief \b Function \b Name: MDrv_COPRO_Enable
468 /// @brief \b Function \b Description: Release to enable co-processor
469 /// @param  <IN>     \b u32_ADR : Set physical address
470 /// @param  <OUT>    \b None :
471 /// @param  <RET>    \b None :
472 ////////////////////////////////////////////////////////////////////////////////
MDrv_COPRO_Enable(MS_U32 u32_ADR)473 void MDrv_COPRO_Enable(MS_U32 u32_ADR)
474 {
475   #if (CPU_UTOPIA20)
476     PCPU_ENABLE_PARAM pEnableParam = NULL;
477     if (pInstantCpu==NULL)
478     {
479         return;
480     }
481     pEnableParam = (PCPU_ENABLE_PARAM)malloc(sizeof(CPU_ENABLE_PARAM));
482     if (pEnableParam==NULL)
483     {
484         return;
485     }
486     pEnableParam->u32_ADR = u32_ADR;
487     if (UtopiaIoctl(pInstantCpu,MDrv_CMD_CPU_Enable,(void*)pEnableParam) != UTOPIA_STATUS_SUCCESS)
488     {
489         MS_DEBUG_MSG(COPRO_DBG_ERR("Ioctl MDrv_CMD_CPU_Enable failure\n"));
490     }
491     free(pEnableParam);
492   #else
493     _MDrv_CPU_Enable(u32_ADR);
494   #endif
495 }
496 
497 ////////////////////////////////////////////////////////////////////////////////
498 /// @brief \b Function \b Name: MDrv_COPRO_GetBase
499 /// @brief \b Function \b Description: Get RIU access base
500 /// @param  <IN>     \b None :
501 /// @param  <OUT>    \b None :
502 /// @param  <RET>    \b MS_U32 : RIU access base
503 ////////////////////////////////////////////////////////////////////////////////
MDrv_COPRO_GetBase(void)504 MS_VIRT MDrv_COPRO_GetBase(void)
505 {
506     return _MDrv_CPU_GetBase();
507 }
508 
509 ////////////////////////////////////////////////////////////////////////////////
510 /// @brief \b Function \b Name: MDrv_COPRO_Init_Front
511 /// @brief \b Function \b Description: Reset & disable co-processor
512 /// @param  <IN>     \b None :
513 /// @param  <OUT>    \b None :
514 /// @param  <RET>    \b None :
515 ////////////////////////////////////////////////////////////////////////////////
MDrv_COPRO_Init_Front(void)516 void MDrv_COPRO_Init_Front(void)
517 {
518   #if (CPU_UTOPIA20)
519     if(pInstantCpu)
520     {
521 	    if(UtopiaClose(pInstantCpu) != UTOPIA_STATUS_SUCCESS)
522 	    {
523 		    MS_DEBUG_MSG(COPRO_DBG_ERR("close CPU fail\n"));
524 	    }
525         pInstantCpu = NULL;
526     }
527   #endif
528     return _MDrv_CPU_InitFront();
529 }
530 
531 ////////////////////////////////////////////////////////////////////////////////
532 /// @brief \b Function \b Name: MDrv_COPRO_Init_End
533 /// @brief \b Function \b Description: Release & enable co-processor
534 /// @param  <IN>     \b u32_ADR : Set physical address
535 /// @param  <OUT>    \b None :
536 /// @param  <RET>    \b None :
537 ////////////////////////////////////////////////////////////////////////////////
MDrv_COPRO_Init_End(MS_U32 u32_ADR)538 void MDrv_COPRO_Init_End(MS_U32 u32_ADR)
539 {
540   #if (CPU_UTOPIA20)
541     if(pInstantCpu==NULL)
542     {
543 	    if(UtopiaOpen(MODULE_CPU, &pInstantCpu, 0, pAttributeCpu) !=  UTOPIA_STATUS_SUCCESS)
544 	    {
545 		    MS_DEBUG_MSG(COPRO_DBG_ERR("Open CPU fail\n"));
546 		    _coproInfo.Init = FALSE;
547 	    }
548     }
549   #endif
550     return _MDrv_CPU_InitEnd(u32_ADR);
551 }
552 
553 #if !defined(CONFIG_FRC)//frcr2_integration###
554 ////////////////////////////////////////////////////////////////////////////////
555 /// @brief \b Function \b Name: MDrv_FRCR2_Init_Front
556 /// @brief \b Function \b Description: Reset & disable co-processor
557 /// @param  <IN>     \b None :
558 /// @param  <OUT>    \b None :
559 /// @param  <RET>    \b None :
560 ////////////////////////////////////////////////////////////////////////////////
MDrv_FRCR2_Init_Front(void)561 void MDrv_FRCR2_Init_Front(void)
562 {
563     if(MDrv_COPRO_GetBase()==FALSE)
564     {
565         MS_DEBUG_MSG(COPRO_DBG_ERR("MDrv_COPRO_Init Fail\n"));
566         return;
567     }
568     HAL_FRCR2_Init_Front();
569 	_frcr2Info.Init = FALSE;
570     _frcr2Status.HwBusy = FALSE;
571 }
572 
573 ////////////////////////////////////////////////////////////////////////////////
574 /// @brief \b Function \b Name: MDrv_FRCR2_Init_End
575 /// @brief \b Function \b Description: Release & enable co-processor
576 /// @param  <IN>     \b u32_ADR : Set physical address
577 /// @param  <OUT>    \b None :
578 /// @param  <RET>    \b None :
579 ////////////////////////////////////////////////////////////////////////////////
MDrv_FRCR2_Init_End(MS_U32 u32_ADR)580 void MDrv_FRCR2_Init_End(MS_U32 u32_ADR)
581 {
582     HAL_FRCR2_Init_End(u32_ADR);
583     _frcr2Info.Init = TRUE;
584     _frcr2Info.u32Addr = u32_ADR;
585     _frcr2Status.HwBusy = FALSE;
586 }
587 #endif
588 
589 ////////////////////////////////////////////////////////////////////////////////
590 /// @brief \b Function \b Name: MDrv_CPU_QueryClock
591 /// @brief \b Function \b Description: Get Host CPU clock
592 /// @param  <IN>     \b None :
593 /// @param  <OUT>    \b None :
594 /// @param  <RET>    \b None :
595 ////////////////////////////////////////////////////////////////////////////////
MDrv_CPU_QueryClock(void)596 MS_U32 MDrv_CPU_QueryClock(void)
597 {
598   #if (CPU_UTOPIA20)
599     MS_U32 u32QueryClock = 0;
600     MS_BOOL bFlagClose = FALSE;
601     if (pInstantCpu==NULL)
602     {
603         if(UtopiaOpen(MODULE_CPU, &pInstantCpu, 0, pAttributeCpu) !=  UTOPIA_STATUS_SUCCESS)
604         {
605             MS_DEBUG_MSG(COPRO_DBG_ERR("Open CPU fail\n"));
606             return E_COPRO_FAIL;
607         }
608         bFlagClose = TRUE;
609     }
610     if (UtopiaIoctl(pInstantCpu,MDrv_CMD_CPU_QueryClock,(void*)(&u32QueryClock)) != UTOPIA_STATUS_SUCCESS)
611     {
612         MS_DEBUG_MSG(COPRO_DBG_ERR("Ioctl MDrv_CMD_CPU_QueryClock failure\n"));
613     }
614     if (bFlagClose)
615     {
616         if(UtopiaClose(pInstantCpu) != UTOPIA_STATUS_SUCCESS)
617         {
618             MS_DEBUG_MSG(COPRO_DBG_ERR("close CPU fail\n"));
619         }
620 		pInstantCpu = 0;
621     }
622     return u32QueryClock;
623   #else
624     return _MDrv_CPU_QueryClock();
625   #endif
626 }
627 
628 ////////////////////////////////////////////////////////////////////////////////
629 /// @brief \b Function \b Name: MDrv_CPU_SetPowerState
630 /// @brief \b Function \b Description: Support Suspend/Resume mechanism
631 /// @param  <IN>     \b u16PowerState : set power state
632 /// @param  <OUT>    \b None :
633 /// @param  <RET>    \b MS_U32 : return utopia status
634 ////////////////////////////////////////////////////////////////////////////////
MDrv_CPU_SetPowerState(EN_POWER_MODE u16PowerState)635 MS_U32 MDrv_CPU_SetPowerState(EN_POWER_MODE u16PowerState)
636 {
637 	static EN_POWER_MODE _prev_u16PowerState = E_POWER_MECHANICAL;
638 	MS_U16 u16Return = UTOPIA_STATUS_FAIL;
639 
640 	if (u16PowerState == E_POWER_SUSPEND)
641 	{
642 	    MDrv_COPRO_Disable();
643 		_prev_u16PowerState = u16PowerState;
644 		u16Return = UTOPIA_STATUS_SUCCESS;//SUSPEND_OK;
645 	}
646 	else if (u16PowerState == E_POWER_RESUME)
647 	{
648 
649 		if (_prev_u16PowerState == E_POWER_SUSPEND)
650 		{
651             MDrv_COPRO_Init_Front();
652             MDrv_COPRO_Init_End(_coproInfo.u32Addr);
653             #if !defined(CONFIG_FRC)//frcr2_integration###
654             MDrv_FRCR2_Init_Front();
655             MDrv_FRCR2_Init_End(_frcr2Info.u32Addr);
656             #endif
657 			_prev_u16PowerState = u16PowerState;
658 			u16Return = UTOPIA_STATUS_SUCCESS;//RESUME_OK;
659 		}
660 		else
661 		{
662 		    MS_DEBUG_MSG(COPRO_DBG_ERR("[%s,%5d]It is not suspended yet. We shouldn't resume\n",__FUNCTION__,__LINE__));
663 			u16Return = UTOPIA_STATUS_FAIL;//SUSPEND_FAILED;
664 		}
665 	}
666 	else
667 	{
668         MS_DEBUG_MSG(COPRO_DBG_ERR("[%s,%5d]Do Nothing: %d\n",__FUNCTION__,__LINE__,u16PowerState));
669 		u16Return = UTOPIA_STATUS_FAIL;
670 	}
671 
672 	return u16Return;// for success
673 }
674 
MDrv_CPU_GetDqmemInfo(MS_U32 * pu32_DqmemAddr,MS_U32 * pu32_DqmemSize)675 MS_U32 MDrv_CPU_GetDqmemInfo(MS_U32 *pu32_DqmemAddr, MS_U32 *pu32_DqmemSize)
676 {
677     MS_U32 u32Return = UTOPIA_STATUS_FAIL;
678 
679 #ifdef __AEONR2__
680     if (pu32_DqmemAddr && pu32_DqmemSize)
681     {
682         MS_VIRT u32RiuBaseAddr;
683         MS_PHY u32RiuBaseSize;
684         MS_U16 u16BaseHigh, u16MaskHigh;
685 
686         if( !MDrv_MMIO_GetBASE(&u32RiuBaseAddr, &u32RiuBaseSize, MS_MODULE_HW) )
687         {
688             MS_DEBUG_MSG(COPRO_DBG_ERR("MDrv_CPU_GetDqmemInfo: IOMap failure for R2\n"));
689             return u32Return;
690         }
691         else
692         {
693             HAL_COPRO_RegSetBase(u32RiuBaseAddr);
694             MS_DEBUG_MSG(COPRO_DBG_INFO("MDrv_CPU_GetDqmemInfo: u32RiuBaseAdd = %lx, size = 0x:%lx\n", u32RiuBaseAddr, u32RiuBaseSize));
695         }
696 
697         if ( !(HAL_COPRO_RegRead2Byte(R2_REG_SPACE_EN) & BIT(4)))   // io_space_en[3:0]: UART,RIU, qmem_space_en[4] : enable
698         {
699             MS_DEBUG_MSG(COPRO_DBG_INFO("MDrv_CPU_GetDqmemInfo: DQMEM is Disable\n"));
700             return u32Return;
701         }
702 
703         u16BaseHigh = HAL_COPRO_RegRead2Byte(R2_REG_QMEM_BASE_HIGH);
704         //lib_lowprintf("[Jeffery utopia] [R2] DQMEM High Base = 0x%x\n", (unsigned int)u16BaseHigh);
705         u16MaskHigh = HAL_COPRO_RegRead2Byte(R2_REG_QMEM_MASK_HIGH);
706         //lib_lowprintf("[Jeffery utopia] [R2] DQMEM High Mask = 0x%x\n", (unsigned int)u16MaskHigh);
707 
708         *pu32_DqmemAddr = (MS_U32) ((u16BaseHigh & u16MaskHigh) << 16);
709         *pu32_DqmemSize = 8*1024;
710 
711         u32Return = UTOPIA_STATUS_SUCCESS;
712     }
713 #else
714     MS_DEBUG_MSG(COPRO_DBG_ERR("[%s,%5d] Get DQMEM Fail: R2 PROC only\n", __func__, __LINE__));
715 #endif  //#ifdef __AEONR2__
716 
717     return u32Return;
718 }
719