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 #ifndef _HAL_NSK2_H_ 95 #define _HAL_NSK2_H_ 96 97 //////////////////////////////////////////////////////////////////////////////// 98 /// @file halNSK2.h 99 /// @author MStar Semiconductor Inc. 100 /// @brief 101 //////////////////////////////////////////////////////////////////////////////// 102 103 //////////////////////////////////////////////////////////////////////////////// 104 // Header Files 105 //////////////////////////////////////////////////////////////////////////////// 106 #include "regNSK2.h" 107 108 //////////////////////////////////////////////////////////////////////////////// 109 // Define & data type 110 //////////////////////////////////////////////////////////////////////////////// 111 #define OpenAllConfigs 0 112 #define MaximumXConnection 2 113 114 115 typedef struct _cmchannel_group_capability_descriptor { 116 MS_U8 descriptor_tag; 117 MS_U8 descriptor_length; 118 MS_U8 number_of_channels[4]; 119 MS_U8 switch_combination_bitmap[32]; 120 MS_U8 user_context[8]; 121 } cmchannel_group_capability_descriptor_t; 122 123 124 typedef struct _cmchannel_group_algorithm_record_descriptor { 125 MS_U8 descriptor_tag; 126 MS_U8 descriptor_length; 127 MS_U8 algorithm_type; 128 MS_U8 algorithm; 129 MS_U8 parity_combination_bitmap; 130 MS_U8 capability; 131 } cmchannel_group_algorithm_record_descriptor_t; 132 133 typedef struct _DMA_Capabability_Descriptor{ 134 MS_U8 descriptor_tag; 135 MS_U8 descriptor_length; 136 MS_U8 maximum_data_size[4]; 137 MS_U8 minimum_data_size[4]; 138 MS_U8 data_size_granularity[4]; 139 MS_U8 data_alignment[4]; 140 MS_U8 capability[4]; 141 } DMA_Capa_Desc_t; 142 143 144 typedef struct _M2MChannelGroup_Capabability_Descriptor{ 145 MS_U8 descriptor_tag; 146 MS_U8 descriptor_length; 147 MS_U8 number_of_channels[4]; 148 MS_U8 user_context[8]; 149 } M2MChGr_Capa_Desc_t; 150 151 typedef struct _M2MChannelGroup_AlgoRecord_Descriptor{ 152 MS_U8 descriptor_tag; 153 MS_U8 descriptor_length; 154 MS_U8 algorithm; 155 MS_U8 capability[4]; 156 } M2MChGr_AlgoRecord_Desc_t; 157 158 typedef struct _NVCounter_Descriptor{ 159 MS_U8 descriptor_tag; 160 MS_U8 descriptor_length; 161 MS_U8 max_nvcounter[4]; 162 MS_U8 left_nvcounter[4]; 163 } NVCounter_Desc_t; 164 165 //////////////////////////////////////////////////////////////////////////////// 166 // Extern function 167 //////////////////////////////////////////////////////////////////////////////// 168 MS_U32 HAL_NSK2_Init(void); 169 MS_U32 HAL_NSK2_Exit(void); 170 void HAL_NSK2_SetBase(MS_U32 u32Base); 171 MS_U32 HAL_NSK2_ColdReset(void); 172 173 MS_U32 HAL_NSK2_CompareMem(MS_U32 reserved, MS_U32 StartAddr, MS_U32 CompareLens, 174 MS_U32 CompareSim, MS_U32 ExpectResult, void *pGolden); 175 MS_U32 HAL_NSK2_Compare(MS_U32 StartAddr, MS_U32 CompareLens, MS_U32 CompareSim, 176 MS_U32 Mask, MS_U32 ExpectResult); 177 MS_U32 HAL_NSK2_CompareKTE(MS_U32 reserved_1, MS_U32 reserved_2, void *pLabel); 178 MS_U32 HAL_NSK2_CompareOut(MS_U32 reserved_1, MS_U32 reserved_2, MS_U32 HighDWord, MS_U32 LowDWord); 179 180 MS_U32 HAL_NSK2_WriteControl(MS_U32 control); 181 MS_U32 HAL_NSK2_WriteCommand(MS_U32 command); 182 MS_U32 HAL_NSK2_WriteESA(MS_U8 ESASelect, MS_U8 ESASubSelect, MS_U8 pid_no); 183 MS_U32 HAL_NSK2_WriteMem(MS_U32 reserved, MS_U32 StartAddr, MS_U32 WriteLens, void *pWriteData); 184 MS_U32 HAL_NSK2_WriteM2MKey(void *pIV, MS_U8 SubAlgo); 185 MS_U32 HAL_NSK2_WriteSFR(MS_U32 StartAddr, MS_U32 Data); 186 MS_U32 HAL_NSK2_WriteSCPUKey(void); 187 MS_U32 HAL_NSK2_WriteTransportKey(MS_U8 SCB, MS_U8 ForceSCB, void *pLabel, MS_U8 pid_no); 188 189 MS_U32 HAL_NSK2_NSKBasicInitializationComplete(void); 190 MS_U32 HAL_NSK2_SetRNG(MS_U32 reserved_1,MS_U32 RNG_Value); 191 MS_U32 HAL_NSK2_DriveKteAck(void); 192 MS_U32 HAL_NSK2_SetJTagPswd(void); 193 MS_U32 HAL_NSK2_PushSlowClock ( MS_BOOL HaltClk, MS_U32 NumOfMs); 194 void HAL_NSK2_RunFree(MS_BOOL bRunFree); 195 196 197 MS_U32 HAL_NSK2_UnlockOTPCtrl(void); 198 MS_BOOL HAL_NSK2_CheckPubOTPConfig(void *pCheck); 199 200 MS_U32 HAL_NSK2_ReadData(MS_U32 addr_offset, MS_U32 data_size, MS_U8 *data); 201 MS_U32 HAL_NSK2_WriteData(MS_U32 addr_offset, MS_U32 data_size, MS_U8 *data); 202 MS_U32 HAL_NSK2_ReadData8(MS_U32 addr_offset, MS_U32 data_size, MS_U8 *data); 203 MS_U32 HAL_NSK2_WriteData8(MS_U32 addr_offset, MS_U32 data_size, MS_U8 *data); 204 MS_U32 HAL_NSK2_ReadData32(MS_U32 addr_offset, MS_U32 data_size, MS_U32 *data); 205 MS_U32 HAL_NSK2_WriteData32(MS_U32 addr_offset, MS_U32 data_size, MS_U32 *data); 206 MS_U32 HAL_NSK2_EnableInt(void); 207 MS_U32 HAL_NSK2_GetIntStatus(void); 208 MS_U32 HAL_NSK2_ClearInt(MS_U32 u32IntValue); 209 MS_U32 HAL_NSK2_GetMaxXConn(void); 210 MS_U32 HAL_NSK2_CMChannelNum(void); 211 MS_U32 HAL_NSK2_ReadSwitchFromNSK2(void); 212 void HAL_NSK2_ReadTSPInfo(MS_U32 pid_no); 213 void HAL_NSK2_AllTSPPidFilter(void); 214 void HAL_NSK2_ChangePidFilter(MS_U32 pid_no, MS_U32 Data); 215 void HAL_NSK2_SetDbgLevel(MS_U32 u32Level); 216 void HAL_NSK2_SetPollingCnt(MS_U32 u32Cnt); 217 void HAL_NSK2_ClockTest(MS_U32 testnum); 218 void HAL_NSK2_GetRNGThroughPut(void *pRngData, MS_U32 u32DataSize, MS_BOOL bDump); 219 void HAL_NSK2_BurstLen(MS_U32 u32PVREng, MS_U32 u32BurstMode); 220 MS_U32 HAL_NSK2_GetCMProperties(MS_U32 *desc_size, MS_U8 *desc); 221 MS_U32 HAL_NSK2_GetM2MProperties(MS_U32 *desc_size, MS_U8 *desc); 222 MS_U32 HAL_NSK2_GetDMAProperties(MS_U32 *desc_size, MS_U8 *desc); 223 MS_U32 HAL_NSK2_GetOTPProperties(MS_U32 *desc_size, MS_U8 *desc); 224 MS_U32 HAL_NSK2_GetFullChipSize(void); 225 MS_U32 HAL_NSK2_GetFullChipConfig(MS_U32 *desc_size, MS_U8 *desc); 226 MS_U32 HAL_NSK2_GetNVCounterConfig(MS_U32 *desc_size, MS_U8 *desc); 227 228 void HAL_NSK2_ReadAllOTP(void); 229 230 MS_U32 HAL_NSK2_ReadKTEResp(void); 231 MS_U32 HAL_NSK21_InvalidCmChannel(MS_U16 PidSlot); 232 MS_U32 HAL_NSK21_CfgCmChannel(MS_U16 PidSlot, MS_U16 LocalDAlgo, MS_U16 ESAAlgo, MS_U16 LocalSAlgo, MS_U16 SysKeyIndex); 233 MS_U32 HAL_NSK21_WriteTransportKey(MS_U8 SCB, MS_U8 ForceSCB, void *pLocalDIV1, void *pLocalDIV2, 234 void *pESAIV1, void *pESAIV2, void *pLocalSIV1, void *pLocalSIV2, MS_U16 PidSlot ); 235 MS_U32 HAL_NSK21_WriteM2MKey(MS_U32 M2MAlgo); 236 MS_U32 HAL_NSK21_ModifyGenIn(MS_U32 MaskVal,MS_U32 XorVal); 237 MS_U32 HAL_NSK21_WriteJTagKey(MS_U32 OverrideOid, MS_U32 Select); 238 MS_U32 HAL_NSK21_IncrementNvCounter(void); 239 MS_U32 HAL_NSK2_WriteOtpKey(void); 240 MS_U32 HAL_NSK2_EndSubtest(void); 241 MS_U32 HAL_NSK2_DisableInt(void); 242 MS_U32 HAL_NSK2_WriteReservedKey(void); 243 MS_U32 HAL_NSK2_GetReserveKeyNum(void); 244 MS_U32 HAL_NSK2_ReadPWD_Status(void); 245 MS_U32 HAL_NSK2_CtrlClk(MS_BOOL Enable); 246 MS_U32 HAL_NSK2_ReadClkStatus(void); 247 MS_U32 HAL_NSK2_GetSRAlignBit(void); 248 MS_BOOL HAL_NSK2_RSA_SetSecureRange(MS_U32 u32SecSet, MS_U32 u32SecStart, MS_U32 u32SecEnd, MS_BOOL bEnable); 249 void HAL_NSK2_RSA_SetSR_Mask(MS_U32 u32DramSize); 250 251 #endif //_HAL_NSK2_H_ 252 253