yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [diff] [blame^] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2005 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *****************************************************************************/ |
| 35 | |
| 36 | /******************************************************************************* |
| 37 | * |
| 38 | * Filename: |
| 39 | * --------- |
| 40 | * che_hw.h |
| 41 | * |
| 42 | * Project: |
| 43 | * -------- |
| 44 | * MAUI |
| 45 | * |
| 46 | * Description: |
| 47 | * ------------ |
| 48 | * Cipher/hash engine hw register definitions. |
| 49 | * |
| 50 | * Author: |
| 51 | * ------- |
| 52 | * ------- |
| 53 | * |
| 54 | *============================================================================== |
| 55 | * HISTORY |
| 56 | * Below this line, this part is controlled by ClearCase. DO NOT MODIFY!! |
| 57 | *------------------------------------------------------------------------------ |
| 58 | * $Log$ |
| 59 | * |
| 60 | * 11 26 2010 carlos.yeh |
| 61 | * removed! |
| 62 | * Initial checkin for HAL |
| 63 | * |
| 64 | * removed! |
| 65 | * removed! |
| 66 | * |
| 67 | * |
| 68 | * removed! |
| 69 | * removed! |
| 70 | * |
| 71 | * |
| 72 | * removed! |
| 73 | * removed! |
| 74 | * |
| 75 | * |
| 76 | * removed! |
| 77 | * removed! |
| 78 | * |
| 79 | * |
| 80 | * removed! |
| 81 | * removed! |
| 82 | * |
| 83 | * |
| 84 | * removed! |
| 85 | * removed! |
| 86 | * |
| 87 | * |
| 88 | * removed! |
| 89 | * removed! |
| 90 | * |
| 91 | * |
| 92 | * removed! |
| 93 | * removed! |
| 94 | * |
| 95 | * |
| 96 | * removed! |
| 97 | * removed! |
| 98 | * |
| 99 | * |
| 100 | * Rev 1.1 Jun 06 2005 19:29:20 mtk00288 |
| 101 | * Revise HW register. |
| 102 | * Resolution for 11205: [Video/Drv][Add feature]Add MT6228 option |
| 103 | * |
| 104 | * Rev 1.0 Jun 06 2005 12:57:20 BM |
| 105 | * Initial revision. |
| 106 | * |
| 107 | *------------------------------------------------------------------------------ |
| 108 | * Upper this line, this part is controlled by ClearCase. DO NOT MODIFY!! |
| 109 | *============================================================================== |
| 110 | *******************************************************************************/ |
| 111 | #ifndef CHE_HW_H |
| 112 | #define CHE_HW_H |
| 113 | |
| 114 | #include "drvpdn.h" |
| 115 | #include "reg_base.h" |
| 116 | #include "che_api.h" |
| 117 | |
| 118 | #ifndef __HW_CHE__ |
| 119 | #define che_slowdown() |
| 120 | #define che_recover() |
| 121 | #else |
| 122 | void che_slowdown(void); |
| 123 | void che_recover(void); |
| 124 | #endif |
| 125 | |
| 126 | |
| 127 | #if defined(__CLKG_DEFINE__) |
| 128 | #define CHE_PDN_SET (CG_SET0) |
| 129 | #define CHE_PDN_CLR (CG_CLR0) |
| 130 | #else |
| 131 | #define CHE_PDN_SET (0x80000310) |
| 132 | #define CHE_PDN_CLR (0x80000320) |
| 133 | #endif |
| 134 | |
| 135 | #define CHE_PDN_BIT 0x10 |
| 136 | |
| 137 | #define CHE_START (CHE_base+0x0) |
| 138 | #define CHE_CON (CHE_base+0x4) |
| 139 | #define CHE_IN0 (CHE_base+0x8) |
| 140 | #define CHE_IN1 (CHE_base+0xc) |
| 141 | #define CHE_IN2 (CHE_base+0x10) |
| 142 | #define CHE_IN3 (CHE_base+0x14) |
| 143 | #define CHE_SDRAT (CHE_base+0x18) |
| 144 | #define CHE_PCNT (CHE_base+0x1c) /*RO*/ |
| 145 | #define CHE_STAT (CHE_base+0x20) /*RO*/ |
| 146 | #define CHE_CDES (CHE_base+0x24) /*RO*/ |
| 147 | #define CHE_INTSTA (CHE_base+0x28) /*RC*/ |
| 148 | #define CHE_INTEN (CHE_base+0x2c) /*RW*/ |
| 149 | #define CHE_BCON (CHE_base+0xc0) |
| 150 | #define CHE_BSRC (CHE_base+0xc4) |
| 151 | #define CHE_BSEED (CHE_base+0xc8) |
| 152 | #define CHE_BENC (CHE_base+0xcc) |
| 153 | #define CHE_BDEC (CHE_base+0xd0) |
| 154 | |
| 155 | /*CHE_START*/ |
| 156 | #define CHE_START_DONE 0x0000 |
| 157 | #define CHE_START_STUD 0x0001 |
| 158 | #define CHE_START_LAST 0x0002 |
| 159 | #define CHE_START_WSTAT 0x0004 |
| 160 | #define CHE_START_RSTAT 0x0008 |
| 161 | #define CHE_START_CLEAR 0x0010 |
| 162 | #define CHE_START_UPDES 0x0020 |
| 163 | #define CHE_START_WKEY 0x0040 |
| 164 | #define CHE_START_RKEY 0x0080 |
| 165 | #define CHE_START_UPIV01 0x0100 |
| 166 | #define CHE_START_UPIV23 0x0200 |
| 167 | #define CHE_START_UPK01 0x0400 |
| 168 | #define CHE_START_UPK23 0x0800 |
| 169 | #define CHE_START_UPK45 0x1000 |
| 170 | #define CHE_START_UPK67 0x2000 |
| 171 | |
| 172 | /*CHE_CON*/ |
| 173 | #define CHE_CON_ATYPE_MASK 0x0007 |
| 174 | #define CHE_CON_ATYPE_MD5 0x0 |
| 175 | #define CHE_CON_ATYPE_SHA1 0x1 |
| 176 | #define CHE_CON_ATYPE_DES 0x2 |
| 177 | #define CHE_CON_ATYPE_3DES 0x3 |
| 178 | #define CHE_CON_ATYPE_AES_128 0x4 |
| 179 | #define CHE_CON_ATYPE_AES_192 0x5 |
| 180 | #define CHE_CON_ATYPE_AES_256 0x6 |
| 181 | #define CHE_CON_DECIPHER 0x0000 |
| 182 | #define CHE_CON_CIPHER 0x0008 |
| 183 | #define CHE_CON_SMODE_ECB 0x0000 |
| 184 | #define CHE_CON_SMODE_CBC 0x0010 |
| 185 | #define CHE_CON_DKEY1_64BIT 0x0000 |
| 186 | #define CHE_CON_DKEY1_56BIT 0x0020 |
| 187 | #define CHE_CON_DKEY2_64BIT 0x0000 |
| 188 | #define CHE_CON_DKEY2_56BIT 0x0040 |
| 189 | #define CHE_CON_DKEY3_64BIT 0x0000 |
| 190 | #define CHE_CON_DKEY3_56BIT 0x0080 |
| 191 | |
| 192 | /*CHE_IN0*/ |
| 193 | #define CHE_IN0_MASK 0xffffffff |
| 194 | |
| 195 | /*CHE_IN1*/ |
| 196 | #define CHE_IN1_MASK 0xffffffff |
| 197 | |
| 198 | /*CHE_IN2*/ |
| 199 | #define CHE_IN2_MASK 0xffffffff |
| 200 | |
| 201 | /*CHE_IN3*/ |
| 202 | #define CHE_IN3_MASK 0xffffffff |
| 203 | |
| 204 | /*CHE_SDRAT*/ |
| 205 | #define CHE_SDRAT_MASK 0x00ff /*RW*/ |
| 206 | |
| 207 | /*CHE_PCNT*/ |
| 208 | #define CHE_PCNT_MASK 0x001f |
| 209 | |
| 210 | /*CHE_STAT*/ |
| 211 | #define CHE_STAT_MASK 0x0007 /*RO*/ |
| 212 | #define CHE_STAT_OK 0x0000 /*RO*/ |
| 213 | #define CHE_STAT_CTRL_ERR 0x0001 /*RO*/ |
| 214 | #define CHE_STAT_ZEROLEN 0x0002 /*RO*/ |
| 215 | #define CHE_STAT_RESUME 0x0003 /*RO*/ |
| 216 | #define CHE_STAT_BUSY 0x0004 /*RO*/ |
| 217 | |
| 218 | /*CHE_CDES*/ |
| 219 | #define CHE_CDES_MASK 0xffffffff |
| 220 | |
| 221 | /*CHE_INTSTA*/ |
| 222 | #define CHE_INTSTA_OK 0x1 |
| 223 | #define CHE_INTSTA_FAIL 0x2 |
| 224 | #define CHE_INTSTA_RESUME 0x3 //?? |
| 225 | |
| 226 | /*CHE_INTEN*/ |
| 227 | #define CHE_INTEN_OK 0x1 |
| 228 | #define CHE_INTEN_FAIL 0x2 |
| 229 | |
| 230 | #define CHE_REGSET_START(_data) \ |
| 231 | {\ |
| 232 | DRV_WriteReg32(CHE_START, (_data));\ |
| 233 | che_hw_setting[CHE_HW_SETTING_START] = (_data);\ |
| 234 | } |
| 235 | |
| 236 | #define CHE_REGSET_INTEN(_data) \ |
| 237 | {\ |
| 238 | DRV_WriteReg32(CHE_INTEN, (_data));\ |
| 239 | che_hw_setting[CHE_HW_SETTING_INTEN] = (_data);\ |
| 240 | } |
| 241 | |
| 242 | #define CHE_REGSET_CON(_data) \ |
| 243 | {\ |
| 244 | DRV_WriteReg32(CHE_CON, (_data));\ |
| 245 | che_hw_setting[CHE_HW_SETTING_CON] = (_data);\ |
| 246 | } |
| 247 | |
| 248 | #define CHE_REGSET_KEY0(_data) \ |
| 249 | {\ |
| 250 | DRV_WriteReg32(CHE_IN0, (_data));\ |
| 251 | che_hw_setting[CHE_HW_SETTING_KEY0] = (_data);\ |
| 252 | } |
| 253 | |
| 254 | #define CHE_REGSET_KEY1(_data) \ |
| 255 | {\ |
| 256 | DRV_WriteReg32(CHE_IN1, (_data));\ |
| 257 | che_hw_setting[CHE_HW_SETTING_KEY1] = (_data);\ |
| 258 | } |
| 259 | |
| 260 | #define CHE_REGSET_KEY2(_data) \ |
| 261 | {\ |
| 262 | DRV_WriteReg32(CHE_IN2, (_data));\ |
| 263 | che_hw_setting[CHE_HW_SETTING_KEY2] = (_data);\ |
| 264 | } |
| 265 | |
| 266 | #define CHE_REGSET_KEY3(_data) \ |
| 267 | {\ |
| 268 | DRV_WriteReg32(CHE_IN3, (_data));\ |
| 269 | che_hw_setting[CHE_HW_SETTING_KEY3] = (_data);\ |
| 270 | } |
| 271 | |
| 272 | #define CHE_REGSET_KEY4(_data) \ |
| 273 | {\ |
| 274 | DRV_WriteReg32(CHE_IN0, (_data));\ |
| 275 | che_hw_setting[CHE_HW_SETTING_KEY4] = (_data);\ |
| 276 | } |
| 277 | |
| 278 | #define CHE_REGSET_KEY5(_data) \ |
| 279 | {\ |
| 280 | DRV_WriteReg32(CHE_IN1, (_data));\ |
| 281 | che_hw_setting[CHE_HW_SETTING_KEY5] = (_data);\ |
| 282 | } |
| 283 | |
| 284 | #define CHE_REGSET_KEY6(_data) \ |
| 285 | {\ |
| 286 | DRV_WriteReg32(CHE_IN2, (_data));\ |
| 287 | che_hw_setting[CHE_HW_SETTING_KEY6] = (_data);\ |
| 288 | } |
| 289 | |
| 290 | #define CHE_REGSET_KEY7(_data) \ |
| 291 | {\ |
| 292 | DRV_WriteReg32(CHE_IN3, (_data));\ |
| 293 | che_hw_setting[CHE_HW_SETTING_KEY7] = (_data);\ |
| 294 | } |
| 295 | |
| 296 | #define CHE_REGSET_CKEY(_data) \ |
| 297 | {\ |
| 298 | DRV_WriteReg32(CHE_IN3, (_data));\ |
| 299 | che_hw_setting[CHE_HW_SETTING_CKEY] = (_data);\ |
| 300 | } |
| 301 | |
| 302 | #define CHE_REGSET_IV0(_data) \ |
| 303 | {\ |
| 304 | DRV_WriteReg32(CHE_IN0, (_data));\ |
| 305 | che_hw_setting[CHE_HW_SETTING_IV0] = (_data);\ |
| 306 | } |
| 307 | |
| 308 | #define CHE_REGSET_IV1(_data) \ |
| 309 | {\ |
| 310 | DRV_WriteReg32(CHE_IN1, (_data));\ |
| 311 | che_hw_setting[CHE_HW_SETTING_IV1] = (_data);\ |
| 312 | } |
| 313 | |
| 314 | #define CHE_REGSET_IV2(_data) \ |
| 315 | {\ |
| 316 | DRV_WriteReg32(CHE_IN2, (_data));\ |
| 317 | che_hw_setting[CHE_HW_SETTING_IV2] = (_data);\ |
| 318 | } |
| 319 | |
| 320 | #define CHE_REGSET_IV3(_data) \ |
| 321 | {\ |
| 322 | DRV_WriteReg32(CHE_IN3, (_data));\ |
| 323 | che_hw_setting[CHE_HW_SETTING_IV3] = (_data);\ |
| 324 | } |
| 325 | |
| 326 | #define CHE_REGSET_SRC(_data) \ |
| 327 | {\ |
| 328 | DRV_WriteReg32(CHE_IN0, _data);\ |
| 329 | che_hw_setting[CHE_HW_SETTING_SRC] = (_data);\ |
| 330 | } |
| 331 | |
| 332 | #define CHE_REGSET_DST(_data) \ |
| 333 | {\ |
| 334 | DRV_WriteReg32(CHE_IN1, _data);\ |
| 335 | che_hw_setting[CHE_HW_SETTING_DST] = (_data);\ |
| 336 | } |
| 337 | |
| 338 | #define CHE_REGSET_LEN(_data) \ |
| 339 | {\ |
| 340 | DRV_WriteReg32(CHE_IN2, _data);\ |
| 341 | che_hw_setting[CHE_HW_SETTING_LEN] = (_data);\ |
| 342 | } |
| 343 | |
| 344 | #define CHE_REGSET_SADDR(_data) \ |
| 345 | {\ |
| 346 | DRV_WriteReg32(CHE_IN3, _data);\ |
| 347 | che_hw_setting[CHE_HW_SETTING_SADDR] = (_data);\ |
| 348 | } |
| 349 | |
| 350 | #define CHE_WAIT_STAT_OK() \ |
| 351 | {\ |
| 352 | kal_uint32 status;\ |
| 353 | while(DRV_Reg32(CHE_STAT) != CHE_STAT_OK);\ |
| 354 | status = DRV_Reg32(CHE_INTSTA);\ |
| 355 | } |
| 356 | |
| 357 | #define CHE_WAIT_STAT_RESUME() \ |
| 358 | {\ |
| 359 | kal_uint32 status;\ |
| 360 | while(DRV_Reg32(CHE_STAT) != CHE_STAT_RESUME);\ |
| 361 | status = DRV_Reg32(CHE_INTSTA);\ |
| 362 | } |
| 363 | |
| 364 | |
| 365 | |
| 366 | #define CHE_MAX_CHANNEL 32 |
| 367 | #define CHE_HW_STATUS_SIZE 120 |
| 368 | //#define CHE_INTR_ENABLE |
| 369 | |
| 370 | /*AES 10000, DES 20000*/ |
| 371 | #define ISR_ENABLE_DATA_LENGTH 15000 |
| 372 | |
| 373 | typedef enum { |
| 374 | CHE_HW_SETTING_START = 0, |
| 375 | CHE_HW_SETTING_CON, /*1*/ |
| 376 | CHE_HW_SETTING_KEY0, /*2*/ |
| 377 | CHE_HW_SETTING_KEY1, /*3*/ |
| 378 | CHE_HW_SETTING_KEY2, /*4*/ |
| 379 | CHE_HW_SETTING_KEY3, /*5*/ |
| 380 | CHE_HW_SETTING_KEY4, /*6*/ |
| 381 | CHE_HW_SETTING_KEY5, /*7*/ |
| 382 | CHE_HW_SETTING_KEY6, /*8*/ |
| 383 | CHE_HW_SETTING_KEY7, /*9*/ |
| 384 | CHE_HW_SETTING_CKEY, /*10*/ |
| 385 | CHE_HW_SETTING_IV0, /*11*/ |
| 386 | CHE_HW_SETTING_IV1, /*12*/ |
| 387 | CHE_HW_SETTING_IV2, /*13*/ |
| 388 | CHE_HW_SETTING_IV3, /*14*/ |
| 389 | CHE_HW_SETTING_SRC, /*15*/ |
| 390 | CHE_HW_SETTING_DST, /*16*/ |
| 391 | CHE_HW_SETTING_LEN, /*17*/ |
| 392 | CHE_HW_SETTING_SADDR, /*18*/ //state addr |
| 393 | CHE_HW_SETTING_INTEN, /*19*/ |
| 394 | CHE_HW_SETTING_DUMMY1, /*20*/ |
| 395 | CHE_HW_SETTING_DUMMY2, /*21*/ |
| 396 | CHE_HW_SETTING_DUMMY3, /*22*/ |
| 397 | CHE_HW_SETTING_DUMMY4, /*23*/ |
| 398 | CHE_HW_SETTING_DUMMY5, /*24*/ |
| 399 | CHE_HW_SETTING_DUMMY6, /*25*/ |
| 400 | CHE_HW_SETTING_DUMMY7, /*26*/ |
| 401 | CHE_HW_SETTING_DUMMY8, /*27*/ |
| 402 | MAX_CHE_HW_SETTING /*28*/ |
| 403 | } CHE_HW_SETTING; |
| 404 | |
| 405 | typedef struct { |
| 406 | kal_uint32 che_glb_handle; /*CHE global handle*/ |
| 407 | kal_uint8 che_lastest_finish_handle; /*Avoid race condition*/ |
| 408 | kal_bool che_machie_running; /*Avoid race condition*/ |
| 409 | kal_uint32 che_dbg_line; /*Just for debug*/ |
| 410 | kal_uint8 che_sm_handle; /*CHE SM control*/ |
| 411 | kal_hisrid hisr; /*CHE HISR*/ |
| 412 | kal_eventgrpid event; /*CHE EVENT*/ |
| 413 | } CHE_CB_DATA_STRUCT; |
| 414 | |
| 415 | |
| 416 | void convert_des_Key(kal_uint8 *key, kal_uint32 *ckey); |
| 417 | void convert_3des_Key(kal_uint8 *key, kal_uint32 *ckey); |
| 418 | void convert_aes_Key(kal_uint8 *key, kal_uint8 *ckey); |
| 419 | void convert_aes_128_key(kal_uint8 *key, kal_uint8 *ckey); |
| 420 | void convert_aes_192_key(kal_uint8 *key, kal_uint8 *ckey); |
| 421 | void convert_aes_256_key(kal_uint8 *key, kal_uint8 *ckey); |
| 422 | |
| 423 | void des_set_iv(kal_uint8 *cheIV); |
| 424 | void aes_set_iv(kal_uint8 *cheIV); |
| 425 | |
| 426 | |
| 427 | kal_bool che_hw_aes(STCHE* che_context, kal_uint8 *srcData, kal_uint8 *encryptedData, kal_uint32 data_length, CHE_OPERATION_MODE mode, CHE_ACTION act, kal_bool last_block); |
| 428 | kal_bool che_hw_des(STCHE* che_context,kal_uint8 *srcData, kal_uint8 *encryptedData, kal_uint32 data_length, CHE_TYPE type, CHE_OPERATION_MODE mode, CHE_ACTION act, kal_bool last_block); |
| 429 | kal_uint32 che_hw_hash(STCHE* che_context, CHE_TYPE type, kal_uint8 *srcData, kal_uint8 *output_data, kal_uint32 data_length, kal_bool last_block); |
| 430 | |
| 431 | |
| 432 | #endif |