xref: /utopia/UTPA2-700.0.x/modules/security/hal/manhattan/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			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 typedef enum
188 {
189     E_AESDMA_HDMI_INPUT_PORT_DVI0              = 80,
190     E_AESDMA_HDMI_INPUT_PORT_DVI1              = 81,
191     E_AESDMA_HDMI_INPUT_PORT_DVI2              = 82,
192     E_AESDMA_HDMI_INPUT_PORT_DVI3              = 83
193 } AESDMA_HDMI_INPUT_PORT;
194 
195 ////////////////////////////////////////////////
196 // HAL API
197 ////////////////////////////////////////////////
198 void HAL_AESDMA_SetBank(MS_VIRT u32NonPmBankAddr, MS_VIRT u32PmBankAddr);
199 MS_PHY AESDMA_GetMIU1Base(void);
200 MS_PHY AESDMA_GetMIU2Base(void);
201 void AESDMA_Reset(void);
202 void AESDMA_Set_CipherKey(MS_U32 *cipherkey);
203 void AESDMA_Set_InitVector(MS_U32 *pInitVector);
204 void AESDMA_Sel_Key(MS_BOOL keysel);
205 void AESDMA_Sel_SecureKey(void);
206 void AESDMA_Set_FileinDesc(MS_PHY FileinAddr , MS_PHY FileinNum);
207 void AESDMA_Set_FileoutDesc(MS_PHY FileoutSAddr , MS_PHY FileoutEAddr);
208 void AESDMA_Start(MS_BOOL AESDMAStart);
209 void AESDMA_Set_PS_PTN(MS_U32 MatchPTN);
210 void AESDMA_Set_PS_Mask(MS_U32 MatchMask);
211 void AESDMA_Set_PS_ENG(MS_BOOL PSin_en, MS_BOOL PSout_en);
212 MS_U32 AESDMA_Get_PS_MatchedBytecnt(void);
213 MS_U32 AESDMA_Get_PS_MatchedPTN(void);
214 void AESDMA_Set_PS_Release(void);
215 MS_U32 AESDMA_Get_AESDMA_Status(void);
216 MS_U32 AESDMA_Get_AESDMA_IsFinished(void);
217 void AESDMA_Set_CIPHER_ENG(AESDMA_CipherMode eMode, MS_BOOL Descrypt);
218 MS_U32 AESDMA_QueryCipherMode(AESDMA_CipherMode eMode);
219 void AESDMA_Set_MIU_Path(MS_BOOL MIU_R, MS_BOOL MIU_W);
220 void AESDMA_Set_MIU2_Path(MS_BOOL MIU_R, MS_BOOL MIU_W);
221 void AESDMA_Enable_Int(void);
222 void AESDMA_Disable_Int(void);
223 void AESDMA_Clear_Int(void);
224 void AESDMA_HW_Patch(void);
225 void AESDMA_Enable_Clk(void);
226 void AESDMA_Disable_Clk(void);
227 MS_U8 AESDMA_Rand(void);
228 void SHA_Reset(void);
229 MS_U32 SHA_Get_Status(void);
230 void SHA_SelMode(AESDMA_SHAMode eMode);
231 void SHA_SetAddress(MS_PHY u32Addr);
232 void SHA_SetLength(MS_U32 u32Size);
233 void SHA_Start(MS_BOOL SHAStart);
234 void SHA_Out(MS_VIRT u32Buf);
235 void MOBF_OneWay(void);
236 void MOBF_WriteKey(MS_U32 u32WriteKey);
237 void MOBF_ReadKey(MS_U32 u32ReadKey);
238 void MOBF_WriteEnable(MS_BOOL bEnable);
239 void MOBF_ReadEnable(MS_BOOL bEnable);
240 void MOBF_DisableTDES(void);
241 void AESDMA_Parser_Set_Mode(AESDMA_ParserMode eMode);
242 void AESDMA_Parser_Insert_Scrmb(MS_BOOL bEnable);
243 void AESDMA_Parser_Remove_Scrmb(MS_BOOL bEnable);
244 void AESDMA_Parser_Mask_Scrmb(MS_BOOL bEnable);
245 void AESDMA_Parser_Bypass_Pid(MS_BOOL bEnable);
246 void AESDMA_Parser_Set_ScrmbPattern(AESDMA_ScrmbPattern ePattern);
247 void AESDMA_Parser_Set_AddedScrmbPattern(AESDMA_ScrmbPattern ePattern);
248 void AESDMA_Parser_Set_Pid(MS_U8 u8Index, MS_U16 u16Pid);
249 MS_U8 AESDMA_Parser_Query_PidCount(void);
250 void AESDMA_Parser_Enable_HWParser(MS_BOOL bEnable);
251 void RSA_ClearInt(void);
252 void RSA_Reset(void);
253 void RSA_Ind32Ctrl(MS_U8 u8dirction);
254 void RSA_LoadSram(MS_U32 *u32Buf, RSA_IND32Address eMode);
255 void RSA_SetKeyLength(MS_U32 u32keylen);
256 void RSA_SetKeyType(MS_U8 u8hwkey, MS_U8 u8pubkey);
257 void RSA_ExponetialStart(void);
258 MS_U32 RSA_GetStatus(void);
259 void RSA_FileOutStart(void);
260 void RSA_SetFileOutAddr(MS_U32 u32offset);
261 MS_U32 RSA_FileOut(void);
262 MS_U32 RSA_Get_RSA_IsFinished(void);
263 void AESDMA_Parser_Enable_Two_Keys(MS_BOOL bEnable);
264 void AESDMA_Set_CipherOddKey(MS_U32 *cipherkey);
265 void AESDMA_Set_CipherEvenKey(MS_U32 *cipherkey);
266 void AESDMA_Set_OddInitVector(MS_U32 *pInitVector);
267 void AESDMA_Set_EvenInitVector(MS_U32 *pInitVector);
268 
269 MS_U32 AESDMA_IsSecretKeyInNormalBank(void);
270 void HDCP_ProcessCipher (MS_U8 u8Idx, MS_U8 *pu8Data, MS_U8* pu8privData);
271 void AESDMA_NormalReset(void);
272 void HDCP_GetHdcpCipherState(MS_U8 u8Idx, MS_U8 *pu8State);
273 void AESDMA_Set_SecureBankEnable (MS_BOOL bEnable);
274 void HAL_AESDMA_HDMI_GetM0(AESDMA_HDMI_INPUT_PORT enInputPortType, MS_U8 *pu8Data);
275 void AESDMA_SetKeyIndex (MS_U32 u32Index, MS_BOOL bIsOddKey);
276 void AESDMA_SET_CTR64(MS_BOOL bEnable);
277 void AESDMA_SetSecureKeyIdx (MS_U8 u8KeyIdx);
278 //reserved for secure protect function
279 /*
280 void AESDMA_Secure_SetCipherKey(MS_U32 *cipherkey);
281 void AESDMA_Secure_SetInitVector(MS_U32 *pInitVector);
282 void AESDMA_SecureProtect(MS_BOOL bEnable);
283 void AESDMA_Set_FileOutEnable(MS_BOOL bEnable);
284 void AESDMA_Secure_Start(MS_BOOL AESDMAStart);
285 MS_U32 AESDMA_Get_AESDMA_SecureIsFinished(void);
286 */
287 
288 MS_BOOL AESDMA_POWER_SUSPEND(void);
289 MS_BOOL AESDMA_POWER_RESUME(void);
290 #endif // #ifndef __HAL_TSP_H__
291