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 // file MVD_EX_Common.c
78 // @brief MPEG Video Decoder (MVD) OSAL
79 // @author MStar Semiconductor,Inc.
80 ////////////////////////////////////////////////////////////////////////////////////////////////////
81 #if (!defined(MSOS_TYPE_NUTTX) && !defined(MSOS_TYPE_OPTEE)) || defined(SUPPORT_X_MODEL_FEATURE)
82 #ifndef CONFIG_MBOOT //Add For GPL (content protection)
83
84 #include "MsCommon.h"
85 #include "drvMVD_EX.h"
86 #include "halVPU_EX.h"
87 #include "controller.h"
88 #include "halMVD_EX.h"
89 #include "fwHVD_if.h"
90 #include "../hvd_lite/drvHVD_def.h"
91 #include "drvSYS.h"
92
93
94 #define IPAUTH_VIDEO_MPEG2 (19)
95 #define IPAUTH_VIDEO_MPEG2_HD (20)
96 #define IPAUTH_VIDEO_MPEG4 (21)
97 #define IPAUTH_VIDEO_MPEG4_SD (22)
98 #define IPAUTH_VIDEO_MPEG4_HD (23)
99 #define IPAUTH_VIDEO_DIVX_1080PHD (24)
100 #define IPAUTH_VIDEO_DIVX_DRM (25)
101 #define IPAUTH_VIDEO_DIVX_PLUS (26)
102 #define IPAUTH_VIDEO_VC1 (29)
103 #define IPAUTH_VIDEO_WMV (30)
104 #define IPAUTH_VIDEO_WMDRM_PD (31)
105 #define IPAUTH_VIDEO_WMDRM_ND (32)
106 #define IPAUTH_VIDEO_FLV (34)
107 #define IPAUTH_VIDEO_DIVX_QMOBILE (35)
108 #define IPAUTH_VIDEO_DIVX_MOBILE (36)
109 #define IPAUTH_VIDEO_DIVX_HT (37)
110 #define IPAUTH_VIDEO_DIVX_720PHD (38)
111 #if !defined(SUPPORT_X_MODEL_FEATURE)
112 extern MS_U8 MDrv_AUTH_IPCheck(MS_U8 u8Bit);
113 #endif
114
MDrv_MVD_AUTH_IPCheck(MS_U32 u32CodecType,MS_BOOL * bSupportSDModeOnly)115 MS_BOOL MDrv_MVD_AUTH_IPCheck(MS_U32 u32CodecType,MS_BOOL* bSupportSDModeOnly)
116 {
117 MS_BOOL bIPAUTHReady = FALSE;
118 *bSupportSDModeOnly = TRUE;
119 #if !defined(SUPPORT_X_MODEL_FEATURE)
120 switch (u32CodecType)
121 {
122 case E_MVD_CODEC_MPEG2:
123 if(MDrv_AUTH_IPCheck(IPAUTH_VIDEO_MPEG2_HD) == TRUE)
124 {
125 bIPAUTHReady = TRUE;
126 *bSupportSDModeOnly = FALSE;
127 }
128 else if(MDrv_AUTH_IPCheck(IPAUTH_VIDEO_MPEG2) == TRUE)
129 {
130 bIPAUTHReady = TRUE;
131 }
132 break;
133 case E_MVD_CODEC_MPEG4:
134 case E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER:
135 if(MDrv_AUTH_IPCheck(IPAUTH_VIDEO_MPEG4_HD) == TRUE)
136 {
137 bIPAUTHReady = TRUE;
138 *bSupportSDModeOnly = FALSE;
139 }
140 else if((MDrv_AUTH_IPCheck(IPAUTH_VIDEO_MPEG4) == TRUE) || (MDrv_AUTH_IPCheck(IPAUTH_VIDEO_MPEG4_SD) == TRUE))
141 {
142 bIPAUTHReady = TRUE;
143 }
144 break;
145 case E_MVD_CODEC_DIVX311:
146 if ((MDrv_AUTH_IPCheck(IPAUTH_VIDEO_DIVX_1080PHD) == TRUE)
147 ||(MDrv_AUTH_IPCheck(IPAUTH_VIDEO_DIVX_DRM) == TRUE)
148 ||(MDrv_AUTH_IPCheck(IPAUTH_VIDEO_DIVX_PLUS) == TRUE)
149 ||(MDrv_AUTH_IPCheck(IPAUTH_VIDEO_DIVX_HT) == TRUE))
150 {
151 bIPAUTHReady = TRUE;
152 *bSupportSDModeOnly = FALSE;
153 }
154 else if((MDrv_AUTH_IPCheck(IPAUTH_VIDEO_DIVX_QMOBILE) == TRUE) || (MDrv_AUTH_IPCheck(IPAUTH_VIDEO_DIVX_MOBILE) == TRUE))
155 {
156 bIPAUTHReady = TRUE;
157 }
158 break;
159 case E_MVD_CODEC_FLV:
160 if (MDrv_AUTH_IPCheck(IPAUTH_VIDEO_FLV) == TRUE)
161 {
162 *bSupportSDModeOnly = FALSE;
163 bIPAUTHReady = TRUE;
164 }
165 break;
166 case E_MVD_CODEC_VC1_ADV:
167 case E_MVD_CODEC_VC1_MAIN:
168 if ((MDrv_AUTH_IPCheck(IPAUTH_VIDEO_VC1) == TRUE)
169 ||(MDrv_AUTH_IPCheck(IPAUTH_VIDEO_WMV) == TRUE)
170 ||(MDrv_AUTH_IPCheck(IPAUTH_VIDEO_WMDRM_PD) == TRUE)
171 ||(MDrv_AUTH_IPCheck(IPAUTH_VIDEO_WMDRM_ND) == TRUE))
172 {
173 *bSupportSDModeOnly =FALSE;
174 bIPAUTHReady = TRUE;
175 }
176 break;
177 default:
178 bIPAUTHReady = FALSE;;
179 }
180
181 if(bIPAUTHReady == FALSE)
182 {
183 HVD_PRINT("%s fail!!\r\n", __FUNCTION__);
184 }
185 #endif
186 return bIPAUTHReady;
187 }
188 #endif
189
190
191 #ifdef VDEC3
192 #define MVD_MAX_STREAMS 16
193 #else
194 #define MVD_MAX_STREAMS 2
195 #endif
196
197 #define VPU_MAIL_BOX_SEND_FAIL 1
198 #define CODEC_KEY_COMPARE_TIMEOUT 2
199 extern MS_U8 u8CodecCompare[MVD_MAX_STREAMS];
200 extern HVD_Return HAL_HVD_EX_SetCmd(MS_U32 u32Id, HVD_User_Cmd eUsrCmd, MS_U32 u32CmdArg);
201 #define _VDEC_GET_IDX(x) (MS_U8)((x)>>24)
202
203 #if defined(CHIP_KANO)
MDrv_MVDSendVPUCMD(MS_U32 u32Id,MS_U32 u32CMD,MS_U32 u32Arg)204 MS_BOOL MDrv_MVDSendVPUCMD(MS_U32 u32Id,MS_U32 u32CMD,MS_U32 u32Arg)
205 {
206 MS_BOOL bRet = TRUE;
207 MS_U8 u8Idx = _VDEC_GET_IDX(u32Id);
208
209 HAL_VPU_EX_Mutex_Lock();
210 if(HAL_HVD_EX_SetCmd(u32Id, u32CMD, u32Arg) != E_HVD_RETURN_SUCCESS)
211 {
212 bRet = FALSE;
213 }
214 HAL_VPU_EX_Mutex_UnLock();
215
216 if(bRet == FALSE)
217 {
218 HVD_PRINT("[Info]Case1\n");
219 u8CodecCompare[u8Idx] = VPU_MAIL_BOX_SEND_FAIL;
220 }
221
222 return bRet;
223 }
224
MDrv_MVDSendCodecKey(MS_U32 u32Id,MS_U8 u8Decoder,MS_U16 u16CodecKey)225 MS_BOOL MDrv_MVDSendCodecKey(MS_U32 u32Id,MS_U8 u8Decoder,MS_U16 u16CodecKey)
226 {
227 MS_U8 u8Idx = _VDEC_GET_IDX(u32Id);
228 MS_U8 u8VPUIdx = HAL_VPU_EX_GetOffsetIdx(u32Id);
229 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
230 MS_U32 u32Timeout = 0;
231 struct _ctl_info *ctl_ptr = (struct _ctl_info *) MsOS_PA2KSEG1(HAL_VPU_EX_GetFWCodeAddr(u32Id) + CTL_INFO_ADDR);
232
233 if(MDrv_MVDSendVPUCMD(u32Id,E_NST_CMD_COMMON_CMD1,(((VDEC_TAG<<24)&0xff000000))|(((u8Decoder<<16)&0xff0000))|(u16CodecKey&0xffff)) == FALSE)
234 {
235 HAL_MVD_DeleteTask(u8HalIdx, (HAL_VPU_StreamId)MDrv_MVD_GetVpuStreamId(u32Id));
236 return FALSE;
237 }
238
239 if(MDrv_MVDSendVPUCMD(u32Id,E_NST_CMD_COMMON_MASK,0) == FALSE)
240 {
241 HAL_MVD_DeleteTask(u8HalIdx, (HAL_VPU_StreamId)MDrv_MVD_GetVpuStreamId(u32Id));
242 return FALSE;
243 }
244
245 MsOS_ReadMemory();
246 u32Timeout = MsOS_GetSystemTime() + 500; //timeout 500 ms
247 while (CTL_TASK_CMD != ctl_ptr->task_statue[u8VPUIdx])
248 {
249 if (MsOS_GetSystemTime() > u32Timeout)
250 {
251 HVD_PRINT("[Info]Case2\n");
252 u8CodecCompare[u8Idx] = CODEC_KEY_COMPARE_TIMEOUT;
253 HAL_MVD_DeleteTask(u8HalIdx, (HAL_VPU_StreamId)MDrv_MVD_GetVpuStreamId(u32Id));
254 return FALSE;
255 }
256 MsOS_ReadMemory();
257 }
258 return TRUE;
259 }
260 #endif
261
_MVD_Init(MS_U32 u32Id,MVD_CodecType u8CodecType,MVD_SrcMode u8BSProviderMode,MS_U8 bDisablePESParsing)262 MS_BOOL _MVD_Init(MS_U32 u32Id, MVD_CodecType u8CodecType, MVD_SrcMode u8BSProviderMode, MS_U8 bDisablePESParsing)
263 {
264 MS_U8 u8HalIdx = MVD_GetHalIdx(u32Id);
265 MS_U8 u8ChipECORev = MDrv_SYS_GetChipRev();
266 //MVD_PRINT("u8CodecType=0x%x\n", u8CodecType);
267 //MVD_PRINT("u8BSProviderMode=0x%x\n", u8BSProviderMode);
268 if (HAL_MVD_SetCodecInfo(u8HalIdx, u8CodecType, u8BSProviderMode, bDisablePESParsing, u8ChipECORev) == FALSE)
269 {
270 HVD_PRINT("%s fail!!\r\n", __FUNCTION__);
271 return FALSE;
272 }
273
274 #ifndef CONFIG_MBOOT //Add For GPL (content protection)
275 #if defined(CHIP_KANO)
276 if(MDrv_MVDSendCodecKey(u32Id,MVD_DECODER,u8CodecType) == FALSE)
277 {
278 return FALSE;
279 }
280 else
281 #endif
282 #endif
283 {
284 return TRUE;
285 }
286 }
287
288 #endif
289