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 /// 97 /// @file drvCA.h 98 /// @brief CA Driver Interface 99 /// @author MStar Semiconductor,Inc. 100 //////////////////////////////////////////////////////////////////////////////////////////////////// 101 102 #ifndef __DRV_CA_H__ 103 #define __DRV_CA_H__ 104 105 #include "MsTypes.h" 106 #include "MsCommon.h" 107 108 #ifdef __cplusplus 109 extern "C" 110 { 111 #endif 112 113 #define MSIF_CA_LIB_CODE {'C','A', '_', '_'} //Lib code 114 #define MSIF_CA_LIBVER {'0','1'} //LIB version 115 #define MSIF_CA_BUILDNUM {'1','1'} //Build Number 116 #define MSIF_CA_CHANGELIST {'0','0','0','0','0','0','0','0'} //P4 ChangeList Number 117 118 #define CA_DRV_VERSION /* Character String for DRV/API version */ \ 119 MSIF_TAG, /* 'MSIF' */ \ 120 MSIF_CLASS, /* '00' */ \ 121 MSIF_CUS, /* 0x0000 */ \ 122 MSIF_MOD, /* 0x0000 */ \ 123 MSIF_CHIP, \ 124 MSIF_CPU, \ 125 MSIF_CA_LIB_CODE, /* IP__ */ \ 126 MSIF_CA_LIBVER, /* 0.0 ~ Z.Z */ \ 127 MSIF_CA_BUILDNUM, /* 00 ~ 99 */ \ 128 MSIF_CA_CHANGELIST, /* CL# */ \ 129 MSIF_OS 130 131 132 typedef enum 133 { 134 E_CA_DEBUG_PORT_I2C, 135 E_CA_DEBUG_PORT_JTAG, 136 E_CA_DEBUG_PORT_SCAN, 137 } CA_DEBUG_PORT; 138 139 typedef enum 140 { 141 E_CA_DEBUG_PORT_OPEN, 142 E_CA_DEBUG_PORT_PASSWD, 143 E_CA_DEBUG_PORT_CLOSE 144 } CA_DEBUG_PORT_MODE; 145 146 typedef enum 147 { 148 E_CA_LOCK_WRITE = 1 << 0, 149 E_CA_LOCK_READ = 1 << 1 150 } CA_LOCK_TYPE; 151 152 typedef enum 153 { 154 E_BOOT_LockWord_W0000_0511_Addr, 155 E_BOOT_LockWord_W0512_1023_Addr, 156 E_BOOT_LockWord_W1024_1535_Addr, 157 E_BOOT_LockWord_W1536_2047_Addr, 158 E_BOOT_LockWord_W2048_2559_Addr, 159 E_BOOT_LockWord_W2560_3071_Addr, 160 E_BOOT_LockWord_W3072_3583_Addr, 161 E_BOOT_LockWord_W3584_3759_Addr, 162 E_LockWord_v_PubOtpOID, 163 E_LockWord_v_PubOtpVID, 164 E_LockWord_v_pubOtpUniqueID1, 165 E_LockWord_v_pubOtpUniqueID2, 166 E_LockWord_CA_Reserved, 167 E_LockWord_CA_MSID, 168 169 E_BOOT_LockWord_W3072_3391_Addr, 170 E_LockWord_v_pubOtpUniqueID3, 171 E_LockWord_v_pubOtpUniqueID4, 172 173 E_LockWord_CAV_SecretKey6_W=0x106, 174 E_LockWord_CAV_SecretKey6_R=0x116, 175 176 E_LockWord_RSA_1_W=0x201, 177 178 E_LockWord_Debugport_PWD_W=0x301, 179 E_LockWord_Debugport_PWD_R=0x311, 180 181 E_LockWord_CA_reserved0=0x401, 182 E_LockWord_CA_reserved1=0x402, 183 E_LockWord_CA_reserved2=0x403, 184 E_LockWord_CA_reserved3=0x404, 185 } CA_OTP_LOCK; 186 187 /* 188 CA Vendor code rule 189 First 8 bits: code by initial of CA Vendor 190 "A": 01, "B": 02, "C": 03, "D": 04, ... , "Y": 19, "Z": 1A 191 Second 4 bits: Increase if the initial of CA Vendor repeat 192 Thrid 4 bits: Serial number of CA Vendor 193 194 0x0000 reserve for NULL 195 0xFFFF for unknow CA 196 */ 197 typedef enum 198 { 199 E_CA_VENDOR_NULL, 200 E_CA_VENDOR_CONAX = 0x0300, 201 E_CA_VENDOR_ECHOSTAR = 0x0500, 202 E_CA_VENDOR_IRDETO = 0x0900, 203 E_CA_VENDOR_LATENS = 0x0C00, 204 E_CA_VENDOR_NDS = 0x0E00, 205 E_CA_VENDOR_NAGRA = 0x0E10, 206 E_CA_VENDOR_SMI = 0x1300, 207 E_CA_VENDOR_VIACCESS = 0x1600, 208 E_CA_VENDOR_VERIMATRIX = 0x1610, 209 E_CA_VENDOR_UNKNOW = 0xFFFF 210 } CA_VENDOR_CODE; 211 212 typedef struct 213 { 214 MS_U32 u32FwAddr; 215 MS_U32 u32FwSize; 216 } CA_BGC_CFG; 217 218 typedef struct 219 { 220 MS_U32 u32BGCMode; //0:dynamic, 1:static 221 MS_U32 u32ProtectAddr; //protected address, physicall address 222 MS_U32 u32ProtectSize; //protected size 223 MS_U8 u8Golden[32]; //password is used for reset section 224 MS_U8 u8ResetPassword[4];//only use for dynamic mode 225 MS_U16 u16Interval; //unit: millisecond, the frequency to check the proteced area 226 } CA_BGC_SEC_CFG; 227 228 typedef enum 229 { 230 E_CA_SECRET_KEY1, 231 E_CA_SECRET_KEY2, 232 E_CA_SECRET_KEY3, 233 E_CA_SECRET_KEY4, 234 E_CA_SECRET_KEY5, 235 E_CA_SECRET_KEY6, 236 E_CA_SECRET_KEY7, 237 E_CA_SECRET_KEY8, 238 } CA_SECRET_KEY; 239 240 typedef enum 241 { 242 E_CA_RSA_KEY0, 243 E_CA_RSA_KEY1, 244 } CA_RSA_KEY; 245 246 typedef enum 247 { 248 E_CA_CUSTOM_SECURE_MAGIC, 249 } CA_CUSTOM_DATA; 250 251 252 DLL_PUBLIC MS_BOOL MDrv_CA_Init(void); 253 DLL_PUBLIC MS_U32 MDrv_CA_MaxDeviceIdSize(void); 254 DLL_PUBLIC MS_U32 MDrv_CA_MaxReservedSize(void); 255 256 //------------------------------------------------------------------------------------------------- 257 // The functions will read/write directly from/to OTP 258 //------------------------------------------------------------------------------------------------- 259 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_EnableSecureBoot(void); 260 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_IsSecureBootEnabled(void); 261 262 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_SetBlockLock(MS_U32 u32Start, MS_U32 u32End, CA_LOCK_TYPE eLockType); 263 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_GetBlockLock(MS_U32 *pu32Start, MS_U32 *pu32End, CA_LOCK_TYPE *eLockType); 264 265 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_SetRSAextID(MS_U32 u32Value); 266 DLL_PUBLIC MS_U32 MDrv_CA_OTP_GetRSAextID(void); 267 268 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_SetTEERSAextID(MS_U32 u32Value); 269 DLL_PUBLIC MS_U32 MDrv_CA_OTP_GetTEERSAextID(void); 270 271 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_SetHASH_REF_VER(MS_U32 u32HASH0_REF_VER, MS_U32 u32HASH2_REF_VER); 272 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_GetHASH_REF_VER(MS_U32 *pu32HASH0_REF_VER, MS_U32 *pu32HASH2_REF_VER); 273 274 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_SetHASH1_REF_VER(MS_U32 u32HASH1_REF_VER); 275 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_GetHASH1_REF_VER(MS_U32 *pu32HASH1_REF_VER); 276 277 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_SetHASH_TEE_REF_VER(MS_U32 u32HASH_TEE0_REF_VER, MS_U32 u32HASH_TEE1_REF_VER, MS_U32 u32HASH_TEE2_REF_VER); 278 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_GetHASH_TEE_REF_VER(MS_U32 *pu32HASH_TEE0_REF_VER, MS_U32 *pu32HASH_TEE1_REF_VER, MS_U32 *pu32HASH_TEE2_REF_VER); 279 280 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_SetDebugPortMode(CA_DEBUG_PORT eDebugPort, CA_DEBUG_PORT_MODE eMode); 281 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_GetDebugPortMode(CA_DEBUG_PORT eDebugPort, CA_DEBUG_PORT_MODE *eMode); 282 283 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_SetDeviceId(const MS_U8 *pu8Did, MS_U32 u32Size); 284 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_GetDeviceId(MS_U8 *pu8Did, MS_U32 u32Size); 285 286 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_WriteReserved(const MS_U8 *pu8RData, MS_U32 u32Size); 287 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_ReadReserved(MS_U8 *pu8RData, MS_U32 u32Size); 288 289 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_EnableSecureCWMode(void); 290 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_IsSecureCWMode(void); 291 292 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_DumpKeyProperty(MS_U32 u32KeyNumber); 293 294 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_SetSecretKey(CA_SECRET_KEY eKeySel, const MS_U8 *pu8SecretKey, MS_U32 u32Size); 295 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_GetSecretKey(CA_SECRET_KEY eKeySel, MS_U8 *pu8SecretKey, MS_U32 u32Size); 296 297 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_SetRSAKey(CA_RSA_KEY eKeySel, const MS_U8 *pu8RSAKey, MS_U32 u32Size); 298 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_GetRSAKey(CA_RSA_KEY eKeySel, MS_U8 *pu8RSAKey, MS_U32 u32Size); 299 300 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_SetDebugPortPassword(CA_DEBUG_PORT eDebugPort, const MS_U8 *pu8Password, MS_U32 u32Size); 301 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_GetDebugPortPassword(CA_DEBUG_PORT eDebugPort, MS_U8 *pu8Password, MS_U32 u32Size); 302 303 //------------------------------------------------------------------------------------------------- 304 // The OTP read/write 305 //------------------------------------------------------------------------------------------------- 306 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_IsBlank(MS_U32 addr); 307 DLL_PUBLIC MS_U32 MDrv_CA_OTP_Read(MS_U32 addr); 308 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_Write(MS_U32 addr, MS_U32 value); 309 310 DLL_PUBLIC MS_BOOL MDrv_CA_Locked(CA_OTP_LOCK eLock); 311 DLL_PUBLIC MS_BOOL MDrv_CA_OTP_Lock(CA_OTP_LOCK eLock); 312 313 //------------------------------------------------------------------------------------------------- 314 // Hardware 16-bits Random number generator 315 //------------------------------------------------------------------------------------------------- 316 DLL_PUBLIC MS_U32 MDrv_CA_Random(void); 317 318 //------------------------------------------------------------------------------------------------- 319 // The CA Vendor 320 //------------------------------------------------------------------------------------------------- 321 DLL_PUBLIC MS_U32 MDrv_CA_OTP_ReadCAVendor(void); 322 323 324 //------------------------------------------------------------------------------------------------- 325 // The CA MBX between R2 and ACPU 326 //------------------------------------------------------------------------------------------------- 327 DLL_PUBLIC MS_BOOL MDrv_CA_MBX_Init(void); 328 DLL_PUBLIC MS_U32 MDrv_CA_MBX_Write(MS_U8* u8Addr, MS_U32 u32Size); 329 DLL_PUBLIC MS_U32 MDrv_CA_MBX_Read(MS_U8* u8Addr, MS_U32 u32Size); 330 331 //------------------------------------------------------------------------------------------------- 332 // The CA STR PM Config 333 //------------------------------------------------------------------------------------------------- 334 DLL_PUBLIC MS_BOOL MDrv_CA_STR_Init(void); 335 DLL_PUBLIC MS_BOOL MDrv_CA_STR_SetParamAddr(MS_U8 *pu8VAddr); 336 DLL_PUBLIC MS_BOOL MDrv_CA_STR_SetMAC(MS_U8 *pu8MAC, MS_U32 u32MACSize); 337 338 //------------------------------------------------------------------------------------------------- 339 // The function will config BGC 340 //------------------------------------------------------------------------------------------------- 341 DLL_PUBLIC MS_BOOL MDrv_CA_BGC_Init(CA_BGC_CFG stBGCCfg); 342 DLL_PUBLIC MS_BOOL MDrv_CA_BGC_SetSection(MS_U32 u32SecId, const CA_BGC_SEC_CFG* const pstSecCfg); 343 DLL_PUBLIC MS_BOOL MDrv_CA_BGC_ResetSection(MS_U32 u32SecId, const MS_U8* const pu8RstPSWD); 344 345 //------------------------------------------------------------------------------------------------- 346 // The function is used for reading/writing a 32-bit customer specific data 347 //------------------------------------------------------------------------------------------------- 348 DLL_PUBLIC MS_BOOL MDrv_CA_CustomData_Write(CA_CUSTOM_DATA eData, MS_U32 u32Data); 349 DLL_PUBLIC MS_BOOL MDrv_CA_CustomData_Read(CA_CUSTOM_DATA eData, MS_U32* pu32Data); 350 351 352 #ifdef __cplusplus 353 } 354 #endif 355 356 #endif 357