xref: /utopia/UTPA2-700.0.x/modules/security/hal/k6lite/cipher/regCIPHER.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2006-2009 MStar Semiconductor, Inc.
4 // All rights reserved.
5 //
6 // Unless otherwise stipulated in writing, any and all information contained
7 // herein regardless in any format shall remain the sole proprietary of
8 // MStar Semiconductor Inc. and be kept in strict confidence
9 // (��MStar Confidential Information��) by the recipient.
10 // Any unauthorized act including without limitation unauthorized disclosure,
11 // copying, use, reproduction, sale, distribution, modification, disassembling,
12 // reverse engineering and compiling of the contents of MStar Confidential
13 // Information is unlawful and strictly prohibited. MStar hereby reserves the
14 // rights to any and all damages, losses, costs and expenses resulting therefrom.
15 //
16 ////////////////////////////////////////////////////////////////////////////////
17 
18 ////////////////////////////////////////////////////////////////////////////////////////////////////
19 //
20 //  File name: regCIPHER.h
21 //  Description: CIPHER Register Definition
22 //
23 ////////////////////////////////////////////////////////////////////////////////////////////////////
24 
25 #ifndef __REG_CIPHER_H__
26 #define __REG_CIPHER_H__
27 
28 
29 //--------------------------------------------------------------------------------------------------
30 //  Abbreviation
31 //--------------------------------------------------------------------------------------------------
32 // Addr                             Address
33 // Buf                              Buffer
34 // Clr                              Clear
35 // CmdQ                             Command queue
36 // Cnt                              Count
37 // Ctrl                             Control
38 // Flt                              Filter
39 // Hw                               Hardware
40 // Int                              Interrupt
41 // Len                              Length
42 // Ovfw                             Overflow
43 // Pkt                              Packet
44 // Rec                              Record
45 // Recv                             Receive
46 // Rmn                              Remain
47 // Reg                              Register
48 // Req                              Request
49 // Rst                              Reset
50 // Scmb                             Scramble
51 // Sec                              Section
52 // Stat                             Status
53 // Sw                               Software
54 // Ts                               Transport Stream
55 
56 #include "MsTypes.h"
57 //--------------------------------------------------------------------------------------------------
58 //  Global Definition
59 //--------------------------------------------------------------------------------------------------
60 
61 
62 //--------------------------------------------------------------------------------------------------
63 //  Compliation Option
64 //--------------------------------------------------------------------------------------------------
65 
66 
67 //-------------------------------------------------------------------------------------------------
68 //  Harware Capability
69 //-------------------------------------------------------------------------------------------------
70 
71 
72 //-------------------------------------------------------------------------------------------------
73 //  Type and Structure
74 //-------------------------------------------------------------------------------------------------
75 #if defined (MCU_AEON)
76 #define REG_CIPHERCTRL_BASE         (0x1A0200 * 2) // bank 0x2A02
77 #else
78 #define REG_CIPHERCTRL_BASE         (0xA0B00 * 2) // bank 0x1A0B
79 #endif
80 #define REG_IRQCTRL_BASE            (0x01900 * 2) // bank 0x1019
81 #define REG_MIU_CROSSBAR            (0x61300 * 2) //bank 0x1613
82 
83 #define REG32_Data   volatile MS_U32
84 
85 #define DMA_CTRL_REG_SIZE       5UL  //0x02:ctrl  0x03:reserved  0x04:reserved  0x05:except_flag  0x06:cryptoDMA_debug
86 #define DMA_DIRECT_OUTPUT_SIZE  4UL
87 #define HASH_RPT_REG_SIZE       10UL
88 #define DMA_RPT_REG_SIZE        2UL
89 #define HMAC_KEY_SIZE           4UL
90 #define HWPA_KEY_SIZE           4UL
91 #define HWPA_IV_SIZE            4UL
92 
93 #define RESERVE_SIZE1           3UL
94 #define RESERVE_SIZE2           21UL
95 
96 #define HASH_CMD_MSG_SIZE           (64UL) //16*4
97 #define HASH_CMD_IV_SIZE            (32UL) //8*4
98 #define HASH_CMD_HMAC_HOSTKEY_SIZE  (16UL)
99 
100 typedef struct _REG_AESDMACtrl
101 {
102     REG32_Data   SpareCnt_ORG ;
103     REG32_Data   Cmd_Queue_ORG;
104     REG32_Data   Dma_Ctrl[DMA_CTRL_REG_SIZE]; //0x02:ctrl  0x03:debug data  0x04:reserved  0x05:except_flag  0x06:cryptoDMA_debug
105 		#define	 REG_DMA_CTRL 			       0x0
106         #define	 REG_EXCEPT_FLAG 			   0x3
107         #define  REG_EXCEPT_FLAG_SIZE          27
108         #define  REG_CRYPTODMA_DEBUG           0x4
109 		#define  REG_EXCEPT_FLAG_CLEAR         0x80000
110 		#define  REG_DMA_SW_RESET              0x1
111         #define  REG_PARSER_LG_PATH_EN         0x400
112     REG32_Data   Dma_Out[DMA_DIRECT_OUTPUT_SIZE];
113     REG32_Data   Hash_Reportp[HASH_RPT_REG_SIZE];
114         #define  REG_CIPHER_RPT_THREAD_MSK     0xFFFF
115         #define  REG_CIPHER_RPT_OK             0x80000000
116         #define  REG_CIPHER_RPT_SHT              31
117     REG32_Data   Dma_Reportp[DMA_RPT_REG_SIZE];
118     REG32_Data   CryptoDMA2MI_NS;
119     REG32_Data   Debug_Port;
120     REG32_Data   HMAC_Key[HMAC_KEY_SIZE];
121     REG32_Data   RESERVE1[RESERVE_SIZE1];
122     REG32_Data   HWPA_Ctrl;
123     REG32_Data   HWPA_IV2[HWPA_IV_SIZE];
124     REG32_Data   HWPA_Key2[HWPA_KEY_SIZE];
125     REG32_Data   Cipher_Status;
126     REG32_Data   Parser_Status;
127     REG32_Data   RESERVE2[RESERVE_SIZE2];
128     REG32_Data   SpareCnt ;
129     REG32_Data   Cmd_Queue;
130 
131 
132 }REG_AESDMACtrl;
133 
134 typedef enum
135 {
136     E_CIPHER_NDS_Region_fail,
137     E_CIPHER_NDS_keyoff,
138     E_CIPHER_sha_write_scr,
139     E_CIPHER_sha_read_scr,
140     E_CIPHER_sha_error_flag,
141     E_CIPHER_except_read_scr,
142     E_CIPHER_except_key,
143     E_CIPHER_except_CAVid,
144     E_CIPHER_except_des,
145     E_CIPHER_except_NDS,
146     E_CIPHER_except_chain,
147     E_CIPHER_except_algo,
148     E_CIPHER_except_key_HID,
149     E_CIPHER_except_key_cbc_mac,
150     E_CIPHER_except_file_dqmem,
151     E_CIPHER_except_hash_dqmem,
152     E_CIPHER_disable_masterkey0,
153     E_CIPHER_disable_masterkey1,
154     E_CIPHER_disable_cck,
155     E_CIPHER_disable_reg_key_0,
156     E_CIPHER_disable_reg_key_1,
157     E_CIPHER_disable_reg_key_2,
158     E_CIPHER_disable_reg_key_3,
159     E_CIPHER_dma_forbid_qmem2dram,
160     E_CIPHER_dma_forbid_cryptodma_keyslot_qmem,
161     E_CIPHER_sha_forbid_qmem2dram,
162     E_CIPHER_sha_forbid_cryptodma_keyslot_qmem,
163 	E_CIPHER_tdes_key_error,
164 	E_CIPHER_write_address_error,
165 	E_CIPHER_except_str,
166 	E_CIPHER_except_sha_str
167 
168 }REG_Cipher_ExceptFlag;
169 
170 typedef enum
171 {
172     E_CIPHER_DEBUG_HASH_BUSY  = 0x40,
173     E_CIPHER_DEBUG_DMA_BUSY   = 0x80,
174 
175 }REG_CIPHER_Debug;
176 
177 
178 typedef struct _CMD_DmaFormat0
179 {
180     MS_U32          CL:6;
181         #define     CMD_LEN_MASK            0x3FUL
182 
183     MS_U32          DIV:1;
184 
185     MS_U32          DK:1;
186 
187     MS_U32          OVT:1;
188 
189     MS_U32          SB:3;
190         #define     CMD_DMA_SB_SEL_CLR          0x0UL
191         #define     CMD_DMA_SB_SEL_IV1          0x1UL
192         #define     CMD_DMA_SB_SEL_IV2          0x2UL
193 
194     MS_U32          Residue:3;
195     	#define     CMD_DMA_RESIDUE_CLR         0x0UL
196     	#define     CMD_DMA_RESIDUE_CTS         0x1UL
197     	#define     CMD_DMA_RESIDUE_SCTE52      0x2UL
198 
199   //jamietest  MS_U32          Decrypt:1;
200 
201     MS_U32          SubAlgo:4;
202         #define     CMD_DMA_SUBALGO_ECB          0x0UL
203         #define     CMD_DMA_SUBALGO_CBC          0x1UL
204         #define     CMD_DMA_SUBALGO_CTR          0x2UL
205         #define     CMD_DMA_SUBALGO_CBC_MAC      0x3UL  // [NOTE] This sub algorithm is AES only
206 		#define     CMD_DMA_SUBALGO_CTR64        0x4UL
207         #define     CMD_DMA_SUBALGO_CMAC_KEY     0x5UL
208         #define     CMD_DMA_SUBALGO_CMAC_ALGO    0x6UL
209 
210     MS_U32          Algo:4;
211         #define     CMD_DMA_ALGO_AES                0x1UL
212         #define     CMD_DMA_ALGO_DES                0x2UL
213         #define     CMD_DMA_ALGO_TDES               0x3UL
214         #define     CMD_DMA_ALGO_M6                 0x4UL
215         #define     CMD_DMA_ALGO_M6_CCBC_DIS        0x5UL
216         #define     CMD_DMA_ALGO_M6_KE56            0x6UL
217         #define     CMD_DMA_ALGO_M6_KE56_CCBC_DIS   0x7UL
218         #define     CMD_DMA_RC4                     0x8UL
219 
220     MS_U32          KeySel:4; //jamietest KeySel:3
221 
222         // bit [3]
223         #define     CMD_DMA_KSEL_CLR_SK             0x8UL
224 
225         // bit [2:0]
226         #define     CMD_DMA_KSEL_SK0                0x0UL //session key 0
227         #define     CMD_DMA_KSEL_SK1                0x1UL
228         #define     CMD_DMA_KSEL_SK2                0x2UL
229         #define     CMD_DMA_KSEL_RESERVED           0x3UL
230         #define     CMD_DMA_KSEL_MK0                0x4UL //SCK3
231         #define     CMD_DMA_KSEL_MK1                0x5UL //SCK4
232         #define     CMD_DMA_KSEL_CCCK               0x6UL //SCK6
233 		#define     CMD_DMA_KSEL_TRNG               0x7UL //PM Key
234 
235 	MS_U32          CMD:3;
236         #define     CMD_DMA_ENCRYPT                 0x2UL
237         #define     CMD_DMA_DECRYPT                 0x3UL
238         #define     CMD_DMA_MASK                    0x2FUL
239 
240     MS_U32          HID:2;                      	//[NOTE] Set by HW only
241         #define     CMD_ACPU                    	0x0UL
242         #define     CMD_R2                      	0x1UL
243         #define     CMD_BGC51                   	0x2UL
244 
245 }CMD_DmaFormat0;
246 
247 
248 typedef struct _CMD_DmaFormat1
249 {
250     MS_U32          TID:16;
251     MS_U32          CaVid:5;
252     MS_U32          IntM:1;
253         #define     CMD_INT_MODE_NONE       0x0UL
254         #define     CMD_INT_MODE_EN         0x1UL
255         //#define     CMD_INT_MODE_WAIT_CLR   0x2   // Block next operation until interrupt is cleared
256     MS_U32          NL:1;
257         #define     CMD_NEW_LINE            0x1UL
258 
259     MS_U32          RR:1;  	// Report Mode
260         #define     CMD_DMA_RPT_MODE_REG        0x0UL
261         #define     CMD_DMA_RPT_MODE_DRAM       0x1UL
262 
263     MS_U32          Dest:1;     // File output Dest
264         #define     CMD_DMA_OUTPUT_DRAM         0x0UL
265         #define     CMD_DMA_OUTPUT_REG          0x1UL   //[NOTE] if HID = R2 , the output will be written into DQRAM
266 
267     MS_U32          SD:2;       // Source Data
268 	    #define     CMD_DMA_DATA_REG            0x0UL
269         #define     CMD_DMA_DATA_DRAM           0x1UL
270         #define     CMD_DMA_DATA_R2             0x2UL //[NOTE] bit[15] = 0, IQMEM. bit[15] = 1, DQMEM
271         #define     CMD_DMA_DATA_HW_INPUT       0x3UL //jamietest
272     MS_U32          DIBS:1;     // Data Input Byte Swap
273     MS_U32          DOBS:1;     // Output Data Byte swap
274     MS_U32          DestKL:1;     // [NOTE] if DestKL = 0 ,Write output data to DRAM, Regfile or QMEM by setting, DestKL = 1 output to SRAM of KL
275         #define     CMD_DMA_OUTPUT_DEST         0x0UL
276         #define     CMD_DMA_OUTPUT_SRAM_KL      0x1UL
277     MS_U32          COS:1;      // Output Data Swap
278     MS_U32          CIS:1;      // Input Data Swap
279 
280 }CMD_DmaFormat1;
281 
282 typedef struct _CMD_DmaFormat2
283 {
284     MS_U32          OBF_IDX_WRITE:5;
285     MS_U32          CTROT:4;
286     MS_U32          DMP:1;
287     MS_U32          TK:1;
288     MS_U32          TsInSb:2;
289     MS_U32          BPS:1;
290     MS_U32          TsSbMk:1;
291     MS_U32          TsSbPn:2;
292         #define     CMD_PARSER_SCB10            0x2UL
293         #define     CMD_PARSER_SCB11            0x3UL
294     MS_U32          InSb:1;
295     MS_U32          RmSb:1;
296     MS_U32          CR:1;
297     MS_U32          IT:1;
298     MS_U32          AT:1;
299     MS_U32          P192:1;
300     MS_U32          TS:1;
301     MS_U32          HDCP:1;
302     MS_U32          HP:1;
303     MS_U32          OBF_IDX_READ:5;
304 
305     MS_U32          NS:1;
306         #define     CMD_DMA_SECURE_IP       0x0UL
307         #define     CMD_DMA_NON_SECURE_IP   0x1UL
308 
309 }CMD_DmaFormat2;
310 
311 typedef struct _CMD_DmaFormat3
312 {
313     MS_U32          Rsv1:4;
314     MS_U32          CRS:1;
315     MS_U32          MP:1;
316     MS_U32          DIV2:1;
317     MS_U32          DK2:1;
318     MS_U32          Rsv2:15;
319     MS_U32          KeySel2:4;
320     MS_U32          Decrypt2:1;
321     MS_U32          IK:1;
322     MS_U32          AP:1;
323     MS_U32          Rsv3:2;
324 
325 }CMD_DmaFormat3;
326 
327 
328 typedef struct _CMD_HashFormat0
329 {
330     MS_U32          CL:6;
331     MS_U32          IntM:1;
332 
333     MS_U32          IWC_Sel:1;
334         #define     CMD_HASH_IWC_RPT        0x0UL
335         #define     CMD_HASH_IWC_CMDQ       0x1UL
336 
337     MS_U32          OVT:1;
338     MS_U32          HOS:1; //reverse hash output
339 
340     MS_U32          Inv16:1; //invere byte order per 16 byte
341     MS_U32          KPAD:1;
342         #define     CMD_HASH_IKP    0x0UL
343         #define     CMD_HASH_OKP    0x1UL
344     MS_U32          HMAC:1;
345         #define     CMD_HASH_NONE   0x0UL
346         #define     CMD_HASH_HMAC   0x1UL
347 
348 
349     MS_U32          HMAC_KeySel:4;
350 
351         // bit [3:0]
352         #define     CMD_HMAC_KSEL_HK                 0x0UL
353         #define     CMD_HMAC_KSEL_STRN               0x1UL
354         #define     CMD_HMAC_KSEL_MK0                0x2UL
355         #define     CMD_HMAC_KSEL_MK1                0x3UL
356         #define     CMD_HMAC_KSEL_CCCK               0x4UL
357         #define     CMD_HMAC_KSEL_SK0                0x5UL
358         #define     CMD_HMAC_KSEL_SK1                0x6UL
359         #define     CMD_HMAC_KSEL_SK2                0x7UL
360         #define     CMD_HMAC_KSEL_SK3                0x8UL
361 
362     MS_U32          DK:1;                                 //HMAC command key, clear seesion key
363         #define     CMD_HMAC_KSEL_CLR_SK             0x1UL  //HMAC KSEL = 5-8
364         #define     CMD_HMAC_KSEL_DIR_HK             0x1UL  //HMAC KSEL = 0
365 
366     MS_U32          Dest:2;
367         #define     CMD_HASH_OUTPUT_RPT     0x0UL
368         #define     CMD_HASH_OUTPUT_R2      0x2UL  //IQMEM or DQMEM
369         #define     CMD_HASH_OUTPUT_DRAM    0x3UL
370 
371     MS_U32          Src:2;
372         #define     CMD_HASH_SRC_DRAM       0x0UL
373         #define     CMD_HASH_SRC_PRV_RPT    0x1UL  //use previous hash operation result in hasg_rpt_reg2~9
374         #define     CMD_HASH_SRC_R2         0x2UL  //[NOTE] bit[15] = 0, IQMEM. bit[15] = 1, DQMEM
375         #define     CMD_HASH_SRC_REG        0x3UL
376     MS_U32          AutoPad:1;
377     MS_U32          InitHashSel:2;
378         #define     CMD_HASH_IV_FIPS        0x0UL
379         #define     CMD_HASH_IV_CMD         0x1UL
380         #define     CMD_HASH_IV_PRV_RPT     0x2UL
381 
382     MS_U32          HashSel:2;  //jamietest
383         #define     CMD_HASH_SHA1           0x0UL
384         #define     CMD_HASH_SHA256         0x1UL
385         #define     CMD_HASH_MD5            0x2UL
386 
387     MS_U32          CMD:3;
388         #define     CMD_HASH_START          0x4UL
389 		#define     CMD_HASH_START_RR       0x6UL
390 
391     MS_U32          HID:2;
392         #define     CMD_ACPU                    0x0UL
393         #define     CMD_R2                      0x1UL
394         #define     CMD_BGC51                   0x2UL
395 
396 }Hash_DmaFormat0;
397 
398 typedef struct _CMD_HashFormat1
399 {
400     MS_U32          TID:16;
401     MS_U32          CaVid:5;
402     MS_U32          OBF_IDX_WRITE:5;
403     MS_U32          OBF_IDX_READ:5;
404     MS_U32          NS:1;
405         #define     CMD_HASH_SECURE_IP       0x0UL
406         #define     CMD_HASH_NON_SECURE_IP   0x1UL
407 
408 }Hash_DmaFormat1;
409 
410 typedef struct _CMD_HashFormat2
411 {
412     MS_U32          Rsv:31;
413     MS_U32          RR:1;
414 
415 }CMD_HashFormat2;
416 
417 
418 //=====================================================================
419 //            RSA Register Definition
420 //=====================================================================
421 
422 #define REG_RSA_BASE         (0x31800UL)
423 
424 #define REG_RSA_COMMON          ( REG_RSA_BASE + 0x0UL )
425 #define REG_RSA_ONEWAY_SYSREG   ( REG_RSA_BASE + 0x1UL )
426 #define REG_RSA_CTRL            ( REG_RSA_BASE + 0x2UL )
427 #define REG_RSA_IND32_ADDR      ( REG_RSA_BASE + 0x3UL )
428 #define REG_RSA_IND32_WDATA     ( REG_RSA_BASE + 0x4UL )
429 
430 #define REG_RSA_SEC_RANGE_START(_a_)   ( REG_RSA_BASE + ((_a_)* 2) + 0x5 ) // a = 0 ~ 5
431 #define REG_RSA_SEC_RANGE_END(_a_)     ( REG_RSA_BASE + ((_a_)* 2) + 0x6 )
432 
433 #define REG_RSA_KEY_SEL         ( REG_RSA_BASE + 0x32UL )
434 #define REG_RSA_WDATA           ( REG_RSA_BASE + 0x39UL )
435 #define REG_RSA_LV_PROTECT_EN   ( REG_RSA_BASE + 0x3aUL )
436 #define REG_RSA_MAILBOX(_a_)    ( REG_RSA_BASE + 0x40UL + (_a_) )
437 
438 //=====================================================================
439 //            MISC Register Definition
440 //=====================================================================
441 #define REG_RNG_BASE        (0x143800UL)//(0xA1C00 * 2)
442 #define REG_OTP_PUB0_BASE   (0xC5800UL)//(0x62C00 * 2)
443 #define REG_OTP_PUB1_BASE   (0xC5A00UL)//(0x62D00 * 2)
444 #define REG_OTP_PUB2_BASE   (0xC5C00UL)//(0x62E00 * 2)
445 
446 #define REG_RNG_TRNG_ACPU           (REG_RNG_BASE + 0x13 * 4)
447 
448 #define REG_RNG_TRNG_ACK_ACPU 0x80000000UL
449 #define REG_RNG_TRNG_VALID_ACPU_MASK 0x00010000UL
450 #define REG_RNG_TRNG_OUT_ACPU_MASK 0x0000FFFFUL
451 
452 #define REG_RNG_TRNG_SCPU           (REG_RNG_BASE + 0x12 * 4)
453 
454 #define REG_RNG_TRNG_ACK_SCPU 0x80000000UL
455 #define REG_RNG_TRNG_VALID_SCPU_MASK 0x00010000UL
456 #define REG_RNG_TRNG_OUT_SCPU_MASK 0x0000FFFFUL
457 
458 //=====================================================================
459 //            IRQ Register Definition
460 //=====================================================================
461 #define REG_HST0_FIQ_STATUS_63_48    (REG_IRQCTRL_BASE + (0xfUL * 4))
462 #define REG_HST0_FIQ_MASK_63_48      (REG_IRQCTRL_BASE + (0x7UL * 4))
463 
464 #define REG_HTS0_FIQ_MASK_CRYPTODMA  (0xFEFFUL)
465 #define REG_HTS0_FIQ_CRYPTODMA       (0x0100UL)   //FIQ 56 is CryptoDMA
466 
467 #endif // #ifndef __REG_CIPHER_H__
468