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