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 #define _DRVNSK2_C
94
95 ////////////////////////////////////////////////////////////////////////////////
96 /// file drvNSK2.c
97 /// @author MStar Semiconductor Inc.
98 /// @brief
99 ////////////////////////////////////////////////////////////////////////////////
100 //------------------------------------------------------------------------------
101 // Header Files
102 //------------------------------------------------------------------------------
103 #ifdef MSOS_TYPE_LINUX_KERNEL
104 #include <linux/string.h>
105 #else
106 #include "string.h"
107 #endif
108
109 #include "MsCommon.h"
110 #include "MsVersion.h"
111 #include "drvMMIO.h"
112 #include "MsOS.h"
113 #include "asmCPU.h"
114 #include "halCHIP.h"
115
116 #include "drvNSK2.h"
117 #include "halNSK2.h"
118 #include "drvNSK2Type.h"
119
120
121 ////////////////////////////////////////////////////////////////////////////////
122 // Local defines & local structures
123 ////////////////////////////////////////////////////////////////////////////////
124
125 static MS_U32 _g32NSK2DbgLv = NSK2_DBGLV_DEBUG;
126
127 #define DRVNSK2_DBG(lv, x, args...) if (lv <= _g32NSK2DbgLv ) \
128 {printf(x, ##args);}
129
130 #define NSK2_TASK_STACK_SIZE 16*1024
131
132 #define NDS_NSK2_IRQ E_INT_IRQ_CA_NSK_INT
133
134 #define NSK2_INT_EVENT_0 0x00000001
135 #define NSK2_INT_GROUP 0x0000FFFF
136
137 //#define ACPUTest
138 ////////////////////////////////////////////////////////////////////////////////
139 // Local Variables
140 ////////////////////////////////////////////////////////////////////////////////
141 static MS_U32 u32NSK2_Stack[NSK2_TASK_STACK_SIZE/sizeof(MS_U32)];
142 static MS_S32 s32NSK2_TaskId = -1;
143 static MS_S32 s32NSK2_EventId = -1;
144
145 static MS_BOOL _bNSKInit = FALSE;
146 static NSK2_IntNotify _gNs2IntNtf = NULL;
147
148 #ifdef ACPUTest
149 static MS_U32 u32NSK2IntStatus = 0;
150 #endif
151
152 ////////////////////////////////////////////////////////////////////////////////
153 // Global Variables
154 ////////////////////////////////////////////////////////////////////////////////
155
156
157 ////////////////////////////////////////////////////////////////////////////////
158 // External funciton
159 ////////////////////////////////////////////////////////////////////////////////
160
161
162 ////////////////////////////////////////////////////////////////////////////////
163 // Local Function
164 ////////////////////////////////////////////////////////////////////////////////
165
_NSK2_Isr(void)166 static void _NSK2_Isr(void)
167 {
168 MS_U32 status;
169 //MsOS_DisableInterrupt(NDS_NSK2_IRQ);
170
171 status = HAL_NSK2_GetIntStatus();
172 #ifdef ACPUTest
173 u32NSK2IntStatus = status;
174 //printf("_NSK2_Isr, status = %x time = %d\n",u32NSK2IntStatus,MsOS_GetSystemTime());
175 #else
176 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"_NSK2_Isr, status = %x\n",status);
177 HAL_NSK2_ClearInt(status);
178 MsOS_SetEvent(s32NSK2_EventId, status);
179 #endif
180 }
181
_NSK2_Isr_Task(void)182 static void _NSK2_Isr_Task(void)
183 {
184 MS_U32 u32Reg;
185 MS_U32 u32Events = 0;
186
187 while(1)
188 {
189 MsOS_WaitEvent(s32NSK2_EventId, NSK2_INT_GROUP, &u32Events, E_OR_CLEAR, MSOS_WAIT_FOREVER);
190
191 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"s32NSK2_EventId = %d\n",s32NSK2_EventId);
192 u32Reg = u32Events;
193 if (NSK2_INT_ASYNC_EVENT != u32Reg) //because frequent int's for this event
194 {
195 if(_gNs2IntNtf != NULL)
196 {
197 _gNs2IntNtf(u32Reg, 0);
198 }
199 }
200
201 MsOS_DelayTask(1);
202 MsOS_EnableInterrupt(NDS_NSK2_IRQ);
203 }
204 }
205
206
207 ////////////////////////////////////////////////////////////////////////////////
208 // Global Function
209 ////////////////////////////////////////////////////////////////////////////////
210
211
MDrv_NSK2_Init(void)212 MS_U32 MDrv_NSK2_Init(void)
213 {
214 //init clock, register bank
215 MS_VIRT u32Base;
216 MS_PHY u32BankSize;
217
218 if(TRUE == _bNSKInit)
219 return TRUE;
220
221 DRVNSK2_DBG(NSK2_DBGLV_INFO,"enter %s \n", __FUNCTION__);
222
223 if (FALSE == MDrv_MMIO_GetBASE(&u32Base, &u32BankSize, MS_MODULE_PM))
224 {
225 DRVNSK2_DBG(NSK2_DBGLV_EMERG,"%s, %d MDrv_MMIO_GetBASE (NonPM base)fail\n", __FUNCTION__,__LINE__);
226 MS_ASSERT(0);
227 }
228
229 HAL_NSK2_SetBase((MS_U32)u32Base); //set non pm bank
230
231
232 s32NSK2_EventId = MsOS_CreateEventGroup("NDS_NSK2_Event");
233 if (s32NSK2_EventId < 0)
234 {
235 return FALSE;
236 }
237
238 s32NSK2_TaskId = MsOS_CreateTask((TaskEntry)_NSK2_Isr_Task,
239 (MS_U32)NULL,
240 E_TASK_PRI_HIGH,
241 TRUE,
242 u32NSK2_Stack,
243 NSK2_TASK_STACK_SIZE,
244 "NDS_NSK2_Task");
245 if (s32NSK2_TaskId < 0)
246 {
247 MsOS_DeleteEventGroup(s32NSK2_EventId);
248 return FALSE;
249 }
250
251 MsOS_DisableInterrupt(NDS_NSK2_IRQ);
252 MsOS_DetachInterrupt(NDS_NSK2_IRQ);
253 MsOS_AttachInterrupt(NDS_NSK2_IRQ, (InterruptCb)_NSK2_Isr);
254 MsOS_EnableInterrupt(NDS_NSK2_IRQ);
255
256 _bNSKInit = TRUE;
257 return TRUE;
258 }
259
MDrv_NSK2_Exit(void)260 MS_U32 MDrv_NSK2_Exit(void)
261 {
262 return HAL_NSK2_Exit();
263 }
264
MDrv_NSK2_CtrlInt(MS_BOOL bEnable)265 MS_U32 MDrv_NSK2_CtrlInt(MS_BOOL bEnable)
266 {
267 if(TRUE == bEnable)
268 {
269 MsOS_EnableInterrupt(NDS_NSK2_IRQ);
270 }
271 else
272 {
273 MsOS_DisableInterrupt(NDS_NSK2_IRQ);
274 }
275
276 return TRUE;
277 }
278
MDrv_NSK2_ColdReset(void)279 MS_U32 MDrv_NSK2_ColdReset(void)
280 {
281 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
282 HAL_NSK2_ColdReset();
283 return TRUE;
284 }
285
MDrv_NSK2_EndSubtest(void)286 MS_U32 MDrv_NSK2_EndSubtest(void)
287 {
288 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
289 HAL_NSK2_EndSubtest();
290 return TRUE;
291 }
292
293
MDrv_NSK2_Compare(MS_U32 StartAddr,MS_U32 CompareLens,MS_U32 CompareSim,MS_U32 Mask,MS_U32 ExpectResult)294 MS_U32 MDrv_NSK2_Compare(MS_U32 StartAddr, MS_U32 CompareLens, MS_U32 CompareSim,
295 MS_U32 Mask, MS_U32 ExpectResult)
296 {
297 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
298
299 #ifdef ACPUTest
300 if(0xFC08 == StartAddr)
301 {
302 MS_U32 status;
303 status = HAL_NSK2_Compare(StartAddr, CompareLens, CompareSim, Mask, ExpectResult);
304 HAL_NSK2_ClearInt(ExpectResult);
305 MsOS_EnableInterrupt(NDS_NSK2_IRQ);
306 return status;
307 }
308 else
309 return HAL_NSK2_Compare(StartAddr, CompareLens, CompareSim, Mask, ExpectResult);
310 #else
311 return HAL_NSK2_Compare(StartAddr, CompareLens, CompareSim, Mask, ExpectResult);
312 #endif
313
314
315 }
316
MDrv_NSK2_CompareMem(MS_U32 reserved,MS_U32 StartAddr,MS_U32 CompareLens,MS_U32 CompareSim,MS_U32 ExpectResult,void * pGolden)317 MS_U32 MDrv_NSK2_CompareMem(MS_U32 reserved, MS_U32 StartAddr, MS_U32 CompareLens,
318 MS_U32 CompareSim, MS_U32 ExpectResult, void *pGolden)
319 {
320 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
321 return HAL_NSK2_CompareMem(reserved, StartAddr, CompareLens, CompareSim, ExpectResult, pGolden);
322 }
323
MDrv_NSK2_WriteMem(MS_U32 reserved,MS_U32 StartAddr,MS_U32 WriteLens,void * pWriteData)324 MS_U32 MDrv_NSK2_WriteMem(MS_U32 reserved, MS_U32 StartAddr, MS_U32 WriteLens, void *pWriteData)
325 {
326 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
327 HAL_NSK2_WriteMem(reserved,StartAddr,WriteLens,pWriteData);
328 return TRUE;
329 }
330
331
MDrv_NSK2_WriteSFR(MS_U32 StartAddr,MS_U32 Data)332 MS_U32 MDrv_NSK2_WriteSFR(MS_U32 StartAddr, MS_U32 Data)
333 {
334 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
335 HAL_NSK2_WriteSFR(StartAddr, Data);
336 return TRUE;
337 }
338
MDrv_NSK2_BasicInitializationComplete(void)339 MS_U32 MDrv_NSK2_BasicInitializationComplete(void)
340 {
341 //the chip should manager internal variables NSKactive and ConcurrencyMode
342 DRVNSK2_DBG(NSK2_DBGLV_INFO,"%s \n", __FUNCTION__);
343
344 HAL_NSK2_NSKBasicInitializationComplete();
345 return TRUE;
346 }
347
MDrv_NSK2_WriteESA(MS_U8 ESASelect,MS_U8 ESASubSelect,MS_U8 pid_no)348 MS_U32 MDrv_NSK2_WriteESA(MS_U8 ESASelect, MS_U8 ESASubSelect, MS_U8 pid_no)
349 {
350 DRVNSK2_DBG(NSK2_DBGLV_INFO,"%s \n", __FUNCTION__);
351
352 HAL_NSK2_WriteESA(ESASelect, ESASubSelect, pid_no);
353 return TRUE;
354
355 }
356
MDrv_NSK2_WriteTransportKey(MS_U8 SCB,MS_U8 ForceSCB,void * pLabel,MS_U8 pid_no)357 MS_U32 MDrv_NSK2_WriteTransportKey(MS_U8 SCB, MS_U8 ForceSCB, void *pLabel, MS_U8 pid_no )
358 {
359 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
360
361 DRVNSK2_DBG(NSK2_DBGLV_INFO,"SCB = %x, ForceSCB = %x\n",SCB,ForceSCB);
362
363
364 HAL_NSK2_WriteTransportKey(SCB,ForceSCB,pLabel,pid_no);
365 return TRUE;
366 }
367
MDrv_NSK2_CompareKTE(MS_U32 reserved_1,MS_U32 reserved_2,void * pLabel)368 MS_U32 MDrv_NSK2_CompareKTE(MS_U32 reserved_1, MS_U32 reserved_2, void *pLabel)
369 {
370 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
371 return HAL_NSK2_CompareKTE(reserved_1, reserved_2, pLabel);
372 }
373
MDrv_NSK2_CompareOut(MS_U32 reserved_1,MS_U32 reserved_2,MS_U32 HighDWord,MS_U32 LowDWord)374 MS_U32 MDrv_NSK2_CompareOut(MS_U32 reserved_1, MS_U32 reserved_2, MS_U32 HighDWord, MS_U32 LowDWord)
375 {
376 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
377
378 return HAL_NSK2_CompareOut( reserved_1, reserved_2, HighDWord, LowDWord);
379 }
380
MDrv_NSK2_SetRNG(MS_U32 reserved_1,MS_U16 RNG_Value)381 MS_U32 MDrv_NSK2_SetRNG(MS_U32 reserved_1, MS_U16 RNG_Value)
382 {
383 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
384
385 HAL_NSK2_SetRNG( reserved_1, RNG_Value);
386 return TRUE;
387 }
388
389
MDrv_NSK2_DriveKteAck(void)390 MS_U32 MDrv_NSK2_DriveKteAck(void)
391 {
392 DRVNSK2_DBG(NSK2_DBGLV_INFO,"%s \n", __FUNCTION__);
393 HAL_NSK2_DriveKteAck();
394 return TRUE;
395 }
396
MDrv_NSK2_WriteSCPUKey(void)397 MS_U32 MDrv_NSK2_WriteSCPUKey(void)
398 {
399 return HAL_NSK2_WriteSCPUKey();
400 }
401
MDrv_NSK2_WriteReservedKey(void)402 MS_U32 MDrv_NSK2_WriteReservedKey(void)
403 {
404 return HAL_NSK2_WriteReservedKey();
405 }
406
MDrv_NSK2_GetReserveKeyNum(void)407 MS_U32 MDrv_NSK2_GetReserveKeyNum(void)
408 {
409 return HAL_NSK2_GetReserveKeyNum();
410 }
411
MDrv_NSK2_WriteM2MKey(void * pIV,MS_U8 SubAlgo)412 MS_U32 MDrv_NSK2_WriteM2MKey(void *pIV, MS_U8 SubAlgo)
413 {
414 DRVNSK2_DBG(NSK2_DBGLV_INFO,"%s, SubAlgo = %x \n", __FUNCTION__,SubAlgo);
415
416 //can't find the algorithm meaning
417 HAL_NSK2_WriteM2MKey(pIV,SubAlgo);
418 return TRUE;
419 }
420
421 // TODO: need to remove and check by MW
MDrv_NSK2_FillJTagPswd(void)422 MS_U32 MDrv_NSK2_FillJTagPswd(void)
423 {
424 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
425 HAL_NSK2_SetJTagPswd();
426 return TRUE;
427 }
428
429 // TODO: need to remove and check by MW
MDrv_NSK2_CheckPubOTPConfig(void * pCheck)430 MS_U32 MDrv_NSK2_CheckPubOTPConfig(void *pCheck)
431 {
432 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
433 return HAL_NSK2_CheckPubOTPConfig(pCheck);
434 }
435
436 // TODO:Check OTP control password here
MDrv_NSK2_UnlockOTPCtrl(void)437 MS_U32 MDrv_NSK2_UnlockOTPCtrl(void)
438 {
439 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
440 HAL_NSK2_UnlockOTPCtrl();
441 return TRUE;
442 }
443
444
MDrv_NSK2_ReadData(MS_U32 addr_offset,MS_U32 data_size,MS_U8 * data)445 MS_U32 MDrv_NSK2_ReadData(MS_U32 addr_offset, MS_U32 data_size, MS_U8 *data)
446 {
447 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
448 return HAL_NSK2_ReadData(addr_offset, data_size, data);
449 }
450
MDrv_NSK2_WriteData(MS_U32 addr_offset,MS_U32 data_size,MS_U8 * data)451 MS_U32 MDrv_NSK2_WriteData(MS_U32 addr_offset, MS_U32 data_size, MS_U8 *data)
452 {
453 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
454 return HAL_NSK2_WriteData(addr_offset, data_size, data);
455 }
456
MDrv_NSK2_ReadData8(MS_U32 addr_offset,MS_U32 data_size,MS_U8 * data)457 MS_U32 MDrv_NSK2_ReadData8(MS_U32 addr_offset, MS_U32 data_size, MS_U8 *data)
458 {
459 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
460 return HAL_NSK2_ReadData8(addr_offset, data_size, data);
461 }
462
MDrv_NSK2_WriteData8(MS_U32 addr_offset,MS_U32 data_size,MS_U8 * data)463 MS_U32 MDrv_NSK2_WriteData8(MS_U32 addr_offset, MS_U32 data_size, MS_U8 *data)
464 {
465 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
466 return HAL_NSK2_WriteData8(addr_offset, data_size, data);
467 }
468
MDrv_NSK2_ReadData32(MS_U32 addr_offset,MS_U32 data_size,MS_U32 * data)469 MS_U32 MDrv_NSK2_ReadData32(MS_U32 addr_offset, MS_U32 data_size, MS_U32 *data)
470 {
471 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
472 return HAL_NSK2_ReadData32(addr_offset, data_size, data);
473 }
474
MDrv_NSK2_WriteData32(MS_U32 addr_offset,MS_U32 data_size,MS_U32 * data)475 MS_U32 MDrv_NSK2_WriteData32(MS_U32 addr_offset, MS_U32 data_size, MS_U32 *data)
476 {
477 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
478 return HAL_NSK2_WriteData32(addr_offset, data_size, data);
479 }
480
481
MDrv_NSK2_SetIntNotify(NSK2_IntNotify IntNotify)482 MS_U32 MDrv_NSK2_SetIntNotify(NSK2_IntNotify IntNotify)
483 {
484 _gNs2IntNtf = IntNotify;
485 return TRUE;
486 }
487
488
MDrv_NSK2_ExcuteCmd(MS_U32 command,MS_U32 control,MS_U32 register_offset,MS_U32 data_size,const MS_U8 * data)489 MS_U32 MDrv_NSK2_ExcuteCmd(MS_U32 command, MS_U32 control,
490 MS_U32 register_offset, MS_U32 data_size,
491 const MS_U8 *data)
492 {
493 MS_U32 u32Status;
494 HAL_NSK2_WriteControl(control);
495
496 if(data_size != 0)
497 {
498 DRVNSK2_DBG(NSK2_DBGLV_INFO,"%s data_size = %x\n", __FUNCTION__,data_size);
499 u32Status = HAL_NSK2_WriteData8(register_offset, data_size, ( MS_U8 *)data);
500 if(TRUE != u32Status)
501 {
502 DRVNSK2_DBG(NSK2_DBGLV_ERR,"%s, write excute cmd error", __FUNCTION__);
503 }
504 }
505
506 HAL_NSK2_WriteCommand(command);
507 return TRUE;
508 }
509
510
511
512
MDrv_NSK2_GetMaxXConn(void)513 MS_U32 MDrv_NSK2_GetMaxXConn(void)
514 {
515 return HAL_NSK2_GetMaxXConn();
516 }
517
MDrv_NSK2_CMChannelNum(void)518 MS_U32 MDrv_NSK2_CMChannelNum(void)
519 {
520 return HAL_NSK2_CMChannelNum();
521 }
522
MDrv_NSK2_SetDbgLevel(MS_U32 u32Level)523 void MDrv_NSK2_SetDbgLevel(MS_U32 u32Level)
524 {
525 _g32NSK2DbgLv = u32Level;
526 DRVNSK2_DBG(NSK2_DBGLV_INFO, "%s level: %x\n", __FUNCTION__, u32Level);
527 HAL_NSK2_SetDbgLevel(u32Level);
528 }
529
MDrv_NSK2_SetPollingCnt(MS_U32 u32Cnt)530 void MDrv_NSK2_SetPollingCnt(MS_U32 u32Cnt)
531 {
532 HAL_NSK2_SetPollingCnt(u32Cnt);
533 }
534
MDrv_NSK2_RunFree(MS_BOOL bRunFree)535 void MDrv_NSK2_RunFree(MS_BOOL bRunFree)
536 {
537 DRVNSK2_DBG(NSK2_DBGLV_INFO,"%s, bRunFree = %d\n", __FUNCTION__, bRunFree);
538
539 HAL_NSK2_RunFree(bRunFree);
540 }
541
MDrv_NSK2_PushSlowClock(MS_BOOL HaltClk,MS_U32 TenSecond)542 void MDrv_NSK2_PushSlowClock ( MS_BOOL HaltClk, MS_U32 TenSecond)
543 {
544 HAL_NSK2_PushSlowClock(HaltClk, TenSecond);
545 }
546
MDrv_NSK2_GetRNGThroughPut(void * pRngData,MS_U32 u32DataSize,MS_BOOL bDump)547 void MDrv_NSK2_GetRNGThroughPut(void *pRngData, MS_U32 u32DataSize, MS_BOOL bDump)
548 {
549 DRVNSK2_DBG(NSK2_DBGLV_INFO, "%s enter\n", __FUNCTION__);
550 HAL_NSK2_GetRNGThroughPut(pRngData, u32DataSize, bDump);
551 }
552
553 #if 0
554 void MDrv_NSK2_BurstLen(MS_U32 u32PVREng, MS_U32 u32BurstMode)
555 {
556 HAL_NSK2_BurstLen(u32PVREng, u32BurstMode);
557 }
558 #endif
559
MDrv_NSK2_GetCMProperties(MS_U32 * desc_size,MS_U8 * desc)560 MS_U32 MDrv_NSK2_GetCMProperties(MS_U32 *desc_size, MS_U8 *desc)
561 {
562 return HAL_NSK2_GetCMProperties(desc_size, desc);
563 }
564
MDrv_NSK2_GetM2MProperties(MS_U32 * desc_size,MS_U8 * desc)565 MS_U32 MDrv_NSK2_GetM2MProperties(MS_U32 *desc_size, MS_U8 *desc)
566 {
567 return HAL_NSK2_GetM2MProperties(desc_size, desc);
568 }
569
MDrv_NSK2_GetDMAProperties(MS_U32 * desc_size,MS_U8 * desc)570 MS_U32 MDrv_NSK2_GetDMAProperties(MS_U32 *desc_size, MS_U8 *desc)
571 {
572 return HAL_NSK2_GetDMAProperties(desc_size, desc);
573 }
574
MDrv_NSK2_GetOTPProperties(MS_U32 * desc_size,MS_U8 * desc)575 MS_U32 MDrv_NSK2_GetOTPProperties(MS_U32 *desc_size, MS_U8 *desc)
576 {
577 return HAL_NSK2_GetOTPProperties(desc_size, desc);
578 }
579
MDrv_NSK2_GetFullChipConfig(MS_U32 * desc_size,MS_U8 * desc)580 MS_U32 MDrv_NSK2_GetFullChipConfig(MS_U32 *desc_size, MS_U8 *desc)
581 {
582 return HAL_NSK2_GetFullChipConfig(desc_size, desc);
583 }
584
MDrv_NSK2_GetNVCounterConfig(MS_U32 * desc_size,MS_U8 * desc)585 MS_U32 MDrv_NSK2_GetNVCounterConfig(MS_U32 *desc_size, MS_U8 *desc)
586 {
587 return HAL_NSK2_GetNVCounterConfig(desc_size, desc);
588 }
589
590
MDrv_NSK2_ReadAllOTP(void)591 void MDrv_NSK2_ReadAllOTP(void)
592 {
593 HAL_NSK2_ReadAllOTP();
594 }
595
596
MDrv_NSK2_GetPubOTP(MS_U8 * pPubOTP)597 MS_BOOL MDrv_NSK2_GetPubOTP(MS_U8 *pPubOTP)
598 {
599 //return HAL_NSK2_GetPubOTP(pPubOTP);
600 return TRUE;
601 }
602
603 //=====================================
604 // =========== Debug Usage=================
605 //=====================================
DBG_NSK2_AllTSPPidFilter(void)606 void DBG_NSK2_AllTSPPidFilter(void)
607 {
608 HAL_NSK2_AllTSPPidFilter();
609 }
610
DBG_NSK2_ChangePidFilter(MS_U32 pid_no,MS_U32 Data)611 void DBG_NSK2_ChangePidFilter(MS_U32 pid_no, MS_U32 Data)
612 {
613 HAL_NSK2_ChangePidFilter(pid_no, Data);
614 }
615
616
617 //=====================================
618 //====== NSK2.1 new functions ======
619 //=====================================
620
MDrv_NSK21_InvalidCmChannel(MS_U16 PidSlot)621 MS_U32 MDrv_NSK21_InvalidCmChannel(MS_U16 PidSlot)
622 {
623 DRVNSK2_DBG(NSK2_DBGLV_INFO,"%s PidSlot = %x\n", __FUNCTION__,PidSlot);
624 HAL_NSK21_InvalidCmChannel(PidSlot);
625 return TRUE;
626 }
627
MDrv_NSK21_CfgCmChannel(MS_U16 PidSlot,MS_U16 LocalDAlgo,MS_U16 ESAAlgo,MS_U16 LocalSAlgo,MS_U16 SysKeyIndex)628 MS_U32 MDrv_NSK21_CfgCmChannel(MS_U16 PidSlot, MS_U16 LocalDAlgo, MS_U16 ESAAlgo, MS_U16 LocalSAlgo, MS_U16 SysKeyIndex)
629 {
630 DRVNSK2_DBG(NSK2_DBGLV_INFO,"%s PidSlot = %x\n", __FUNCTION__,PidSlot);
631
632 return HAL_NSK21_CfgCmChannel(PidSlot, LocalDAlgo, ESAAlgo, LocalSAlgo, SysKeyIndex);
633 }
634
MDrv_NSK21_WriteTransportKey(MS_U8 SCB,MS_U8 ForceSCB,void * pLocalDIV1,void * pLocalDIV2,void * pESAIV1,void * pESAIV2,void * pLocalSIV1,void * pLocalSIV2,MS_U16 PidSlot)635 MS_U32 MDrv_NSK21_WriteTransportKey(MS_U8 SCB, MS_U8 ForceSCB, void *pLocalDIV1, void *pLocalDIV2,
636 void *pESAIV1, void *pESAIV2, void *pLocalSIV1, void *pLocalSIV2, MS_U16 PidSlot )
637 {
638 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s \n", __FUNCTION__);
639
640 DRVNSK2_DBG(NSK2_DBGLV_INFO,"SCB = %x, ForceSCB = %x\n",SCB,ForceSCB);
641
642 return HAL_NSK21_WriteTransportKey(SCB, ForceSCB, pLocalDIV1, pLocalDIV2, pESAIV1, pESAIV2, pLocalSIV1, pLocalSIV2, PidSlot);
643 }
644
MDrv_NSK21_WriteM2MKey(MS_U32 M2MAlgo)645 MS_U32 MDrv_NSK21_WriteM2MKey(MS_U32 M2MAlgo)
646 {
647 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s M2MAlgo = %x\n", __FUNCTION__,M2MAlgo);
648
649 return HAL_NSK21_WriteM2MKey(M2MAlgo);
650 }
651
MDrv_NSK21_ModifyGenIn(MS_U32 MaskVal,MS_U32 XorVal)652 MS_U32 MDrv_NSK21_ModifyGenIn(MS_U32 MaskVal,MS_U32 XorVal)
653 {
654 DRVNSK2_DBG(NSK2_DBGLV_DEBUG,"%s MaskVal = %x, XorVal = %x\n", __FUNCTION__,MaskVal,XorVal);
655
656 return HAL_NSK21_ModifyGenIn(MaskVal,XorVal);
657 }
658
MDrv_NSK21_WriteJTagKey(MS_U32 OverrideOid,MS_U32 Select)659 MS_U32 MDrv_NSK21_WriteJTagKey(MS_U32 OverrideOid, MS_U32 Select)
660 {
661 DRVNSK2_DBG(NSK2_DBGLV_INFO,"%s \n", __FUNCTION__);
662 return HAL_NSK21_WriteJTagKey(OverrideOid, Select);
663 }
664
MDrv_NSK21_IncrementNvCounter(void)665 MS_U32 MDrv_NSK21_IncrementNvCounter(void)
666 {
667 DRVNSK2_DBG(NSK2_DBGLV_INFO,"%s \n", __FUNCTION__);
668 return HAL_NSK21_IncrementNvCounter();
669 }
670
MDrv_NSK21_WriteReservedKey(void)671 MS_U32 MDrv_NSK21_WriteReservedKey(void)
672 {
673
674 return TRUE;
675 }
676
677
MDrv_NSK2_CompareIRQ(MS_U32 reserved_1,MS_U32 reserved_2,MS_U32 ExpectedValue)678 MS_U32 MDrv_NSK2_CompareIRQ(MS_U32 reserved_1, MS_U32 reserved_2, MS_U32 ExpectedValue)
679 {
680 DRVNSK2_DBG(NSK2_DBGLV_INFO,"%s \n", __FUNCTION__);
681 MS_U32 status;
682
683 MsOS_DelayTask(100);
684
685 #ifdef ACPUTest
686 //printf("IntStatus = %x, ExpectedValue = %x, time = %d\n",u32NSK2IntStatus, ExpectedValue, MsOS_GetSystemTime());
687 status = u32NSK2IntStatus; //HAL_NSK2_GetIntStatus();
688 u32NSK2IntStatus = 0;
689 #else
690 status = HAL_NSK2_GetIntStatus();
691 #endif
692 //printf("Int Status = %x\n",status);
693
694 if(0 == ExpectedValue)
695 {
696 if(0 != status)
697 return TRUE;
698 else
699 return FALSE;
700 }
701 else
702 {
703 if(0 == status)
704 return TRUE;
705 else
706 return FALSE;
707 }
708
709 }
710
MDrv_NSK2_WriteOtpKey(void)711 MS_U32 MDrv_NSK2_WriteOtpKey(void)
712 {
713 return HAL_NSK2_WriteOtpKey();
714 }
715
MDrv_NSK2_ReadPWD_Status(void)716 MS_U32 MDrv_NSK2_ReadPWD_Status(void)
717 {
718 return HAL_NSK2_ReadPWD_Status();
719 }
720
MDrv_NSK2_CtrlClk(MS_BOOL Enable)721 MS_U32 MDrv_NSK2_CtrlClk(MS_BOOL Enable)
722 {
723 return HAL_NSK2_CtrlClk(Enable);
724 }
725
MDrv_NSK2_ReadClkStatus(void)726 MS_U32 MDrv_NSK2_ReadClkStatus(void)
727 {
728 return HAL_NSK2_ReadClkStatus();
729 }
730
MDrv_NSK2_GetSRAlignBit(void)731 MS_U32 MDrv_NSK2_GetSRAlignBit(void)
732 {
733 return HAL_NSK2_GetSRAlignBit();
734 }
735
MDrv_NSK2_RSA_SetSecureRange(MS_U32 u32SecSet,MS_U32 u32SecStart,MS_U32 u32SecEnd)736 MS_BOOL MDrv_NSK2_RSA_SetSecureRange(MS_U32 u32SecSet, MS_U32 u32SecStart, MS_U32 u32SecEnd)
737 {
738 return HAL_NSK2_RSA_SetSecureRange(u32SecSet, u32SecStart, u32SecEnd, TRUE);
739 }
740
MDrv_NSK2_RSA_SetSR_Mask(MS_U32 u32DramSize)741 void MDrv_NSK2_RSA_SetSR_Mask(MS_U32 u32DramSize)
742 {
743 if (0 != u32DramSize)
744 {
745 HAL_NSK2_RSA_SetSR_Mask(u32DramSize);
746 }
747 }
748