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) 2008-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 drvNDS.h 98 /// @brief NDS Driver Interface 99 /// @author MStar Semiconductor Inc. 100 /////////////////////////////////////////////////////////////////////////////////////////////////// 101 102 #ifndef _DRV_NDS_H_ 103 #define _DRV_NDS_H_ 104 105 106 #ifdef __cplusplus 107 extern "C" 108 { 109 #endif 110 111 //------------------------------------------------------------------------------------------------- 112 // Driver Capability 113 //------------------------------------------------------------------------------------------------- 114 115 116 //------------------------------------------------------------------------------------------------- 117 // Macro and Define 118 //------------------------------------------------------------------------------------------------- 119 #define NDS_ENFLAGS_CTRL_ENC_SUPPORTED 0x01 120 #define NDS_ENFLAGS_CTRL_ENC_HW_FORCED 0x02 // permanently 121 #define NDS_ENFLAGS_CTRL_ENC_SW_FORCED 0x04 // force until reset 122 #define NDS_ENFLAGS_JTAG_PWD 0x08 123 #define NDS_ENFLAGS_BOOTROM 0x10 124 #define NDS_ENFLAGS_DATA_ENC 0x20 125 #define NDS_ENFLAGS_GETRESP2CHALLENGE 0x40 126 127 128 // Predefined by NDS 129 // ref. icq063 130 #define NDS_KTE_ESA_SEL_AES 0x0 131 #define NDS_KTE_ESA_SEL_CSA 0x1 132 #define NDS_KTE_ESA_SEL_DES 0x2 133 #define NDS_KTE_ESA_SEL_TDES 0x3 134 #define NDS_KTE_ESA_SEL_MULTI2 0x4 135 #define NDS_KTE_ESA_SEL_DFAST 0x5 136 #define NDS_KTE_ESA_SEL_USER 0xF 137 138 #define NDS_KTE_ESA_SUB_ECB 0x0 139 #define NDS_KTE_ESA_SUB_CBC 0x1 140 #define NDS_KTE_ESA_SUB_NSA 0x7 141 142 143 144 //------------------------------------------------------------------------------------------------- 145 // Type and Structure 146 //------------------------------------------------------------------------------------------------- 147 148 typedef enum 149 { 150 E_NDS_OK, 151 E_NDS_FAIL, 152 153 } NDS_Result; 154 155 156 typedef enum 157 { 158 E_NDS_SC_EVENT_CARD_REMOVED = 0x00000000, 159 E_NDS_SC_EVENT_CARD_INSERTED = 0x00000001, 160 161 } NDS_SC_Event; 162 163 164 typedef enum 165 { 166 E_NDS_SC_CLK_27M_D6, 167 E_NDS_SC_CLK_27M_D2, 168 E_NDS_SC_CLK_27M_D4, 169 E_NDS_SC_CLK_27M_D8, 170 171 } NDS_SC_Clk; 172 173 174 typedef enum 175 { 176 E_NDS_SC_BAUD_RATE_9600, 177 E_NDS_SC_BAUD_RATE_19200, 178 E_NDS_SC_BAUD_RATE_38400, 179 E_NDS_SC_BAUD_RATE_76800, 180 E_NDS_SC_BAUD_RATE_153600, 181 E_NDS_SC_BAUD_RATE_223200, 182 } NDS_SC_BaudRate; 183 184 185 typedef enum 186 { 187 E_NDS_CAP_ECM_NUM = 0x00, 188 189 E_NDS_CAP_EMM_NUM = 0x10, 190 191 E_NDS_CAP_BUF_PITCH = 0x20, 192 E_NDS_CAP_BUF_ALIGN, 193 E_NDS_CAP_BUF_TOTALSIZE, 194 E_NDS_CAP_RASP_BUF_TOTALSIZE, 195 196 } NDS_Caps; 197 198 199 typedef MS_BOOL (*P_NDS_SC_CbSetVcc)(MS_BOOL b5V); 200 typedef void (*P_NDS_SC_CbEvent)(NDS_SC_Event event); 201 202 typedef struct _NDS_SC_Param 203 { 204 P_NDS_SC_CbSetVcc cbSetVcc; 205 206 P_NDS_SC_CbEvent cbEvent; // for HDI certification 207 MS_BOOL bCommDump; // for card debugging // @TODO: remove 208 209 } NDS_SC_Param; 210 211 212 typedef struct _NDS_FLT_Param 213 { 214 MS_PHYADDR ecm_emm_addr; // NDS_CAP_BUF_SIZE*(NDS_CAP_ECM_NUM+NDS_CAP_EMM_NUM) at least 215 // NDS_CAP_BUF_ALIGN aligned 216 MS_U8* pu8ecm_emm_buf; // virtual address of ecm_emm_addr 217 MS_U32 ecm_emm_size; // total buffer size from emm_ecm_addr 218 } NDS_FLT_Param; 219 220 typedef struct _NDS_RASP_Param 221 { 222 MS_PHYADDR ecm_addr; // NDS_CAP_BUF_SIZE * NDS_CAP_ECM_NUM 223 MS_U8 *pu8ecm_buf; // virtual address of ecm address 224 MS_U32 ecm_size; // total buffer size from emm_ecm_addr 225 226 MS_PHYADDR payload_addr; // NDS_CAP_BUF_SIZE * NDS_CAP_ECM_NUM 227 MS_U8 *pu8playload_buf; // virtual address of ecm address 228 MS_U32 payload_size; // total buffer size from emm_ecm_addr 229 230 } NDS_RASP_Param; 231 232 typedef struct _NDS_Param 233 { 234 NDS_FLT_Param flt; 235 NDS_SC_Param sc; 236 NDS_RASP_Param rasp; 237 } NDS_Param; 238 239 240 //------------------------------------------------------------------------------------------------- 241 // Function and Variable 242 //------------------------------------------------------------------------------------------------- 243 244 NDS_Result MDrv_NDS_Init(NDS_Param *param); 245 NDS_Result MDrv_NDS_Exit(void); 246 NDS_Result MDrv_NDS_PowerOff(void); 247 NDS_Result MDrv_NDS_SetMagicValue(MS_U8 idx, MS_U16 word_0, MS_U16 word_1, MS_U16 word_2, MS_U16 word_3); 248 MS_U32 MDrv_NDS_GetCaps(NDS_Caps cap); 249 250 NDS_Result MDrv_NDS_NSK_Open(MS_U32 nsk_id); 251 NDS_Result MDrv_NDS_NSK_Close(MS_U32 nsk_id); 252 253 254 #ifdef __cplusplus 255 } 256 #endif 257 258 #endif // _DRV_NDS_H_ 259 260