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-2011 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 halMJPEG.c
98 /// @brief MJPEG hal interface
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101
102 #if (!defined(MSOS_TYPE_NUTTX) && !defined(MSOS_TYPE_OPTEE)) || defined(SUPPORT_X_MODEL_FEATURE)
103 //-------------------------------------------------------------------------------------------------
104 // Include Files
105 //-------------------------------------------------------------------------------------------------
106 // Common Definition
107 #include "MsCommon.h"
108 #include "MsOS.h"
109 #include "halCHIP.h"
110 // Internal Definition
111 //#include "regCHIP.h"
112 #include "drvMMIO.h" //get RIU base
113 #include "drvMJPEG.h"
114 #include "VirtualhalMJPEG.h"
115
116 #include "regVPU_EX.h" // For VPU
117 #include "halVPU_EX.h"
118
119
120 #include "drvSYS.h"
121
122 #include "../hvd_v3/fwHVD_if.h"
123 #define NJPD_FW_VERSION "NJPD.FW.00130062"
124
125
126
127 static HAL_MJPEG_Stream _stMJPEGStream[E_MJPEG_MJPEG_TOTAL] =
128 {
129 #ifdef VDEC3
130 {E_HAL_MJPEG_N_STREAM0, FALSE},
131 {E_HAL_MJPEG_N_STREAM1, FALSE},
132 {E_HAL_MJPEG_N_STREAM2, FALSE},
133 {E_HAL_MJPEG_N_STREAM3, FALSE},
134 {E_HAL_MJPEG_N_STREAM4, FALSE},
135 {E_HAL_MJPEG_N_STREAM5, FALSE},
136 {E_HAL_MJPEG_N_STREAM6, FALSE},
137 {E_HAL_MJPEG_N_STREAM7, FALSE},
138 {E_HAL_MJPEG_N_STREAM8, FALSE},
139 #else
140 {E_HAL_MJPEG_MAIN_STREAM0, FALSE},
141 {E_HAL_MJPEG_SUB_STREAM0, FALSE},
142 #endif
143 };
144
145 /*================================ MJPEG =====================================*/
146
147 /******************************************************************************/
148 ///Stop VPU
149 /******************************************************************************/
VirtualHal_MJPEG_StopVPU(void)150 void VirtualHal_MJPEG_StopVPU(void)
151 {
152 //HAL_VPU_PowerCtrl(FALSE);
153 HAL_VPU_EX_DeInit();
154 }
155
156 /******************************************************************************/
157 ///Release VPU
158 /******************************************************************************/
VirtualHal_MJPEG_ReleaseVPU(void)159 void VirtualHal_MJPEG_ReleaseVPU(void)
160 {
161 HAL_VPU_EX_SwRstRelse();
162 }
163
164
165 /******************************************************************************/
166 ///Check VPU MailBox ready or not
167 ///@return TRUE or FALSE
168 /// - TRUE, MailBox is free
169 /// - FALSE, MailBox is busy
170 ///@param u8MBox \b IN: MailBox to check
171 /// - VPU_HI_MBOX0,
172 /// - VPU_HI_MBOX1,
173 /// - VPU_RISC_MBOX0,
174 /// - VPU_RISC_MBOX1,
175 /******************************************************************************/
VirtualHal_MJPEG_IsVPUMBoxReady(MS_U8 u8MBox)176 MS_BOOL VirtualHal_MJPEG_IsVPUMBoxReady(MS_U8 u8MBox)
177 {
178 MS_BOOL bResult = FALSE;
179 bResult = HAL_VPU_EX_MBoxRdy((MS_U32)u8MBox);
180 return bResult;
181 }
182
183 /******************************************************************************/
184 ///Read message from VPU
185 ///@return TRUE or FALSE
186 /// - TRUE, success
187 /// - FALSE, failed
188 ///@param u8MBox \b IN: MailBox to read
189 /// - VPU_RISC_MBOX0
190 /// - VPU_RISC_MBOX1
191 ///@param u32Msg \b OUT: message read
192 /******************************************************************************/
VirtualHal_MJPEG_ReadVPUMBox(MS_U8 u8MBox,MS_U32 * u32Msg)193 MS_BOOL VirtualHal_MJPEG_ReadVPUMBox(MS_U8 u8MBox, MS_U32 *u32Msg)
194 {
195 MS_BOOL bResult = TRUE;
196 bResult = HAL_VPU_EX_MBoxRead((MS_U32)u8MBox, u32Msg);
197 return bResult;
198 }
199
200 ///-----------------------------------------------------------------------------
201 /// Send message to VPU
202 /// @return TRUE or FALSE
203 /// - TRUE, Success
204 /// - FALSE, Failed
205 /// @param u8MBox \b IN: MailBox
206 /// - VPU_HI_MBOX0,
207 /// - VPU_HI_MBOX1,
208 ///-----------------------------------------------------------------------------
VirtualHal_MJPEG_SendVPUMBox(MS_U32 u32Id,MS_U8 u8MBox,MS_U32 u32Msg)209 MS_BOOL VirtualHal_MJPEG_SendVPUMBox(MS_U32 u32Id, MS_U8 u8MBox, MS_U32 u32Msg)
210 {
211 MS_BOOL bResult = TRUE;
212 MS_U8 u8TaskId = HAL_VPU_EX_GetTaskId(u32Id);
213 u32Msg |= (u8TaskId << 24);
214
215 bResult = HAL_VPU_EX_MBoxSend((MS_U32)u8MBox, u32Msg);
216 return bResult;
217 }
218
219 ///-----------------------------------------------------------------------------
220 /// Clear VPU RISC MBox
221 /// @return TRUE or FALSE
222 /// - TRUE, Success
223 /// - FALSE, Failed
224 /// @param u8MBox \b IN: MailBox
225 /// - VPU_RISC_MBOX0,
226 /// - VPU_RISC_MBOX1,
227 ///-----------------------------------------------------------------------------
VirtualHal_MJPEG_ClearVPUMBox(MS_U8 u8MBox)228 MS_BOOL VirtualHal_MJPEG_ClearVPUMBox(MS_U8 u8MBox)
229 {
230 HAL_VPU_EX_MBoxClear((MS_U32)u8MBox);
231 return TRUE;
232 }
233
VirtualHal_MJPEG_Get_Chip_ID(void)234 MJPEG_MSTAR_CHIP_ID VirtualHal_MJPEG_Get_Chip_ID(void)
235 {
236 return E_MJPEG_MSTAR_CHIP_T8;
237 }
238
VirtualHal_MJPEG_GetFreeStream(HAL_MJPEG_StreamType eStreamType)239 HAL_MJPEG_StreamId VirtualHal_MJPEG_GetFreeStream(HAL_MJPEG_StreamType eStreamType)
240 {
241 MS_U32 i = 0;
242
243 if (eStreamType == E_HAL_MJPEG_MAIN_STREAM)
244 {
245 for (i = 0;
246 i <
247 ((E_HAL_MJPEG_MAIN_STREAM_MAX - E_HAL_MJPEG_MAIN_STREAM_BASE) +
248 (E_HAL_MJPEG_SUB_STREAM_MAX - E_HAL_MJPEG_SUB_STREAM_BASE)); i++)
249 {
250 if ((E_HAL_MJPEG_MAIN_STREAM_BASE & _stMJPEGStream[i].eStreamId) && (FALSE == _stMJPEGStream[i].bUsed))
251 {
252 return _stMJPEGStream[i].eStreamId;
253 }
254 }
255 }
256 else if (eStreamType == E_HAL_MJPEG_SUB_STREAM)
257 {
258 for (i = 0;
259 i <
260 ((E_HAL_MJPEG_MAIN_STREAM_MAX - E_HAL_MJPEG_MAIN_STREAM_BASE) +
261 (E_HAL_MJPEG_SUB_STREAM_MAX - E_HAL_MJPEG_SUB_STREAM_BASE)); i++)
262 {
263 if ((E_HAL_MJPEG_SUB_STREAM_BASE & _stMJPEGStream[i].eStreamId) && (FALSE == _stMJPEGStream[i].bUsed))
264 {
265 return _stMJPEGStream[i].eStreamId;
266 }
267 }
268 }
269 #ifdef VDEC3
270 else if ((eStreamType >= E_HAL_MJPEG_N_STREAM) && (eStreamType < E_HAL_MJPEG_N_STREAM + E_MJPEG_MJPEG_TOTAL))
271 {
272 i = eStreamType - E_HAL_MJPEG_N_STREAM;
273 if (!_stMJPEGStream[i].bUsed)
274 return _stMJPEGStream[i].eStreamId;
275 }
276 #endif
277
278 return E_HAL_MJPEG_STREAM_NONE;
279 }
280
281
VirtualHal_MJPEG_Init(MS_U8 u8DrvId)282 void VirtualHal_MJPEG_Init(MS_U8 u8DrvId)
283 {
284 _stMJPEGStream[u8DrvId].bUsed = TRUE;
285
286 }
287
VirtualHal_MJPEG_DeInit(MS_U8 u8DrvId)288 void VirtualHal_MJPEG_DeInit(MS_U8 u8DrvId)
289 {
290 _stMJPEGStream[u8DrvId].bUsed = FALSE;
291 }
292
293
294 #endif
295