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 // file halAESDMA.h 97 // @brief AESDMA HAL 98 // @author MStar Semiconductor,Inc. 99 //////////////////////////////////////////////////////////////////////////////////////////////////// 100 #ifndef __HAL_AESDMA_H__ 101 #define __HAL_AESDMA_H__ 102 103 #include "regAESDMA.h" 104 105 //-------------------------------------------------------------------------------------------------- 106 // Driver Compiler Option 107 //-------------------------------------------------------------------------------------------------- 108 109 //-------------------------------------------------------------------------------------------------- 110 // AESDMA Hardware Abstraction Layer 111 //-------------------------------------------------------------------------------------------------- 112 113 // TSP Register 114 #define _TspPid ((REG_Pid*)(REG_PIDFLT_BASE)) 115 #define _TspSec ((REG_Sec*)(REG_SECFLT_BASE)) 116 117 #define DIGEST_SIZE_SHA1 5UL //160-bit 118 #define DIGEST_SIZE_SHA256 8UL //256-bit 119 #define SHA_MIU1_ENABLE 0x80000000UL //Enable access MIU1 120 #define SHA_UNIT_SIZE 1UL 121 #define PARSER_PID_COUNT 2UL 122 123 //-------------------------------------------------------------------------------------------------- 124 // Macro of bit operations 125 //-------------------------------------------------------------------------------------------------- 126 #define HAS_FLAG(flag, bit) ((flag) & (bit)) 127 #define SET_FLAG(flag, bit) ((flag)|= (bit)) 128 #define RESET_FLAG(flag, bit) ((flag)&= (~(bit))) 129 #define SET_FLAG1(flag, bit) ((flag)| (bit)) 130 #define RESET_FLAG1(flag, bit) ((flag)& (~(bit))) 131 132 /// SHA Mode 133 typedef enum 134 { 135 E_AESDMA_SHA1 = 0, 136 E_AESDMA_SHA256, 137 } AESDMA_SHAMode; 138 139 /// AESDMA Cipher Mode 140 typedef enum 141 { 142 E_AESDMA_CIPHER_ECB = 0, 143 E_AESDMA_CIPHER_CTR, 144 E_AESDMA_CIPHER_CBC, 145 E_AESDMA_CIPHER_DES_ECB, 146 E_AESDMA_CIPHER_DES_CTR, 147 E_AESDMA_CIPHER_DES_CBC, 148 E_AESDMA_CIPHER_TDES_ECB, 149 E_AESDMA_CIPHER_TDES_CTR, 150 E_AESDMA_CIPHER_TDES_CBC, 151 E_AESDMA_CIPHER_CTS_CBC, 152 E_AESDMA_CIPHER_CTS_ECB, 153 E_AESDMA_CIPHER_DES_CTS_CBC, 154 E_AESDMA_CIPHER_DES_CTS_ECB, 155 E_AESDMA_CIPHER_TDES_CTS_CBC, 156 E_AESDMA_CIPHER_TDES_CTS_ECB, 157 } AESDMA_CipherMode; 158 159 /// HW PARSER Mode 160 typedef enum 161 { 162 E_AESDMA_PARSER_TS_PKT192 = 0, 163 E_AESDMA_PARSER_TS_PKT192_CLEAR, 164 E_AESDMA_PARSER_TS_PKT188, 165 E_AESDMA_PARSER_TS_PKT188_CLEAR, 166 E_AESDMA_PARSER_HDCP20_PKT192, 167 E_AESDMA_PARSER_HDCP20_PKT192_CLEAR, 168 E_AESDMA_PARSER_HDCP20_PKT188, 169 E_AESDMA_PARSER_HDCP20_PKT188_CLEAR, 170 } AESDMA_ParserMode; 171 172 typedef enum 173 { 174 E_AESDMA_PARSER_SCRMB_10 = 0, 175 E_AESDMA_PARSER_SCRMB_11, 176 E_AESDMA_PARSER_SCRMB_CLEAR, 177 } AESDMA_ScrmbPattern; 178 179 typedef enum 180 { 181 E_RSA_ADDRESS_E = 0, 182 E_RSA_ADDRESS_N, 183 E_RSA_ADDRESS_A, 184 E_RSA_ADDRESS_Z, 185 } RSA_IND32Address; 186 187 //////////////////////////////////////////////// 188 // HAL API 189 //////////////////////////////////////////////// 190 void HAL_AESDMA_SetBank(MS_VIRT u32NonPmBankAddr, MS_VIRT u32PmBankAddr); 191 MS_PHY AESDMA_GetMIU1Base(void); 192 MS_PHY AESDMA_GetMIU2Base(void); 193 void AESDMA_Reset(void); 194 void AESDMA_Set_CipherKey(MS_U32 *cipherkey); 195 void AESDMA_Set_InitVector(MS_U32 *pInitVector); 196 void AESDMA_Sel_Key(MS_BOOL keysel); 197 void AESDMA_Sel_SecureKey(void); 198 void AESDMA_Set_FileinDesc(MS_PHY FileinAddr , MS_PHY FileinNum); 199 void AESDMA_Set_FileoutDesc(MS_PHY FileoutSAddr , MS_PHY FileoutEAddr); 200 void AESDMA_Start(MS_BOOL AESDMAStart); 201 void AESDMA_Set_PS_PTN(MS_U32 MatchPTN); 202 void AESDMA_Set_PS_Mask(MS_U32 MatchMask); 203 void AESDMA_Set_PS_ENG(MS_BOOL PSin_en, MS_BOOL PSout_en); 204 MS_U32 AESDMA_Get_PS_MatchedBytecnt(void); 205 MS_U32 AESDMA_Get_PS_MatchedPTN(void); 206 void AESDMA_Set_PS_Release(void); 207 MS_U32 AESDMA_Get_AESDMA_Status(void); 208 MS_U32 AESDMA_Get_AESDMA_IsFinished(void); 209 void AESDMA_Set_CIPHER_ENG(AESDMA_CipherMode eMode, MS_BOOL Descrypt); 210 MS_U32 AESDMA_QueryCipherMode(AESDMA_CipherMode eMode); 211 void AESDMA_Set_MIU_Path(MS_BOOL MIU_R, MS_BOOL MIU_W); 212 void AESDMA_Set_MIU2_Path(MS_BOOL MIU_R, MS_BOOL MIU_W); 213 void AESDMA_Enable_Int(void); 214 void AESDMA_Disable_Int(void); 215 void AESDMA_Clear_Int(void); 216 void AESDMA_HW_Patch(void); 217 void AESDMA_Enable_Clk(void); 218 void AESDMA_Disable_Clk(void); 219 MS_U8 AESDMA_Rand(void); 220 void SHA_Reset(void); 221 MS_U32 SHA_Get_Status(void); 222 void SHA_SelMode(AESDMA_SHAMode eMode); 223 void SHA_SetAddress(MS_PHY u32Addr); 224 void SHA_SetLength(MS_U32 u32Size); 225 void SHA_Start(MS_BOOL SHAStart); 226 void SHA_Out(MS_VIRT u32Buf); 227 void MOBF_OneWay(void); 228 void MOBF_WriteKey(MS_U32 u32WriteKey); 229 void MOBF_ReadKey(MS_U32 u32ReadKey); 230 void MOBF_WriteEnable(MS_BOOL bEnable); 231 void MOBF_ReadEnable(MS_BOOL bEnable); 232 void MOBF_DisableTDES(void); 233 void AESDMA_Parser_Set_Mode(AESDMA_ParserMode eMode); 234 void AESDMA_Parser_Insert_Scrmb(MS_BOOL bEnable); 235 void AESDMA_Parser_Remove_Scrmb(MS_BOOL bEnable); 236 void AESDMA_Parser_Mask_Scrmb(MS_BOOL bEnable); 237 void AESDMA_Parser_Bypass_Pid(MS_BOOL bEnable); 238 void AESDMA_Parser_Set_ScrmbPattern(AESDMA_ScrmbPattern ePattern); 239 void AESDMA_Parser_Set_AddedScrmbPattern(AESDMA_ScrmbPattern ePattern); 240 void AESDMA_Parser_Set_Pid(MS_U8 u8Index, MS_U16 u16Pid); 241 MS_U8 AESDMA_Parser_Query_PidCount(void); 242 void AESDMA_Parser_Enable_HWParser(MS_BOOL bEnable); 243 void RSA_ClearInt(void); 244 void RSA_Reset(void); 245 void RSA_Ind32Ctrl(MS_U8 u8dirction); 246 void RSA_LoadSram(MS_U32 *u32Buf, RSA_IND32Address eMode); 247 void RSA_SetKeyLength(MS_U32 u32keylen); 248 void RSA_SetKeyType(MS_U8 u8hwkey, MS_U8 u8pubkey); 249 void RSA_ExponetialStart(void); 250 MS_U32 RSA_GetStatus(void); 251 void RSA_FileOutStart(void); 252 void RSA_SetFileOutAddr(MS_U32 u32offset); 253 MS_U32 RSA_FileOut(void); 254 MS_U32 RSA_Get_RSA_IsFinished(void); 255 void AESDMA_Parser_Enable_Two_Keys(MS_BOOL bEnable); 256 void AESDMA_Set_CipherOddKey(MS_U32 *cipherkey); 257 void AESDMA_Set_CipherEvenKey(MS_U32 *cipherkey); 258 void AESDMA_Set_OddInitVector(MS_U32 *pInitVector); 259 void AESDMA_Set_EvenInitVector(MS_U32 *pInitVector); 260 261 MS_U32 AESDMA_IsSecretKeyInNormalBank(void); 262 void HDCP_ProcessCipher (MS_U8 u8Idx, MS_U8 *pu8Data, MS_U8* pu8privData); 263 void AESDMA_NormalReset(void); 264 void HDCP_GetHdcpCipherState(MS_U8 u8Idx, MS_U8 *pu8State); 265 //reserved for secure protect function 266 /* 267 void AESDMA_Secure_SetCipherKey(MS_U32 *cipherkey); 268 void AESDMA_Secure_SetInitVector(MS_U32 *pInitVector); 269 void AESDMA_SecureProtect(MS_BOOL bEnable); 270 void AESDMA_Set_FileOutEnable(MS_BOOL bEnable); 271 void AESDMA_Secure_Start(MS_BOOL AESDMAStart); 272 MS_U32 AESDMA_Get_AESDMA_SecureIsFinished(void); 273 */ 274 275 #endif // #ifndef __HAL_TSP_H__ 276