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