xref: /utopia/UTPA2-700.0.x/modules/seal/drv/seal/drvSEAL.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2006-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // (¡§MStar Confidential Information¡¨) by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94 
95 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// file    drvSEAL.c
98 /// @brief  SEAL Driver Interface
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101 
102 //-------------------------------------------------------------------------------------------------
103 // Include Files
104 //-------------------------------------------------------------------------------------------------
105 #include "MsCommon.h"
106 #include "MsVersion.h"
107 #include "MsTypes.h"
108 #include "drvSEAL.h"
109 #include "halSEAL.h"
110 #include "drvMMIO.h"
111 #include "MsOS.h"
112 #include "ULog.h"
113 
114 //-------------------------------------------------------------------------------------------------
115 // Local Defines
116 //-------------------------------------------------------------------------------------------------
117 #define TAG_SEAL "SEAL"
118 #define SEAL_ERROR(fmt, args...)           ULOGE(TAG_SEAL, "[SEAL USER ERR][%06d]     " fmt, __LINE__, ## args)
119 #define SEAL_WARN(fmt, args...)            ULOGW(TAG_SEAL, "[SEAL USER WARN][%06d]    " fmt, __LINE__, ## args)
120 #define SEAL_PRINT(fmt, args...)           ULOGD(TAG_SEAL, "[SEAL USER][%06d]         " fmt, __LINE__, ## args)
121 
122 //-------------------------------------------------------------------------------------------------
123 // Macros
124 //-------------------------------------------------------------------------------------------------
125 
126 
127 //-------------------------------------------------------------------------------------------------
128 // Global Variables
129 //-------------------------------------------------------------------------------------------------
130 
131 static SEAL_CB_FUNC  _pSEALCbFunc = NULL;
132 
133 
134 //-------------------------------------------------------------------------------------------------
135 // Local Variables
136 //-------------------------------------------------------------------------------------------------
137 static MSIF_Version _drv_seal_version = {
138     .DDI = { SEAL_DRV_VERSION },
139 };
140 
141 static MS_BOOL _gbSEALInitialized = FALSE;
142 
143 //-------------------------------------------------------------------------------------------------
144 // Local Function Prototypes
145 //-------------------------------------------------------------------------------------------------
146 
147 ////////////////////////////////////////////////////////////////////////////////
148 /// @brief \b Function  \b Name: MDrv_SEAL_GetLibVer
149 /// @brief \b Function  \b Description: Show the SEAL driver version
150 /// @param ppVersion    \b Out: Library version string
151 /// @return             \b 0: Fail 1: Ok
152 ////////////////////////////////////////////////////////////////////////////////
MDrv_SEAL_GetLibVer(const MSIF_Version ** ppVersion)153 MS_BOOL MDrv_SEAL_GetLibVer(const MSIF_Version **ppVersion)
154 {
155     if (!ppVersion)
156         return FALSE;
157 
158     *ppVersion = &_drv_seal_version;
159     return TRUE;
160 }
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// @brief \b Function  \b Name: MDrv_SEAL_Init
164 /// @brief \b Function  \b Description: set SEAL I/O Map base address and parse occupied resource to software structure
165 /// @param None         \b IN :
166 /// @param None         \b OUT :
167 /// @param MS_BOOL      \b RET
168 /// @param None         \b GLOBAL :
169 ////////////////////////////////////////////////////////////////////////////////
MDrv_SEAL_Init(void)170 MS_BOOL MDrv_SEAL_Init(void)
171 {
172     MS_VIRT u32NonPmBaseAddr = 0;
173     MS_PHY u32NonPmBankSize = 0;
174     MS_VIRT u32PmBaseAddr = 0;
175     MS_PHY u32PmBankSize = 0;
176 
177     if (_gbSEALInitialized == TRUE)
178     {
179         SEAL_WARN("%s is called before!\n", __FUNCTION__);
180         return TRUE;
181     }
182 
183     if( !MDrv_MMIO_GetBASE(&u32NonPmBaseAddr, &u32NonPmBankSize, MS_MODULE_MIU))
184     {
185         SEAL_ERROR("Get NonPM IOMap failure\n");
186         MS_ASSERT(0);
187         return FALSE;
188     }
189 
190     if( !MDrv_MMIO_GetBASE(&u32PmBaseAddr, &u32PmBankSize, MS_MODULE_PM))
191     {
192         SEAL_ERROR("Get PM IOMap failure\n");
193         MS_ASSERT(0);
194         return FALSE;
195     }
196 
197     HAL_SEAL_SetIOMapBase(u32NonPmBaseAddr, u32PmBaseAddr);
198     _gbSEALInitialized = TRUE;
199 
200     return TRUE;
201 }
202 
203 ////////////////////////////////////////////////////////////////////////////////
204 /// @brief \b Function       \b Name: MDrv_Seal_SecureRangeSet
205 /// @brief \b Function       \b Description: set the secure range on MIU
206 /// @param u8SecureRangeId:  \b IN : Secure range ID
207 /// @param u64StartAddr      \b IN : Start address of secure range
208 /// @param u64EndAddr        \b IN : End address of secure range
209 /// @param u32Attribute      \b IN : Attribute of secure range
210 /// @param None              \b OUT :
211 /// @param MS_BOOL           \b RET
212 /// @param None              \b GLOBAL :
213 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_SecureRangeSet(MS_U8 u8SecureRangeId,MS_U64 u64StartAddr,MS_U64 u64EndAddr,MS_U32 u32Attribute)214 MS_BOOL MDrv_Seal_SecureRangeSet(MS_U8 u8SecureRangeId ,MS_U64 u64StartAddr, MS_U64 u64EndAddr, MS_U32 u32Attribute)
215 {
216     if (!_gbSEALInitialized)
217     {
218         SEAL_WARN("%s is called before init\n", __FUNCTION__);
219         return FALSE;
220     }
221 
222     MS_BOOL bret;
223 
224     if(((u64StartAddr & (SEAL_SECURE_RANGE_ALIGN -1)) != 0) || ((u64EndAddr & (SEAL_SECURE_RANGE_ALIGN -1)) != 0))
225     {
226         SEAL_ERROR("Secure range address should be aligned to %lx\n",SEAL_SECURE_RANGE_ALIGN);
227         bret = FALSE;
228         return bret;
229     }
230 
231 
232     bret = HAL_Seal_SecureRangeSet(u8SecureRangeId, u64StartAddr, u64EndAddr, u32Attribute);
233 
234     return bret;
235 }
236 
237 ////////////////////////////////////////////////////////////////////////////////
238 /// @brief \b Function       \b Name: MDrv_Seal_SecureRangeQuery
239 /// @brief \b Function       \b Description: Query the attribute of secure range
240 /// @param u8MiuDev          \b IN : 0:MIU0 1:MIU1 2:MIU2 3:MIU3
241 /// @param u8SecureRangeId:  \b IN : Secure range ID
242 /// @param pAttribute        \b OUT : Information of secure range
243 /// @param MS_BOOL           \b RET
244 /// @param None              \b GLOBAL :
245 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_SecureRangeQuery(MS_U8 u8MiuDev,MS_U8 u8SecureRangeId,Seal_SecureRangeInfo * pSecureRangeInfo)246 MS_BOOL MDrv_Seal_SecureRangeQuery(MS_U8 u8MiuDev, MS_U8 u8SecureRangeId, Seal_SecureRangeInfo *pSecureRangeInfo)
247 {
248     if (!_gbSEALInitialized)
249     {
250         SEAL_WARN("%s is called before init\n", __FUNCTION__);
251         return FALSE;
252     }
253 
254     MS_BOOL bret;
255 
256     pSecureRangeInfo->u8MiuDev = u8MiuDev;
257     pSecureRangeInfo->u8SecureRangeId = u8SecureRangeId;
258     bret = HAL_Seal_SecureRangeQuery(u8MiuDev,
259                                      u8SecureRangeId,
260                                      &(pSecureRangeInfo->u32Attribute),
261                                      &(pSecureRangeInfo->u64StartAddr),
262                                      &(pSecureRangeInfo->u64EndAddr));
263 
264     return bret;
265 }
266 
267 ////////////////////////////////////////////////////////////////////////////////
268 /// @brief \b Function       \b Name: MDrv_Seal_IMI_RangeSet
269 /// @brief \b Function       \b Description: set the secure range on internel memory interface
270 /// @param u32StartAddr      \b IN : Start address of secure range on IMI
271 /// @param u32EndAddr        \b IN : End address of secure range on IMI
272 /// @param bEnable           \b IN : Enable/Disable secure range on IMI
273 /// @param None              \b OUT :
274 /// @param MS_BOOL           \b RET
275 /// @param None              \b GLOBAL :
276 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_IMI_RangeSet(MS_U32 u32StartAddr,MS_U32 u32EndAddr,MS_BOOL bEnable)277 MS_BOOL MDrv_Seal_IMI_RangeSet(MS_U32 u32StartAddr, MS_U32 u32EndAddr, MS_BOOL bEnable)
278 {
279     if (!_gbSEALInitialized)
280     {
281         SEAL_WARN("%s is called before init\n", __FUNCTION__);
282         return FALSE;
283     }
284 
285     MS_BOOL bret;
286 
287     if(((u32StartAddr & (SEAL_IMI_RANGE_ALIGN -1)) != 0) || ((u32EndAddr & (SEAL_IMI_RANGE_ALIGN -1)) != 0))
288     {
289         SEAL_ERROR("IMI range address should be aligned to %lx\n",SEAL_IMI_RANGE_ALIGN);
290         bret = FALSE;
291         return bret;
292     }
293 
294     bret = HAL_Seal_IMI_RangeSet(u32StartAddr, u32EndAddr, bEnable);
295 
296     return bret;
297 }
298 
299 ////////////////////////////////////////////////////////////////////////////////
300 /// @brief \b Function       \b Name: MDrv_Seal_GetHittedInfo
301 /// @brief \b Function       \b Description: set the secure range on MIU
302 /// @param u8MiuDev          \b IN : 0:MIU0 1:MIU1 2:MIU2 3:MIU3
303 /// @param *pInfo            \b OUT : Hitted information
304 /// @param MS_BOOL           \b RET
305 /// @param None              \b GLOBAL :
306 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_GetHittedInfo(MS_U8 u8MiuDev,Seal_PortectInfo * pInfo)307 MS_BOOL MDrv_Seal_GetHittedInfo(MS_U8 u8MiuDev, Seal_PortectInfo *pInfo)
308 {
309     if (!_gbSEALInitialized)
310     {
311         SEAL_WARN("%s is called before init\n", __FUNCTION__);
312         return FALSE;
313     }
314 
315     MS_BOOL bret;
316 
317     if(u8MiuDev >= E_SEAL_MIU_NUM)
318     {
319         bret = FALSE;
320         return bret;
321     }
322 
323     pInfo->bIsHit = HAL_Seal_GetMiuHitFlag(u8MiuDev);
324     pInfo->u8MiuDev = u8MiuDev;
325     pInfo->u8SecureRangeId = HAL_Seal_GetMiuHitRangeID(u8MiuDev);
326     pInfo->u8ClientId = HAL_Seal_GetMiuHitClientID(u8MiuDev);
327     pInfo->bIsSecure = HAL_Seal_GetMiuSecureFlag(u8MiuDev);
328     pInfo->bIsWrite = HAL_Seal_GetMiuWriteFlag(u8MiuDev);
329     pInfo->u64HitAddr = HAL_Seal_GetMiuHitAddr(u8MiuDev);
330 
331     HAL_Seal_ClearMiuHitLog(u8MiuDev);
332 
333     if(pInfo->bIsHit == TRUE)
334     {
335         SEAL_PRINT("MIU:%u SecureRangeId:%u ClientId:0x%x IsSecure:%u IsWrite:%u HitAddr:0x%llx\n", u8MiuDev,
336                    pInfo->u8SecureRangeId, pInfo->u8ClientId, pInfo->bIsSecure, pInfo->bIsWrite, (long long unsigned)pInfo->u64HitAddr);
337     }
338 
339     return TRUE;
340 }
341 
342 ////////////////////////////////////////////////////////////////////////////////
343 /// @brief \b Function       \b Name: MDrv_Seal_SecureRangeLock
344 /// @brief \b Function       \b Description: One-way setting to lock the specific secure range
345 /// @param u8MiuDev          \b IN : 0: MIU0 1:MIU1
346 /// @param u8SecureRangeId:  \b IN : Secure range ID
347 /// @param None              \b OUT :
348 /// @param MS_BOOL           \b RET
349 /// @param None              \b GLOBAL :
350 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_SecureRangeLock(MS_U8 u8MiuDev,MS_U8 u8SecureRangeId)351 MS_BOOL MDrv_Seal_SecureRangeLock(MS_U8 u8MiuDev, MS_U8 u8SecureRangeId)
352 {
353     if (!_gbSEALInitialized)
354     {
355         SEAL_WARN("%s is called before init\n", __FUNCTION__);
356         return FALSE;
357     }
358 
359     MS_BOOL bret;
360 
361     if(u8MiuDev >= E_SEAL_MIU_NUM)
362     {
363         bret = FALSE;
364         return bret;
365     }
366 
367     bret = HAL_Seal_SecureRangeLock(u8MiuDev, u8SecureRangeId);
368 
369     return bret;
370 }
371 
372 ////////////////////////////////////////////////////////////////////////////////
373 /// @brief \b Function       \b Name: MDrv_Seal_NonSecureProcessorSet
374 /// @brief \b Function       \b Description: Define the specific processor be secure or not
375 /// @param ProcessorId       \b IN : Processor ID
376 /// @param bSecure:          \b IN : 1: non-secure 0:secure
377 /// @param None              \b OUT :
378 /// @param MS_BOOL           \b RET
379 /// @param None              \b GLOBAL :
380 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_NonSecureProcessorSet(MS_U8 u8ProcessorId,MS_BOOL bNonSecure)381 MS_BOOL MDrv_Seal_NonSecureProcessorSet(MS_U8 u8ProcessorId, MS_BOOL bNonSecure)
382 {
383     if (!_gbSEALInitialized)
384     {
385         SEAL_WARN("%s is called before init\n", __FUNCTION__);
386         return FALSE;
387     }
388 
389     MS_BOOL bret;
390 
391     if(u8ProcessorId >= E_SEAL_PROCESSOR_NUM)
392     {
393         bret = FALSE;
394         return bret;
395     }
396 
397     bret = HAL_Seal_NonSecureProcessorSet(u8ProcessorId, bNonSecure);
398 
399     return bret;
400 }
401 
402 ////////////////////////////////////////////////////////////////////////////////
403 /// @brief \b Function       \b Name: MDrv_Seal_NonSecureProcessorQuery
404 /// @brief \b Function       \b Description: Query specific processor be secure or not
405 /// @param ProcessorId       \b IN : Processor ID
406 /// @param bSecure:          \b OUT : 1: non-secure 0:secure
407 /// @param MS_BOOL           \b RET
408 /// @param None              \b GLOBAL :
409 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_NonSecureProcessorQuery(MS_U8 u8ProcessorId,MS_BOOL * pNonSecure)410 MS_BOOL MDrv_Seal_NonSecureProcessorQuery(MS_U8 u8ProcessorId, MS_BOOL *pNonSecure)
411 {
412     if (!_gbSEALInitialized)
413     {
414         SEAL_WARN("%s is called before init\n", __FUNCTION__);
415         return FALSE;
416     }
417 
418     MS_BOOL bret;
419 
420     if(u8ProcessorId >= E_SEAL_PROCESSOR_NUM)
421     {
422         bret = FALSE;
423         return bret;
424     }
425 
426     bret = HAL_Seal_NonSecureProcessorQuery(u8ProcessorId, pNonSecure);
427 
428     return bret;
429 }
430 
431 ////////////////////////////////////////////////////////////////////////////////
432 /// @brief \b Function       \b Name: MDrv_Seal_SecureSlaveSet
433 /// @brief \b Function       \b Description: Define the specific slave IP be secure or not
434 /// @param u32SlaveId        \b IN : Slave ID
435 /// @param bSecure:          \b IN : 0: non-secure 1:secure
436 /// @param None              \b OUT :
437 /// @param MS_BOOL           \b RET
438 /// @param None              \b GLOBAL :
439 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_SecureSlaveSet(MS_U32 u32SlaveId,MS_BOOL bSecure)440 MS_BOOL MDrv_Seal_SecureSlaveSet(MS_U32 u32SlaveId, MS_BOOL bSecure)
441 {
442     if (!_gbSEALInitialized)
443     {
444         SEAL_WARN("%s is called before init\n", __FUNCTION__);
445         return FALSE;
446     }
447 
448     MS_BOOL bret;
449 
450     bret = HAL_Seal_SecureSlaveSet(u32SlaveId, bSecure);
451 
452     return bret;
453 }
454 
455 ////////////////////////////////////////////////////////////////////////////////
456 /// @brief \b Function       \b Name: MDrv_Seal_SecureSlaveQuery
457 /// @brief \b Function       \b Description: Query the specific slave IP be secure or not
458 /// @param u32SlaveId        \b IN : Slave ID
459 /// @param pSecure:          \b OUT : 0: non-secure 1:secure
460 /// @param None              \b OUT :
461 /// @param MS_BOOL           \b RET
462 /// @param None              \b GLOBAL :
463 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_SecureSlaveQuery(MS_U32 u32SlaveId,MS_BOOL * pSecure)464 MS_BOOL MDrv_Seal_SecureSlaveQuery(MS_U32 u32SlaveId, MS_BOOL *pSecure)
465 {
466     if (!_gbSEALInitialized)
467     {
468         SEAL_WARN("%s is called before init\n", __FUNCTION__);
469         return FALSE;
470     }
471 
472     MS_BOOL bret;
473 
474     bret = HAL_Seal_SecureSlaveQuery(u32SlaveId, pSecure);
475 
476     return bret;
477 }
478 
479 ////////////////////////////////////////////////////////////////////////////////
480 /// @brief \b Function       \b Name: MDrv_Seal_SecureMasterSet
481 /// @brief \b Function       \b Description: Define the specific master IP be secure or not
482 /// @param u32MasterId  \b IN : Master ID
483 /// @param bSecure:          \b IN : 0: non-secure 1:secure
484 /// @param None              \b OUT :
485 /// @param MS_BOOL           \b RET
486 /// @param None              \b GLOBAL :
487 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_SecureMasterSet(MS_U32 u32MasterId,MS_BOOL bSecure)488 MS_BOOL MDrv_Seal_SecureMasterSet(MS_U32 u32MasterId, MS_BOOL bSecure)
489 {
490     if (!_gbSEALInitialized)
491     {
492         SEAL_WARN("%s is called before init\n", __FUNCTION__);
493         return FALSE;
494     }
495 
496     MS_BOOL bret;
497 
498     bret = HAL_Seal_SecureMasterSet(u32MasterId, bSecure);
499 
500     return bret;
501 }
502 
503 ////////////////////////////////////////////////////////////////////////////////
504 /// @brief \b Function       \b Name: MDrv_Seal_SecureMasterQuery
505 /// @brief \b Function       \b Description: Query the specific master IP be secure or not
506 /// @param u32MasterId  \b IN : Master ID
507 /// @param pSecure:          \b OUT : 0: non-secure 1:secure
508 /// @param None              \b OUT :
509 /// @param MS_BOOL           \b RET
510 /// @param None              \b GLOBAL :
511 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_SecureMasterQuery(MS_U32 u32MasterId,MS_BOOL * pSecure)512 MS_BOOL MDrv_Seal_SecureMasterQuery(MS_U32 u32MasterId, MS_BOOL *pSecure)
513 {
514     if (!_gbSEALInitialized)
515     {
516         SEAL_WARN("%s is called before init\n", __FUNCTION__);
517         return FALSE;
518     }
519 
520     MS_BOOL bret;
521 
522     bret = HAL_Seal_SecureMasterQuery(u32MasterId, pSecure);
523 
524     return bret;
525 }
526 
527 ////////////////////////////////////////////////////////////////////////////////
528 /// @brief \b Function       \b Name: MDrv_Seal_SetPowerState
529 /// @brief \b Function       \b Description: STR rountine
530 /// @param u16PowerState  \b IN : Power state
531 /// @param None              \b OUT :
532 /// @param MS_BOOL           \b RET :
533 /// @param None              \b GLOBAL :
534 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_SetPowerState(EN_POWER_MODE u16PowerState)535 MS_U32 MDrv_Seal_SetPowerState(EN_POWER_MODE u16PowerState)
536 {
537     static EN_POWER_MODE _prev_u16PowerState = E_POWER_MECHANICAL;
538     MS_U32 u32Return = FALSE;
539 
540     if (u16PowerState == E_POWER_SUSPEND)
541     {
542         _prev_u16PowerState = u16PowerState;
543         _gbSEALInitialized = FALSE;
544         HAL_SEAL_POWER_SUSPEND();
545         u32Return = UTOPIA_STATUS_SUCCESS;//SUSPEND_OK;
546     }
547     else if (u16PowerState == E_POWER_RESUME)
548     {
549         if (_prev_u16PowerState == E_POWER_SUSPEND)
550         {
551             MDrv_SEAL_Init();
552             HAL_SEAL_POWER_RESUME();
553             _prev_u16PowerState = u16PowerState;
554             u32Return = UTOPIA_STATUS_SUCCESS;//RESUME_OK;
555         }
556         else
557         {
558             ULOGE(TAG_SEAL, "[%s,%5d]It is not suspended yet. We shouldn't resume\n",__FUNCTION__,__LINE__);
559             u32Return = UTOPIA_STATUS_FAIL;//SUSPEND_FAILED;
560         }
561     }
562     else
563     {
564         ULOGE(TAG_SEAL, "[%s,%5d]Do Nothing: %d\n",__FUNCTION__,__LINE__,u16PowerState);
565         u32Return = UTOPIA_STATUS_FAIL;
566     }
567 
568     return u32Return;// for success
569 }
570 
571 ////////////////////////////////////////////////////////////////////////////////
572 /// @brief \b Function       \b Name: MDrv_Seal_BufferLock
573 /// @brief \b Function       \b Description: Lock the specific buffer
574 /// @param <IN>              \b u8SecureRangeId: Secure buffer ID
575 /// @param <IN>              \b bLock: 0: unlock 1:lock
576 /// @param None              \b OUT :
577 /// @param MS_BOOL           \b RET
578 /// @param None              \b GLOBAL :
579 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_BufferLock(MS_U8 u8BufferLockId,MS_BOOL bLock)580 MS_BOOL MDrv_Seal_BufferLock(MS_U8 u8BufferLockId, MS_BOOL bLock)
581 {
582     if (!_gbSEALInitialized)
583     {
584         SEAL_WARN("%s is called before init\n", __FUNCTION__);
585         return FALSE;
586     }
587 
588     MS_BOOL bret;
589 
590     bret = HAL_Seal_BufferLock(u8BufferLockId, bLock);
591 
592     return bret;
593 }
594 
595 
596 #if !defined(CONFIG_FRC)
597 ////////////////////////////////////////////////////////////////////////////////
598 /// @brief \b Function       \b Name: MDrv_Seal_ClearInterruptFlag
599 /// @brief \b Function       \b Description: Static function ,Clear  miu0/miu1 interrupt flag
600 /// @param void  \b IN : void:
601 /// @param None              \b OUT :
602 /// @param MS_BOOL           \b RET :
603 /// @param None              \b GLOBAL :
604 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_ClearInterruptFlag(void)605 static void  MDrv_Seal_ClearInterruptFlag(void)
606 {
607 	HAL_Seal_ClearMiuHitLog(E_SEAL_MIU_DEV0);
608 	HAL_Seal_ClearMiuHitLog(E_SEAL_MIU_DEV1);
609 	HAL_Seal_ClearMiuHitLog(E_SEAL_MIU_DEV2);
610 	HAL_Seal_ClearMiuHitLog(E_SEAL_MIU_DEV3);
611 }
612 
613 ////////////////////////////////////////////////////////////////////////////////
614 /// @brief \b Function       \b Name: MDrv_Seal_MaskInterruptFlag
615 /// @brief \b Function       \b Description: Static function , Mask/UnMask miu0/miu1 interrupt bit
616 /// @param bMask  \b IN : bMask:True, Mask seal interrupt bit for not trigger interrupt; False, Unmaks seal interrupt bit for trigger interrupt
617 /// @param None              \b OUT :
618 /// @param MS_BOOL           \b RET :
619 /// @param None              \b GLOBAL :
620 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_MaskInterruptFlag(MS_BOOL bMask)621 static void MDrv_Seal_MaskInterruptFlag(MS_BOOL bMask)
622 {
623 	HAL_Seal_MaskInterruptFlag(E_SEAL_MIU_DEV0, bMask);
624 	HAL_Seal_MaskInterruptFlag(E_SEAL_MIU_DEV1, bMask);
625 	HAL_Seal_MaskInterruptFlag(E_SEAL_MIU_DEV2, bMask);
626 	HAL_Seal_MaskInterruptFlag(E_SEAL_MIU_DEV3, bMask);
627 }
628 #endif
629 
630 ////////////////////////////////////////////////////////////////////////////////
631 /// @brief \b Function       \b Name: MDrv_Seal_isr
632 /// @brief \b Function       \b Description:Static function , While Seal interrupt trigger, this function is handled
633 /// @param eIntNum  \b eIntNum : interrupt vector number
634 /// @param None              \b OUT :
635 /// @param MS_BOOL           \b RET :
636 /// @param None              \b GLOBAL :
637 ////////////////////////////////////////////////////////////////////////////////
638 #ifdef MSOS_TYPE_LINUX_KERNEL
MDrv_Seal_isr(InterruptNum eIntNum,void * dev_id)639 irqreturn_t MDrv_Seal_isr(InterruptNum eIntNum, void* dev_id)
640 #else
641 void MDrv_Seal_isr(InterruptNum eIntNum )
642 #endif
643 {
644 	Seal_PortectInfo sPInfo_miu0;
645 	Seal_PortectInfo sPInfo_miu1;
646 
647 	if (_pSEALCbFunc != NULL)
648 	{
649 		_pSEALCbFunc(eIntNum);
650 	}
651     else
652     {
653 	    MDrv_Seal_GetHittedInfo(E_SEAL_MIU_DEV0, &sPInfo_miu0);
654 	    MDrv_Seal_GetHittedInfo(E_SEAL_MIU_DEV1, &sPInfo_miu1);
655 	    MDrv_Seal_GetHittedInfo(E_SEAL_MIU_DEV2, &sPInfo_miu1);
656 	    MDrv_Seal_GetHittedInfo(E_SEAL_MIU_DEV3, &sPInfo_miu1);
657     }
658 
659 	#if !defined(CONFIG_FRC)
660 	MDrv_Seal_ClearInterruptFlag();
661 	MsOS_EnableInterrupt(E_INT_IRQ_MIU_SECURITY);
662 	#endif
663 }
664 
665 
666 ////////////////////////////////////////////////////////////////////////////////
667 /// @brief \b Function       \b Name: MDrv_Seal_ENInterrupt
668 /// @brief \b Function       \b Description: Enable/Disable SEAL interrupt
669 /// @param bEnable  \b IN : bEnable: True: Enable SEAL interrupt; False:Diable SEAL interrupt
670 /// @param None              \b OUT :
671 /// @param MS_BOOL           \b RET :
672 /// @param None              \b GLOBAL :
673 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_ENInterrupt(MS_BOOL bEnable)674 MS_BOOL MDrv_Seal_ENInterrupt(MS_BOOL bEnable)
675 {
676     if (!_gbSEALInitialized)
677     {
678         SEAL_WARN("%s is called before init\n", __FUNCTION__);
679         return FALSE;
680     }
681 
682 #if !defined(CONFIG_FRC)
683 	if (bEnable == TRUE)
684 	{
685 		MsOS_AttachInterrupt(E_INT_IRQ_MIU_SECURITY, MDrv_Seal_isr);
686 		MDrv_Seal_ClearInterruptFlag();
687 		MDrv_Seal_MaskInterruptFlag(FALSE);
688 		MsOS_EnableInterrupt(E_INT_IRQ_MIU_SECURITY);
689 	}
690 	else
691 	{
692 		MDrv_Seal_MaskInterruptFlag(TRUE);
693 		MDrv_Seal_ClearInterruptFlag();
694 		MsOS_DisableInterrupt(E_INT_IRQ_MIU_SECURITY);
695 		MsOS_DetachInterrupt(E_INT_IRQ_MIU_SECURITY);
696 	}
697 #endif
698 	return TRUE;
699 }
700 
701 ////////////////////////////////////////////////////////////////////////////////
702 /// @brief \b Function       \b Name: MDrv_Seal_AttachCallbackFunc
703 /// @brief \b Function       \b Description: Attach user call back function
704 /// @param void  \b IN : void
705 /// @param None              \b OUT :
706 /// @param MS_BOOL           \b RET :
707 /// @param None              \b GLOBAL :
708 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_AttachCallbackFunc(SEAL_CB_FUNC pSEALCBFunc)709 MS_BOOL MDrv_Seal_AttachCallbackFunc(SEAL_CB_FUNC pSEALCBFunc)
710 {
711 	_pSEALCbFunc = pSEALCBFunc;
712 	return TRUE;
713 }
714 
715 ////////////////////////////////////////////////////////////////////////////////
716 /// @brief \b Function       \b Name: MDrv_Seal_DispatchCallbackFunc
717 /// @brief \b Function       \b Description: Dispatch user call back function
718 /// @param void  \b IN : void
719 /// @param None              \b OUT :
720 /// @param MS_BOOL           \b RET :
721 /// @param None              \b GLOBAL :
722 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_DispatchCallbackFunc(void)723 MS_BOOL MDrv_Seal_DispatchCallbackFunc(void)
724 {
725 	_pSEALCbFunc = NULL;
726 	return TRUE;
727 }
728 
729 ////////////////////////////////////////////////////////////////////////////////
730 /// @brief \b Function       \b Name: MDrv_Seal_CheckSecureRange
731 /// @brief \b Function       \b Description: Is Overlap Secure Range
732 /// @param phyStartAddr      \b IN : start addr
733 /// @param u32Length         \b IN : prtect length
734 /// @param eCheckSecureRangeType     \b IN : check Overlap Type
735 /// @param None              \b OUT :
736 /// @param MS_BOOL           \b RET :
737 /// @param None              \b GLOBAL :
738 ////////////////////////////////////////////////////////////////////////////////
MDrv_Seal_CheckSecureRange(MS_PHY phyStartAddr,MS_U32 u32Length,eSeal_CheckSecureRangeType eCheckSecureRangeType)739 MS_BOOL MDrv_Seal_CheckSecureRange(MS_PHY phyStartAddr, MS_U32 u32Length, eSeal_CheckSecureRangeType eCheckSecureRangeType)
740 {
741     return HAL_Seal_CheckSecureRange(phyStartAddr, u32Length, eCheckSecureRangeType);
742 }
743 
MDrv_Seal_QueryBufferLocked(eSeal_Lock eLockId,MS_BOOL * bLocked)744 MS_BOOL MDrv_Seal_QueryBufferLocked(eSeal_Lock eLockId, MS_BOOL* bLocked)
745 {
746     return HAL_Seal_QueryBufferLocked(eLockId, bLocked);
747 }
748 
749 #ifdef MSOS_TYPE_OPTEE
MDrv_Seal_ChangeIPSecureDMAAbillity(MS_U32 u32ModuleID,MS_U32 u32ModuleParameter,MS_U32 u32IsSecure)750 MS_BOOL MDrv_Seal_ChangeIPSecureDMAAbillity(MS_U32 u32ModuleID, MS_U32 u32ModuleParameter, MS_U32 u32IsSecure)
751 {
752     return HAL_Seal_ChangeIPSecureDMAAbillity(u32ModuleID, u32ModuleParameter, u32IsSecure);
753 }
754 
MDrv_Seal_SetSecureRange(MS_PHY u64phy,MS_U32 u32Length,MS_U32 u32IsSecure)755 MS_BOOL MDrv_Seal_SetSecureRange(MS_PHY u64phy, MS_U32 u32Length, MS_U32 u32IsSecure)
756 {
757     return HAL_Seal_SetSecureRange(u64phy, u32Length, u32IsSecure);
758 }
759 #endif
760