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 drvCIPHER.h 98 /// @brief CIPHER Driver Interface 99 /// @author MStar Semiconductor,Inc. 100 /// 101 //////////////////////////////////////////////////////////////////////////////////////////////////// 102 #ifndef __DRVCIPHER_H__ 103 #define __DRVCIPHER_H__ 104 105 #include "MsTypes.h" 106 #include "MsDevice.h" 107 #include "MsCommon.h" 108 109 //-------------------------------------------------------------------------------------------------- 110 // Define 111 //-------------------------------------------------------------------------------------------------- 112 #define HASH_TIMEOUT_VALUE (5000UL) 113 114 typedef enum 115 { 116 CIPHER_DBG_NONE, 117 CIPHER_DBG_ERR, 118 CIPHER_DBG_WARN, 119 CIPHER_DBG_INFO, 120 }CIPHER_DBGMSG_LEVEL; 121 122 #define MSIF_CIPHER_LIB_CODE {'D','M','A','_'} //Lib code 123 #define MSIF_CIPHER_LIBVER {'0','1'} //LIB version 124 #define MSIF_CIPHER_BUILDNUM {'0','1'} //Build Number 125 #define MSIF_CIPHER_CHANGELIST {'0','0','8','2','9','9','2','7'} //P4 ChangeList Number 126 127 #define CIPHER_DRV_VERSION /* Character String for DRV/API version */ \ 128 MSIF_TAG, /* 'MSIF' */ \ 129 MSIF_CLASS, /* '00' */ \ 130 MSIF_CUS, /* 0x0000 */ \ 131 MSIF_MOD, /* 0x0000 */ \ 132 MSIF_CHIP, \ 133 MSIF_CPU, \ 134 MSIF_CIPHER_LIB_CODE, /* IP__ */ \ 135 MSIF_CIPHER_LIBVER, /* 0.0 ~ Z.Z */ \ 136 MSIF_CIPHER_BUILDNUM, /* 00 ~ 99 */ \ 137 MSIF_CIPHER_CHANGELIST, /* CL# */ \ 138 MSIF_OS 139 140 141 //-------------------------------------------------------------------------------------------------- 142 // Driver Capability 143 //-------------------------------------------------------------------------------------------------- 144 145 //-------------------------------------------------------------------------------------------------- 146 // Local variable 147 //-------------------------------------------------------------------------------------------------- 148 149 //-------------------------------------------------------------------------------------------------- 150 // Type and Structure 151 //-------------------------------------------------------------------------------------------------- 152 /// AESDMA DDI return value 153 typedef MS_U32 DRV_CIPHER_RET; 154 155 typedef void (*P_DrvCIPHER_EvtCallback)(MS_U32 u32CmdId, MS_BOOL bSuccess, MS_U32 u32Exception); 156 157 typedef enum 158 { 159 E_CIPHER_MAIN_NONE, 160 E_CIPHER_MAIN_AES, 161 E_CIPHER_MAIN_DES, 162 E_CIPHER_MAIN_TDES, 163 E_CIPHER_MAIN_M6_S56_CCBC, 164 E_CIPHER_MAIN_M6_S56, 165 E_CIPHER_MAIN_M6_KE56, 166 E_CIPHER_MAIN_RC4, 167 }CIPHER_MAIN_ALGO; 168 169 typedef enum 170 { 171 E_CIPHER_SUB_NONE, 172 E_CIPHER_SUB_ECB, 173 E_CIPHER_SUB_CBC, 174 E_CIPHER_SUB_CTR, 175 E_CIPHER_SUB_CBC_MAC, 176 E_CIPHER_SUB_CTR_64, 177 E_CIPHER_SUB_CMAC_Key, 178 E_CIPHER_SUB_CMAC_Algo, 179 E_CIPHER_SUB_PCBC_ADD, 180 E_CIPHER_SUB_PCBC_XOR, 181 }CIPHER_SUB_ALGO; 182 183 typedef enum 184 { 185 E_CIPHER_RES_NONE, 186 E_CIPHER_RES_CLR, 187 E_CIPHER_RES_CTS, 188 E_CIPHER_RES_SCTE52, 189 }CIPHER_RES_ALGO; 190 191 typedef enum 192 { 193 E_CIPHER_SB_NONE, 194 E_CIPHER_SB_CLR, 195 E_CIPHER_SB_IV1, 196 E_CIPHER_SB_IV2, 197 }CIPHER_SB_ALGO; 198 199 typedef enum 200 { 201 E_CIPHER_KSRC_CPU, 202 E_CIPHER_KSRC_KL, 203 E_CIPHER_KSRC_OTP , 204 }CIPHER_KEY_SRC; 205 206 207 typedef struct 208 { 209 CIPHER_MAIN_ALGO eMainAlgo; 210 CIPHER_SUB_ALGO eSubAlgo; 211 CIPHER_RES_ALGO eResAlgo; 212 CIPHER_SB_ALGO eSBAlgo; 213 }DRV_CIPHER_ALGO; 214 215 typedef struct 216 { 217 CIPHER_KEY_SRC eKeySrc; 218 MS_U8 u8KeyIdx; 219 MS_U8 u8KeyLen; 220 MS_VIRT ptrKeyData; 221 MS_U8 u8IVLen; 222 MS_VIRT ptrIVData; 223 }DRV_CIPHER_KEY; 224 225 226 typedef enum 227 { 228 E_CIPHER_DRAM = 1, 229 E_CIPHER_DQMEM, 230 E_CIPHER_IQMEM, 231 E_CIPHER_DIRECT, 232 }CIPHER_MEM_TYPE; 233 234 235 typedef struct 236 { 237 MS_PHY phyAddr; 238 MS_U32 u32Size; 239 CIPHER_MEM_TYPE eMemoryType; 240 }DRV_CIPHER_DATA; 241 242 typedef struct 243 { 244 DRV_CIPHER_ALGO stAlgo; 245 DRV_CIPHER_KEY stKey; 246 DRV_CIPHER_DATA stInput; 247 DRV_CIPHER_DATA stOutput; 248 MS_BOOL bDecrypt; 249 MS_U32 u32CAVid; 250 P_DrvCIPHER_EvtCallback pfCallback; 251 }DRV_CIPHER_DMACFG; 252 253 typedef enum 254 { 255 E_CIPHER_HASH_ALGO_SHA1, 256 E_CIPHER_HASH_ALGO_SHA256 , 257 E_CIPHER_HASH_ALGO_MD5 , 258 }CIPHER_HASH_ALGO; 259 260 typedef enum 261 { 262 E_CIPHER_HASH_IV_FIPS, 263 E_CIPHER_HASH_IV_CMD, 264 E_CIPHER_HASH_IV_PRV, 265 }CIPHER_HASH_IV; 266 267 typedef enum 268 { 269 E_CIPHER_HASH_STAGE_FIRST , 270 E_CIPHER_HASH_STAGE_UPDATE , 271 E_CIPHER_HASH_STAGE_LAST , 272 }CIPHER_HASH_STAGE; 273 274 typedef enum 275 { 276 E_CIPHER_HMAC_IKPAD, 277 E_CIPHER_HMAC_OKPAD, 278 }CIPHER_HMAC_KPAD; 279 280 typedef struct 281 { 282 CIPHER_KEY_SRC eKeySrc; 283 MS_U8 u8KeyIdx; 284 MS_U8 u8KeyLen; 285 MS_VIRT ptrKeyData; 286 }DRV_CIPHER_HMAC_KEY; 287 288 typedef struct 289 { 290 CIPHER_HASH_ALGO eAlgo; 291 DRV_CIPHER_DATA stInput; 292 MS_VIRT ptrDigest_Buf; 293 MS_U32 u32Digest_Buf_Size; 294 MS_U32 u32CAVid; 295 P_DrvCIPHER_EvtCallback pfCallback; 296 }DRV_CIPHER_HASHCFG; 297 298 typedef struct 299 { 300 CIPHER_HASH_ALGO eAlgo; 301 DRV_CIPHER_DATA stInput; 302 MS_VIRT ptrDigest_Buf; 303 MS_U32 u32Digest_Buf_Size; 304 MS_U32 u32CAVid; 305 MS_U32 u32StartByte; 306 MS_VIRT ptrSetIV; 307 CIPHER_HASH_IV eIVMode; 308 CIPHER_HASH_STAGE eStage; 309 CIPHER_HMAC_KPAD eHMACKPad; 310 DRV_CIPHER_HMAC_KEY stHMACKey; 311 }DRV_CIPHER_HASHCFG_MANUAL; 312 313 typedef struct 314 { 315 CIPHER_HASH_ALGO eAlgo; 316 DRV_CIPHER_DATA stInput; 317 MS_VIRT ptrDigest_Buf; 318 MS_U32 u32Digest_Buf_Size; 319 MS_U32 u32CAVid; 320 DRV_CIPHER_HMAC_KEY stHMACKey; 321 P_DrvCIPHER_EvtCallback pfCallback; 322 }DRV_CIPHER_HMACCFG; 323 324 #define DRV_CIPHER_OK (0x00000000UL) 325 #define DRV_CIPHER_FAIL (0x00000001UL) 326 #define DRV_CIPHER_BAD_PARAM (0x00000002UL) 327 328 //Exception Message 329 #define DRV_CIPHER_EXCEPT_CAVID (0x00000001UL) 330 #define DRV_CIPHER_EXCEPT_DATA (0x00000002UL) 331 #define DRV_CIPHER_EXCEPT_ALGO (0x00000004UL) 332 #define DRV_CIPHER_EXCEPT_DMA_KEY (0x00000008UL) 333 #define DRV_CIPHER_EXCEPT_HMAC_KEY (0x00000010UL) 334 335 336 //-------------------------------------------------------------------------------------------------- 337 // Function Prototype 338 //-------------------------------------------------------------------------------------------------- 339 // DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_Init(void); 340 // DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_Reset(void); 341 342 // DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_DMACalc(DRV_CIPHER_DMACFG stCfg, MS_U32 *pu32CmdId); 343 // DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_HASH(DRV_CIPHER_HASHCFG stCfg, MS_U32 *pu32CmdId); 344 // DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_HASHManual(DRV_CIPHER_HASHCFG_MANUAL stCfg, MS_U32 *pu32CmdId); 345 // DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_HMAC(DRV_CIPHER_HMACCFG stCfg, MS_U32 *pu32CmdId); 346 347 // DLL_PUBLIC MS_BOOL MDrv_CIPHER_IsDMADone(MS_U32 u32CmdId, MS_U32 *pu32Exception); 348 // DLL_PUBLIC MS_BOOL MDrv_CIPHER_IsHASHDone(MS_U32 u32CmdId, MS_U32 *pu32Exception); 349 350 // DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_SetDbgLevel(CIPHER_DBGMSG_LEVEL eDBGMsgLevel); 351 // DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_GetLibVer(const MSIF_Version **ppVersion); 352 353 #ifdef ENABLE_BGC 354 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_BGC_Enable(MS_U32 u32EngId,MS_U32 u32Algo, MS_VIRT ptrGolden, MS_PHY phySAddr, MS_U32 u32Size); 355 DLL_PUBLIC DRV_CIPHER_RET MDrv_CIPHER_BGC_Check(MS_U32 u32EngId, MS_BOOL *bOK); 356 #endif 357 358 //////// Old Interface ///////////////// 359 //-------------------------------------------------------------------------------------------------- 360 // Function Prototype 361 //-------------------------------------------------------------------------------------------------- 362 #include "drvAESDMA.h" 363 364 #endif 365