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 // Include Files
98 //-------------------------------------------------------------------------------------------------
99 // Common Definition
100 #ifdef MSOS_TYPE_LINUX_KERNEL
101 #include <linux/string.h>
102 #else
103 #include <string.h>
104 #endif
105
106
107 #include "MsCommon.h"
108 #include "drvMVD_EX.h"
109 #include "drvBDMA.h"
110
111 // Internal Definition
112 #include "regMVD_EX.h"
113 #include "halMVD_EX.h"
114 #include "halVPU_EX.h"
115 #include "osalMVD_EX.h"
116 #include "mvd4_interface.h" //firmware header
117 #include "asmCPU.h"
118 #include "controller.h"
119 #include "MVD_EX_Common.h"
120 #include "halCHIP.h"
121 //#include "drvCMAPool.h" // TODO: system owner have to merge kernel mode CMA first !!!
122 #include "drvCMAPool_v2.h"
123 #if defined(MSOS_TYPE_LINUX)
124 #include "msos/linux/mdrv_cma_pool_st.h"
125 #endif
126
127 #if (!defined(MSOS_TYPE_NUTTX) && !defined(MSOS_TYPE_OPTEE)) || defined(SUPPORT_X_MODEL_FEATURE)
128
129
130 #ifdef MSOS_TYPE_LINUX_KERNEL
131 #define VPRINTF printk
132 #else
133 #ifndef ANDROID
134 #define VPRINTF printf
135 #else
136 #include <sys/mman.h>
137 #include <cutils/ashmem.h>
138 #include <cutils/log.h>
139 #define VPRINTF ALOGD
140 #endif
141 #endif
142
143
144 //-------------------------------------------------------------------------------------------------
145 // Driver Compiler Options
146 //-------------------------------------------------------------------------------------------------
147 #define SLQ_NEW_PUSH 1
148 #define VIRTUAL_CMD_TIMEOUT 50
149 #ifdef VDEC3
150 #define v3_temp 1
151 #define v3_thinplayer 0
152 #else
153 #define v3_temp 0
154 #define v3_thinplayer 0
155 #endif
156
157 //-------------------------------------------------------------------------------------------------
158 // Local Defines
159 //-------------------------------------------------------------------------------------------------
160 #define MIU1_BASEADDR pMVDHalContext->stMiuCfg.u32Miu1BaseAddr
161 #define _PA2Offset(x) (((x)>=MIU1_BASEADDR)?(x-MIU1_BASEADDR):(x))
162
163 #ifdef MSOS_TYPE_LINUX_KERNEL
164 #include <asm/div64.h>
165 #else
166 #define do_div(x,y) ((x)/=(y))
167 #endif
168
169
170 #ifndef MS_ASSERT
171 #ifdef MS_DEBUG
172 #define MS_ASSERT(expr) do { \
173 if(!(expr)) \
174 printf("MVD assert fail %s %d!\n", __FILE__, __LINE__); \
175 } while(0)
176 #else
177 #define MS_ASSERT(expr)
178 #endif
179 #endif
180
181 #ifndef UNUSED
182 #define UNUSED(x) (void)(x)
183 #endif
184 //constant
185 #define MVD_PollingTimes 0x40000UL
186
187 #define MVD_DEBUGVERBAL(x) if (_u8HalDbgLevel>3) { (x); }
188 #define MVD_DEBUG_FWCMD(x) if (_u8HalDbgLevel>2) { (x); }
189 #define MVD_DEBUGINFO(x) if (_u8HalDbgLevel>1) { (x); }
190 #define MVD_DEBUGERROR(x) if (_u8HalDbgLevel>0) { (x); }
191 #define MVD_ERROR(x) x
192
193 #define RIU ((unsigned short volatile *) (u32RiuBaseAdd))
194 #define RIU8 ((unsigned char volatile *) (u32RiuBaseAdd))
195
196 #define MVDCPU_ON_MIU1 ((HAL_MVD_RegReadByte(MIU0_SEL0_H) & BIT0) == BIT0)
197 #define MVDHW_ON_MIU1 ((HAL_MVD_RegReadByte(MIU0_SEL2_L) & BIT4) == BIT4)
198
199 // MVD5
200 #define SLQ_TBL_ENTRY_LEN 0x7FFFFFFF //31-bit
201
202 #define MVD_WIDTH_ALIGN_BYTE 16
203 #define MVD_WIDTH_ALIGN_MASK (MVD_WIDTH_ALIGN_BYTE - 1)
204 #define MVD_WIDTH_ALIGN_BITS 4
205
206 #define MVD_FBNUM_DEFAULT 4
207 #define MVD_FBNUM_MAX 5
208 #define MVD_FBNUM_MIN MVD_FBNUM_DEFAULT
209
210 #define MVD_DHD_FBSIZE 0x5FA000 //Framebuffer size minimum for Dual HD: (1920*2)*1088*1.5
211 #define MVD_HD_FBSIZE 0x2FD000 //Framebuffer size minimum for High Definition
212 #define MVD4_VC1_FBSIZE_HDMIN 0xEF1000 //5 * 1920 * 1088 * 1.5 = 14.95MB
213 #define MVD4_VC1_FBSIZE_HDMIN1 0xBF4000 //4 * 1920 * 1088 * 1.5 = 11.96MB
214 #define MVD4_VC1_FBSIZE_SDMIN 0x2F7600 //5 * 720 * 576 * 1.5 = 2.97MB
215 #define MVD4_MPEG_FBSIZE_HDMIN 0xBF4000 //4 * 1920 * 1088 * 1.5 = 11.96MB
216 #define MVD4_MPEG_FBSIZE_SDMIN 0x25F800 //4 * 720 * 576 * 1.5 = 2.38MB
217
218 #define _IS_VC1(x) ((x==E_MVD_CODEC_VC1_ADV) || (x==E_MVD_CODEC_VC1_MAIN))
219
220 #define SLQ_ENTRY_LEN 8 //8-byte per entry
221
222 #define MVD_U32_MAX 0xffffffffUL
223 #define MVD_U64_MAX 0xffffffffffffffffULL
224 #define MVD_GENERAL_MAX ((size_t)(-1))
225
226 #define MAX_ADD_28BIT 0x0fffffffUL
227
228 #define SLQ_ADDR_LEN SLQ_TBL_ENTRY_LEN //Slq address length is the same as SlqTbl
229
230 //Initial value for PTS table
231 #define _INIT_ADDR MVD_U32_MAX
232 #define _INIT_LEN 0
233 #define _INIT_TIMESTAMP MVD_U32_MAX
234 #define _INIT_ID MVD_U32_MAX
235
236 #define _MS_TO_90K(x) (x*90) //ms ==> 90k counter
237 #define _90K_TO_MS(x) ((x!=MVD_U32_MAX)?(x/90):(x)) //90k counter ==> ms
238 #define _90K_TO_MS_U64(x) ((x!=MVD_U64_MAX)?(do_div(x,90)):(x)) //90k counter ==> ms
239
240 #define MVD_DBG_STS(x) {}
241 #define _SLQTBL_DUMP_PTS FALSE//TRUE
242 #define _SLQTBL_DUMP_PUSHQ FALSE//TRUE
243 #define _SLQTBL_DUMP_PKT FALSE//TRUE
244 #define MVD_TURBO_INIT FALSE//TRUE
245
246 #define SLQ_ENTRY_MAX 1024
247 #define SLQ_ENTRY_LEN 8 //8-byte per entry
248 #define SLQ_TBL_SIZE (SLQ_ENTRY_MAX * SLQ_ENTRY_LEN)
249 #define ES_TBL_SIZE (SLQ_ENTRY_MAX * 8) //8-byte per entry
250
251 #define MVD_FW_SLQTBL_PTS_LEN 32
252
253 #define SLQ_TBL_SAFERANGE (40*SLQ_ENTRY_LEN)
254 //this should be smaller than FW's lookup range (current it's 16 entries)
255
256 #define SLQTBL_CHECKVACANCY_WATERLEVEL (44*SLQ_ENTRY_LEN)
257
258
259 #define DIVX_PATTERN 0x63643030
260 #define FLV_PATTERN 0xffff0000
261 #define MPEG_PATTERN_0 0xC6010000 //this SC just for mpeg2/4
262 #if SLQ_NEW_PUSH
263 #define SLQ_PIC_START_FLAG 0x40000000
264 #define VC1_PATTERN 0x0D010000
265 #define RCV_PATTERN 0xFF00A55A
266 #endif
267 #define VC1_PATTERN_0 0xff010000
268 #define VC1_PATTERN_1 0x0000ffff
269 #define VC1_PATTERN_2 0xffffff01
270 #define VC1_PATTERN_3 0x0000ffee
271
272 #define RCV_PATTERN_0 0x00000000
273 #define RCV_PATTERN_1 0xffffffff
274 #define RCV_PATTERN_2 0x00000000
275 #define RCV_PATTERN_3 0xeeeeeeee
276
277 #define DUMMY_PATTERN 0xBE010000
278 #define DUMMY_SIZE 0x2000 //8K
279
280 #define END_PATTERN_0 0xFF010000
281 #define END_PATTERN_1 0xDDCCBBAA
282 #define END_PATTERN_2 0xBBAAFFEE
283 #define END_PATTERN_3 0xFFEEDDCC
284 #define END_PATTERN_SIZE 256
285
286 #define SKIP_PATTERN_0 0xc5010000
287 #define SKIP_PATTERN_1 0x270608ab
288 #define SKIP_PATTERN_SIZE 8
289
290 #define CMD_TIMEOUT_MS 500
291 #define SKIP_DATA_TIMEOUT_MS 15
292
293 //Length of internal buffers
294 #define MVD_FW_IAP_BUF_LEN (0x4000UL) // 16k
295 #define MVD_FW_DP_BUF_LEN (0x80000UL) //512k
296 #define MVD_FW_MV_BUF_LEN (0x48000UL) //288K
297 //Alignment of HW buffers start address
298 #define MVD_FW_IAP_BUF_ALIGN (0x4000UL) // 16k
299 #define MVD_FW_DP_BUF_ALIGN (0x8000UL) // 32k
300 #define MVD_FW_MV_BUF_ALIGN (0x8000UL) // 32k
301
302 //Three HW buffers are allocated after framebuffer, so we need to
303 //consider these buffers when checking the available framebuffer size/number.
304 #define MVD_HW_BUF_TOTAL_LEN (MVD_FW_IAP_BUF_LEN + MVD_FW_DP_BUF_LEN + MVD_FW_MV_BUF_LEN) //u32HWBuffTotalSize
305
306 #define MVD_FW_CODE_LEN (OFFSET_BASE)//refer to the define in mvd4_interface.h
307 #define MVD_FW_CODE_LEN_V00 (0x70000UL) //length for old layout
308 #define MVD_FW_MPOOL_START_OFFSET (0x90000UL) //576K
309 #define MVD_FW_TASK_OFFSET (0x100000UL) //1M
310
311 #define MVD3_FW_VOL_INFO_BUF_LEN (0x1000UL) // 4K
312 #define MVD3_FW_FRAME_INFO_BUF_LEN (0x1000UL) // 4K
313 #define MVD3_FW_DIVX_INFO_BUF_LEN (0x1000UL) // 4K
314 #define MVD3_FW_USER_DATA_BUF_LEN (0x4000UL) // 16K
315 #define MVD3_FW_USER_DATA_BUF_BACKUP_LEN MVD3_FW_USER_DATA_BUF_LEN // 16K
316 #define MVD3_FW_SLQ_TAB_TMPBUF_LEN (0x200UL)
317 #define MVD_FW_SLQTBL_PTS_BUF_LEN (SLQ_ENTRY_MAX*MVD_FW_SLQTBL_PTS_LEN)
318 #define MVD_FW_DYN_SCALE_BUF_LEN (0x2000UL) // 8K
319 #define MVD_FW_SCALER_INFO_BUF_LEN (0x100UL) // 256bytes reserved
320 #define MVD_FW_DECFRM_INFO_BUF_LEN (0x100UL) // 256bytes reserved
321 #define MVD_FW_VBBU_TABLE_LEN (0x2000UL) // 8K
322
323 #define MVD_FW_USER_DATA_HDR_LEN (6)
324 #define MVD_FW_USER_DATA_PKT_LEN (256)
325 #define MVD_FW_USER_DATA_EXT_HDR_LEN (16)
326 #define FW_BUFF_ALIGN (0x1000) //4k align
327
328 #define SLQ_ENTRY_MAX 1024
329 #define MVD_FW_SLQTBL_PTS_LEN 32
330 #define MVD_NULLPKT_PTS MVD_U32_MAX
331
332 #define MVD_HW_MAX_PIXEL (1920*1088*61000ULL) // FHD@60p
333
334 //Get the start address, and the next start address.
335 #define GET_FW_BUFFADD(cur, size, start) \
336 do { \
337 start = cur; \
338 cur += size; \
339 } while(0)
340
341 //Get the aligned start address, and the next start address.
342 #define GET_FW_BUFFADD_ALIGN(cur, align, size, alignStart) \
343 do { \
344 cur = (MemAlign(cur, align)); \
345 GET_FW_BUFFADD(cur, size, alignStart); \
346 } while(0)
347
348 //Init command arguments
349 #define SETUP_CMDARG(x) \
350 do { \
351 x.Arg0 = 0; \
352 x.Arg1 = 0; \
353 x.Arg2 = 0; \
354 x.Arg3 = 0; \
355 x.Arg4 = 0; \
356 x.Arg5 = 0; \
357 } while(0)
358
359 //Set command arguments
360 #define SET_CMDARG(cmd, u32val, u8Num) \
361 do { \
362 cmd.Arg0 = L_WORD(u32val); \
363 cmd.Arg1 = H_WORD(u32val); \
364 cmd.Arg2 = L_DWORD(u32val); \
365 cmd.Arg3 = H_DWORD(u32val); \
366 cmd.Arg4 = 0; \
367 cmd.Arg5 = u8Num; \
368 } while(0)
369
370 #define SET_CMD_RET_FALSE(_cmdVal, _pStcmdArg) \
371 do { \
372 if (HAL_MVD_MVDCommand(_cmdVal, (_pStcmdArg)) == FALSE) \
373 { \
374 MVD_DEBUGERROR(printf("Command: 0x%x fail!!\r\n", _cmdVal)); \
375 return FALSE; \
376 } \
377 } while(0)
378
379 #define SET_CMD_RET_VOID(_cmdVal, _pStcmdArg) \
380 do { \
381 if (HAL_MVD_MVDCommand(_cmdVal, (_pStcmdArg)) == FALSE) \
382 { \
383 MVD_DEBUGERROR(printf("Command: 0x%x fail!!\r\n", _cmdVal)); \
384 return; \
385 } \
386 } while(0)
387
388 #define HAL_MVD_InvalidBuffRetFalse(x) \
389 do { \
390 if ((x)==0) \
391 { \
392 MVD_DEBUGERROR(printf("%s(%d) error: NULL buffer address.\n", __FUNCTION__, __LINE__)); \
393 return FALSE; \
394 } \
395 } while(0)
396
397 #define _MVD_Memset(pDstAddr, u32value, u32Size) \
398 do { \
399 MS_U32 x = 0; \
400 for (x = 0; x < (u32Size/4); x=x+4) \
401 { \
402 HAL_MVD_Memset4Byte(pDstAddr+x,u32value); \
403 } \
404 HAL_MVD_CPU_Sync(); \
405 HAL_MVD_ReadMemory(); \
406 } while (0)
407
408 #define _MVD_MemResetBit(pDstAddr, mask_num) \
409 do{ \
410 *pDstAddr = (*pDstAddr) & (~(0x1<<mask_num)); \
411 }while(0) \
412
413
414 typedef enum
415 {
416 MVD_HKSLQ_GET_READPTR = 0,
417 MVD_HKSLQ_GET_WRITEPTR = 1,
418 MVD_HKSLQ_NONE = 2,
419 } MVD_HKSLQ_CMD;
420
421 #if SLQ_NEW_PUSH
422 typedef struct _MVD_SLQ_STATUS
423 {
424 MS_BOOL bSlqPicStart;
425 MS_BOOL bSlqPicCollect;
426 MS_BOOL bSlqPicWaitNextStart;
427 MS_BOOL bSlqFireRdy;
428 MS_BOOL bSlqCtrlBit;
429 MS_BOOL bSlqEnLastFrameShow;
430 MS_VIRT u32SlqPatternAddr;
431 MS_U32 u32SlqPushLength;
432 MS_VIRT u32VaildWptrAddr;
433 } MVD_SLQ_STATUS;
434 #endif
435
436 typedef struct _MVD_SLQ_TBL_ST
437 {
438 MS_VIRT u32StAdd;
439 MS_VIRT u32EndAdd;
440 MS_U32 u32EntryCntMax;
441
442 MS_VIRT u32RdPtr;
443 MS_VIRT u32WrPtr;
444 MS_VIRT u32Empty;
445 MS_VIRT* pu32LastEntry;
446 } MVD_SLQ_TBL_ST;
447
448 typedef struct _MVD_ALIVEInfo
449 {
450 MS_U32 u32decode_count;
451 MS_U32 u32searchbuf_count;
452 MS_U32 u32searchcode_count;
453 MS_U32 u32prebuf_count;
454 MS_U32 u32vfifobuf_count;
455 MS_U32 u32searchheader_count;
456 MS_U32 u32flashpattern_count;
457 } MVD_ALIVEInfo;
458
459
460 typedef struct _MVD_SLQ_ES_ST
461 {
462 MS_VIRT u32StAdd;
463 MS_VIRT u32EndAdd;
464
465 MS_VIRT u32RdPtr;
466 MS_VIRT u32WrPtr;
467 } MVD_SLQ_ES_ST;
468
469 typedef struct _MVD_FWBuff
470 {
471 MS_VIRT pu8MVDGetVolBufStart;
472 MS_VIRT u32VolAdd;
473 MS_VIRT pu8MVDGetFrameInfoBufStart;
474 MS_VIRT pu8MVDSetHeaderBufStart;
475 MS_VIRT u32UserDataBuf;
476 MS_VIRT u32MVDFWSLQTABTmpbufAdr;
477 MS_VIRT u32MVDFWPtsTblAddr;
478 MS_VIRT u32DynScalingAdd;
479 MS_VIRT u32ScalerInfoAdd;
480 MS_VIRT u32DecFrmInfoAdd;
481 MS_VIRT u32VBBUTableAdd;
482 } MVD_FWBuff;
483
484 typedef enum _FW_BUFF_TYPE
485 {
486 FW_BUFF_VOLINFO,
487 FW_BUFF_FRMINFO,
488 FW_BUFF_HDR,
489 FW_BUFF_USRDATA,
490 FW_BUFF_SLQTBL,
491 FW_BUFF_FWSLQTAB,
492 FW_BUFF_PTSTBL,
493 FW_BUFF_DS,
494 FW_BUFF_XCINFO,
495 FW_BUFF_DECFRMINFO,
496 } FW_BUFF_TYPE;
497
498 typedef struct _MVD_SLQTBLInfo
499 {
500 MS_U32 u32LastPts; ///< record the last PTS to handle the repeat case
501 MS_U32 u32DummyPktCnt; ///< accumulated dummy packet counter
502 MS_U32 u32SlqByteCnt; ///< accumulated byte counter
503 MS_VIRT u32ESBuffEnd; ///< miu offset of ES buffer end, used for report TS read/write ptr.
504 MS_VIRT u32FileEndPtr; ///< write ptr of file-end
505 MS_VIRT u32PreEsRd; ///< previous ES read ptr
506 MS_VIRT u32PreEsWr; ///< previous ES write ptr
507 MS_BOOL bRdyToFireCmd; ///< TRUE after FW is ready to update write pointer
508 MS_BOOL bSlqTblHasValidData; ///< TRUE if the write ptr is not updated
509 MS_BOOL bEnSlqTblHkCtrl;
510 BDMA_CpyType bdmaCpyType;
511 MVD_SLQ_STATUS* pSlqStatus;
512 MVD_SLQ_TBL_ST* pDrvSlqTbl;
513 MVD_SLQ_ES_ST* pDrvEsTbl;
514 MVD_SLQ_ES_ST* pDrvDivxTbl;
515 } MVD_SLQTBLInfo;
516
517 //Only keep one record of MIU setting since there should be only one,
518 //even for multiple decoders.
519 typedef struct _MVDMiuCfg
520 {
521 MS_PHY u32Miu1BaseAddr;
522 MS_PHY u32Miu2BaseAddr;
523 MS_PHY u32Miu3BaseAddr;
524 MS_U8 u8FWMiuSel;
525 MS_U8 u8HWMiuSel;
526 } MVDMiuCfg;
527
528 typedef struct
529 {
530 MS_U64 u64PTS;
531 MS_U32 u32POC;
532 MS_U8 u8FrameType;
533 } MVD_PVR_Seamless_Info;
534
535 typedef enum
536 {
537 E_MVD_DEC_0 = 0,
538 E_MVD_DEC_1,
539 E_MVD_DEC_MAX
540 } MVD_DecNum;
541 #ifdef VDEC3
542 #define MAX_DEC_NUM 16
543 #else
544 #define MAX_DEC_NUM E_MVD_DEC_MAX
545 #endif
546
547 //-------------------------------------------------------------------------------------------------
548 // Local Structures
549 //-------------------------------------------------------------------------------------------------
550
551
552 //-------------------------------------------------------------------------------------------------
553 // Global Variables
554 //-------------------------------------------------------------------------------------------------
555 static MS_VIRT u32RiuBaseAdd = 0;
556 MS_U8 _u8HalDbgLevel = 0;
557 #ifdef VDEC3//#ifdef VDEC3
558 static MS_U32 u32SharememoryBase[MAX_DEC_NUM] ={MVD_U32_MAX,MVD_U32_MAX,MVD_U32_MAX,MVD_U32_MAX};
559 #else
560 static MS_U32 u32SharememoryBase[MAX_DEC_NUM] ={MVD_U32_MAX,MVD_U32_MAX};
561 #endif
562 static MS_U8 u8SHMMiuSel=0;
563 #if 0
564 static MVD_MEMCfg stMemCfg[MAX_DEC_NUM];
565 static MVD_CtrlCfg stCtrlCfg[MAX_DEC_NUM];
566 static MVD_FWCfg stFwCfg[MAX_DEC_NUM];
567
568 // For SLQ table link
569 static MVD_SLQTBLInfo stSlqTblInfo[MAX_DEC_NUM];
570 static MVD_SLQ_STATUS _SlqStatus[MAX_DEC_NUM]; //for SLQ_NEW_PUSH
571 static MVD_SLQ_TBL_ST _drvSlqTbl[MAX_DEC_NUM];
572 static MVD_SLQ_ES_ST _drvEsTbl[MAX_DEC_NUM]; //maintain to report ES read/write ptr
573 static MVD_SLQ_ES_ST _drvDivxTbl[MAX_DEC_NUM]; //header for divx311
574 static FW_DIVX_INFO gdivxInfo[MAX_DEC_NUM];
575
576 MS_BOOL bSlqTblHKCtrl = FALSE; //read/write pointer can be accessed by HK directly
577 static MS_BOOL bStopped = TRUE;
578
579 static HAL_MVD_Stream _stMVDStream[MAX_DEC_NUM] = {
580 {E_HAL_MVD_MAIN_STREAM0, FALSE},
581 {E_HAL_MVD_SUB_STREAM0, FALSE},
582 //{E_HAL_MVD_SUB_STREAM1, FALSE},
583 };
584 static MVD_FWBuff stFWBuff[MAX_DEC_NUM];
585 #endif
586
587 #define FRM_RATE_CODE_NUM 9
588
589 typedef struct
590 {
591 MVD_MEMCfg stMemCfg[MAX_DEC_NUM];
592 MVD_CtrlCfg stCtrlCfg[MAX_DEC_NUM];
593 MVD_FWCfg stFwCfg[MAX_DEC_NUM];
594
595 // For SLQ table link
596 MVD_SLQTBLInfo stSlqTblInfo[MAX_DEC_NUM];
597 MVD_SLQ_STATUS _SlqStatus[MAX_DEC_NUM]; //for SLQ_NEW_PUSH
598 MVD_SLQ_TBL_ST _drvSlqTbl[MAX_DEC_NUM];
599 MVD_SLQ_ES_ST _drvEsTbl[MAX_DEC_NUM]; //maintain to report ES read/write ptr
600 MVD_SLQ_ES_ST _drvDivxTbl[MAX_DEC_NUM]; //header for divx311
601 FW_DIVX_INFO gdivxInfo[MAX_DEC_NUM];
602
603 MS_BOOL bSlqTblHKCtrl[MAX_DEC_NUM]; //read/write pointer can be accessed by HK directly
604 MS_BOOL bStopped[MAX_DEC_NUM];
605
606 HAL_MVD_Stream _stMVDStream[MAX_DEC_NUM];
607
608 MVD_FWBuff stFWBuff[MAX_DEC_NUM];
609
610 #if _SLQTBL_DUMP_PKT
611 MS_U32 u32SendTimes[MAX_DEC_NUM];//HAL_MVD_SLQTblSendPacket
612 #endif
613
614 MS_U32 u32pqTimes[MAX_DEC_NUM];//HAL_MVD_PushQueue
615 MS_BOOL bSetSkip[MAX_DEC_NUM];//MVD_FlushTSQueue
616
617 MS_U32 u32PreVdCnt[MAX_DEC_NUM];//HAL_MVD_DbgDump
618 MS_U32 u32PreErrCnt[MAX_DEC_NUM];
619 MS_BOOL b1stDump[MAX_DEC_NUM];
620 //pre_set
621 HAL_MVD_Pre_Ctrl gMVDPreCtrl[MAX_DEC_NUM];
622 MS_BOOL bAutoInsertDummyPattern[MAX_DEC_NUM];
623 MVDMiuCfg stMiuCfg;
624 MS_BOOL bDropOnePTS[MAX_DEC_NUM];
625 MVD_ALIVEInfo aliveInfo[MAX_DEC_NUM];
626
627 MS_U32 u32DmxFrameRate[MAX_DEC_NUM];
628 MS_U32 u32DmxFrameRateBase[MAX_DEC_NUM];
629 MS_BOOL bCMAUsed;
630
631 struct CMA_Pool_Init_Param cmaInitParam; // support two MIU
632 struct CMA_Pool_Free_Param cmaFreeParam[MAX_DEC_NUM];
633 MS_BOOL bCMATwoMIU[MAX_DEC_NUM];
634 MS_U32 u32LastAliveTime[MAX_DEC_NUM];
635 MS_BOOL bTrickPlay2xAVSync[MAX_DEC_NUM];
636 } MVD_Hal_CTX;
637
638 //global variables
639 MVD_Hal_CTX* pMVDHalContext = NULL;
640 MVD_Hal_CTX gMVDHalContext;
641 const MS_U16 stFrameRateCode[FRM_RATE_CODE_NUM]=
642 {
643 NULL,23976,24000,25000,29976,30000,50000,59947,60000
644 };
645
646
647 #define GET_VOL_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].pu8MVDGetVolBufStart
648 #define GET_VOL_BUFFADD_NONCACHE(idx) pMVDHalContext->stFWBuff[(idx)].u32VolAdd
649 #define GET_FRMINFO_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].pu8MVDGetFrameInfoBufStart
650 #define GET_HDR_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].pu8MVDSetHeaderBufStart
651 #define GET_USRDATA_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].u32UserDataBuf
652 #define GET_SLQ_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].u32MVDFWSLQTABTmpbufAdr
653 #define GET_PTSTBL_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].u32MVDFWPtsTblAddr
654 #define GET_DS_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].u32DynScalingAdd
655 #define GET_XCINFO_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].u32ScalerInfoAdd
656 #define GET_DECFRMINFO_BUFFADD(idx) pMVDHalContext->stFWBuff[(idx)].u32DecFrmInfoAdd
657 #define GET_VBBUTABLEADD(idx) pMVDHalContext->stFWBuff[(idx)].u32VBBUTableAdd
658
659
660
661 //-------------------------------------------------------------------------------------------------
662 // Local Variables
663 //-------------------------------------------------------------------------------------------------
664
665
666 //-------------------------------------------------------------------------------------------------
667 // Debug Functions
668 //-------------------------------------------------------------------------------------------------
669
670
671 //-------------------------------------------------------------------------------------------------
672 // Local Functions
673 //-------------------------------------------------------------------------------------------------
674
HAL_MVD_Context_Init(void)675 static void HAL_MVD_Context_Init(void)
676 {
677 #ifdef VDEC3
678 MS_U8 i;
679
680 for (i = 0; i < MAX_DEC_NUM; i++)
681 {
682 pMVDHalContext->bStopped[i] = TRUE;
683 pMVDHalContext->b1stDump[i] = TRUE;
684 pMVDHalContext->_stMVDStream[i].eStreamId = E_HAL_MVD_N_STREAM0 + i;
685 }
686 #else
687 pMVDHalContext->bStopped[0] = TRUE;
688 pMVDHalContext->bStopped[1] = TRUE;
689 pMVDHalContext->_stMVDStream[0].eStreamId = E_HAL_MVD_MAIN_STREAM0;
690 pMVDHalContext->_stMVDStream[1].eStreamId = E_HAL_MVD_SUB_STREAM0;
691
692 pMVDHalContext->b1stDump[0] = TRUE;
693 pMVDHalContext->b1stDump[1] = TRUE;
694 #endif
695 }
696
697
698
HAL_MVD_SetIsUsed(MS_U8 u8Idx,MS_BOOL bUsed)699 static void HAL_MVD_SetIsUsed(MS_U8 u8Idx, MS_BOOL bUsed)
700 {
701 pMVDHalContext->_stMVDStream[u8Idx].bUsed = bUsed;
702 }
703
704 //Given the start address & the available size for the FW buffers,
705 //return the address of each buffers.
706 //Now only support u8Size==1, 2, 4
MVD_GetFWBuffData(MS_U8 u8Idx,FW_BUFF_TYPE eBuffType,MS_U8 u8Offset,MS_U8 u8Size)707 static MS_U32 MVD_GetFWBuffData(MS_U8 u8Idx, FW_BUFF_TYPE eBuffType, MS_U8 u8Offset, MS_U8 u8Size)
708 {
709 MS_U32 u32Val = 0;
710 MS_VIRT u32BufStart = NULL;
711 switch (eBuffType)
712 {
713 case FW_BUFF_VOLINFO: u32BufStart = GET_VOL_BUFFADD(u8Idx); break;
714 case FW_BUFF_FRMINFO: u32BufStart = GET_FRMINFO_BUFFADD(u8Idx); break;
715 case FW_BUFF_HDR: u32BufStart = GET_HDR_BUFFADD(u8Idx); break;
716 case FW_BUFF_USRDATA: u32BufStart = GET_USRDATA_BUFFADD(u8Idx); break;
717 case FW_BUFF_FWSLQTAB: u32BufStart = GET_SLQ_BUFFADD(u8Idx); break;
718 case FW_BUFF_PTSTBL: u32BufStart = GET_PTSTBL_BUFFADD(u8Idx); break;
719 case FW_BUFF_DS: u32BufStart = GET_DS_BUFFADD(u8Idx); break;
720 case FW_BUFF_XCINFO: u32BufStart = GET_XCINFO_BUFFADD(u8Idx); break;
721 case FW_BUFF_DECFRMINFO: u32BufStart = GET_DECFRMINFO_BUFFADD(u8Idx); break;
722 default:
723 break;
724 }
725 if (NULL == u32BufStart)
726 {
727 printf("%s err: u8Idx=0x%x, bufType=0x%x, offset=%d, size=%d\n",
728 __FUNCTION__, u8Idx, eBuffType, u8Offset, u8Size);
729 return 0;
730 }
731
732 if (u8Size == sizeof(MS_U8))
733 {
734 u32Val = (MS_U32)HAL_MVD_MemReadByte(u32BufStart+u8Offset);
735 }
736 else if (u8Size == sizeof(MS_U32))
737 {
738 u32Val = HAL_MVD_MemRead4Byte(u32BufStart+u8Offset);
739 }
740 else if (u8Size == sizeof(MS_U16))
741 {
742 u32Val = HAL_MVD_MemRead2Byte(u32BufStart+u8Offset);
743 }
744
745 MVD_DEBUGVERBAL(printf("%s: u32Val=%d for u8Idx=0x%x, bufType=0x%x, offset=%d, size=%d\n",
746 __FUNCTION__, u32Val, u8Idx, eBuffType, u8Offset, u8Size));
747 return u32Val;
748 }
749
750 #ifdef VDEC3
MVD_SetFWBuffData(MS_U8 u8Idx,FW_BUFF_TYPE eBuffType,MS_U8 u8Offset,MS_U8 u8Size,MS_U32 u32Value)751 static void MVD_SetFWBuffData(MS_U8 u8Idx, FW_BUFF_TYPE eBuffType, MS_U8 u8Offset, MS_U8 u8Size, MS_U32 u32Value)
752 {
753 MS_VIRT u32BufStart = NULL;
754
755 switch (eBuffType)
756 {
757 case FW_BUFF_VOLINFO: u32BufStart = GET_VOL_BUFFADD(u8Idx); break;
758 case FW_BUFF_FRMINFO: u32BufStart = GET_FRMINFO_BUFFADD(u8Idx); break;
759 case FW_BUFF_HDR: u32BufStart = GET_HDR_BUFFADD(u8Idx); break;
760 case FW_BUFF_USRDATA: u32BufStart = GET_USRDATA_BUFFADD(u8Idx); break;
761 case FW_BUFF_FWSLQTAB: u32BufStart = GET_SLQ_BUFFADD(u8Idx); break;
762 case FW_BUFF_PTSTBL: u32BufStart = GET_PTSTBL_BUFFADD(u8Idx); break;
763 case FW_BUFF_DS: u32BufStart = GET_DS_BUFFADD(u8Idx); break;
764 case FW_BUFF_XCINFO: u32BufStart = GET_XCINFO_BUFFADD(u8Idx); break;
765 case FW_BUFF_DECFRMINFO: u32BufStart = GET_DECFRMINFO_BUFFADD(u8Idx); break;
766 default:
767 break;
768 }
769
770 if (NULL == u32BufStart)
771 {
772 printf("%s err: u8Idx=0x%x, bufType=0x%x, offset=%d, size=%d, value=%d\n",
773 __FUNCTION__, (unsigned int)u8Idx,(unsigned int) eBuffType,(unsigned int) u8Offset,(unsigned int) u8Size,(unsigned int)u32Value);
774 }
775
776 if (pMVDHalContext->stMiuCfg.u8HWMiuSel == MIU_SEL_1)
777 {
778 u32BufStart += HAL_MIU1_BASE;
779 }
780 /* else if (pMVDHalContext->stMiuCfg.u8HWMiuSel == MIU_SEL_2)
781 {
782 u32BufStart += HAL_MIU2_BASE;
783 }*/
784
785 if (u8Size == sizeof(MS_U8))
786 {
787 MS_U8* temp = (MS_U8*)MsOS_PA2KSEG1(u32BufStart+u8Offset);
788 *temp = (MS_U8)u32Value;
789 }
790 else if (u8Size == sizeof(MS_U32))
791 {
792 MS_U32* temp = (MS_U32*)MsOS_PA2KSEG1(u32BufStart+u8Offset);
793 *temp = (MS_U32)u32Value;
794 }
795 else if (u8Size == sizeof(MS_U16))
796 {
797 MS_U16* temp = (MS_U16*)MsOS_PA2KSEG1(u32BufStart+u8Offset);
798 *temp = (MS_U16)u32Value;
799 }
800
801 MVD_DEBUGVERBAL(printf("%s: u8Idx=0x%x, bufType=0x%x, offset=%d, size=%d, value=%d\n",
802 __FUNCTION__, (unsigned int)u8Idx, (unsigned int)eBuffType, (unsigned int)u8Offset, (unsigned int)u8Size,(unsigned int)u32Value));
803 }
804 #endif
805
806
807 //-------------------------------------------------------------------------------------------------
808 // Global Functions
809 //-------------------------------------------------------------------------------------------------
HAL_MVD_SetDbgLevel(MS_U8 level)810 void HAL_MVD_SetDbgLevel(MS_U8 level)
811 {
812 _u8HalDbgLevel = level;
813 return;
814 }
815
816
HAL_MVD_GetCaps(void)817 MS_U8 HAL_MVD_GetCaps(void)
818 {
819 MS_U8 caps = 0;
820
821 caps |= (MVD_SUPPORT_MPEG2|MVD_SUPPORT_MPEG4|MVD_SUPPORT_VC1);
822 return caps;
823 }
824
HAL_MVD_GetMaxPixel(MS_U32 u32Id)825 MS_U64 HAL_MVD_GetMaxPixel(MS_U32 u32Id)
826 {
827 return (MS_U64)MVD_HW_MAX_PIXEL/1000;
828 }
829
HAL_MVD_GetDrvFwVer(void)830 MS_U32 HAL_MVD_GetDrvFwVer(void)
831 {
832 return MVD_FW_VERSION;
833 }
834
835 #if 0
836 MS_U32 HAL_MVD_GetMiu1BaseAdd(void)
837 {
838 return MIU1_BASEADDR;
839 }
840 #endif
841
842 //#if defined(CHIP_MUJI)
HAL_MVD_GetMiu1BaseAdd(void)843 MS_VIRT HAL_MVD_GetMiu1BaseAdd(void)
844 {
845 return MIU1_BASEADDR;
846 }
847
HAL_MVD_GetFWSelMiu1(void)848 MS_BOOL HAL_MVD_GetFWSelMiu1(void)
849 {
850 return MVDCPU_ON_MIU1;
851 }
852 //#endif
853
854
HAL_MVD_GetFWSelMiu(void)855 MS_U8 HAL_MVD_GetFWSelMiu(void)
856 {
857 return pMVDHalContext->stMiuCfg.u8FWMiuSel;
858 }
859
860
861
HAL_MVD_MemGetMap(MS_U8 u8Idx,MS_U8 u8type,MS_VIRT * pu32addr,MS_SIZE * pu32len)862 void HAL_MVD_MemGetMap(MS_U8 u8Idx, MS_U8 u8type, MS_VIRT* pu32addr, MS_SIZE* pu32len)
863 {
864 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
865 MS_VIRT u32StartOffset;
866 MS_U8 u8MiuSel;
867
868 switch (u8type)
869 {
870 case E_MVD_MMAP_ALL:
871 case E_MVD_MMAP_FW:
872 _phy_to_miu_offset(u8MiuSel, u32StartOffset, pstMemCfg->u32FWCodeAddr);
873 *pu32addr = u32StartOffset;
874 *pu32len = pstMemCfg->u32FWCodeSize;
875 break;
876 case E_MVD_MMAP_BS:
877 _phy_to_miu_offset(u8MiuSel, u32StartOffset, pstMemCfg->u32BSAddr);
878 *pu32addr = u32StartOffset;
879 *pu32len = pstMemCfg->u32BSSize;
880 break;
881 case E_MVD_MMAP_FB:
882 _phy_to_miu_offset(u8MiuSel, u32StartOffset, pstMemCfg->u32FBAddr);
883 *pu32addr = u32StartOffset;
884 *pu32len = pstMemCfg->u32FBSize;
885 break;
886 case E_MVD_MMAP_DRV:
887 _phy_to_miu_offset(u8MiuSel, u32StartOffset, pstMemCfg->u32DrvBufAddr);
888 *pu32addr = u32StartOffset;
889 *pu32len = pstMemCfg->u32DrvBufSize;
890 break;
891 default:
892 break;
893 }
894
895 MVD_DEBUGINFO(printf("HAL_MVD_MemGetMap[%d] add=0x%lx len=0x%lx\n",u8type,(unsigned long)*pu32addr,(unsigned long)*pu32len));
896 return;
897 }
898
HAL_MVD_RegSetBase(MS_VIRT u32Base)899 void HAL_MVD_RegSetBase(MS_VIRT u32Base)
900 {
901 u32RiuBaseAdd = u32Base;
902 HAL_VPU_EX_InitRegBase(u32Base);
903 }
904
HAL_MVD_RegWriteByte(MS_VIRT u32Reg,MS_U8 u8Val)905 void HAL_MVD_RegWriteByte(MS_VIRT u32Reg, MS_U8 u8Val)
906 {
907 if ( __builtin_constant_p( u32Reg ) )
908 {
909 RIU8[((u32Reg) * 2) - ((u32Reg) & 1)] = u8Val;
910 }
911 else
912 {
913 RIU8[(u32Reg << 1) - (u32Reg & 1)] = u8Val;
914 }
915 }
916
HAL_MVD_RegReadByte(MS_VIRT u32Reg)917 MS_U8 HAL_MVD_RegReadByte(MS_VIRT u32Reg)
918 {
919 return (__builtin_constant_p( u32Reg ) ?
920 (((u32Reg) & 0x01) ? RIU8[(u32Reg) * 2 - 1] : RIU8[(u32Reg) * 2]) :
921 (RIU8[(u32Reg << 1) - (u32Reg & 1)]));
922 }
923
HAL_MVD_RegWriteBit(MS_VIRT u32Reg,MS_BOOL bEnable,MS_U8 u8Mask)924 void HAL_MVD_RegWriteBit(MS_VIRT u32Reg, MS_BOOL bEnable, MS_U8 u8Mask)
925 {
926 MS_VIRT u32Reg8 = ((u32Reg) * 2) - ((u32Reg) & 1);
927 RIU8[u32Reg8] = (bEnable) ? (RIU8[u32Reg8] | (u8Mask)) :
928 (RIU8[u32Reg8] & ~(u8Mask));
929 }
930
HAL_MVD_RegWriteByteMask(MS_VIRT u32Reg,MS_U8 u8Val,MS_U8 u8Msk)931 void HAL_MVD_RegWriteByteMask(MS_VIRT u32Reg, MS_U8 u8Val, MS_U8 u8Msk)
932 {
933 MS_VIRT u32Reg8 = ((u32Reg) * 2) - ((u32Reg) & 1);
934 RIU8[u32Reg8] = (RIU8[u32Reg8] & ~(u8Msk)) | ((u8Val) & (u8Msk));
935 }
936
HAL_MVD_RegWrite4Byte(MS_VIRT u32Reg,MS_U32 u32Val)937 void HAL_MVD_RegWrite4Byte(MS_VIRT u32Reg, MS_U32 u32Val)
938 {
939 if ( __builtin_constant_p( u32Reg ) && !((u32Reg) & 0x01) )
940 {
941 RIU[u32Reg] = (MS_U16)(u32Val);
942 RIU[(u32Reg) + 2] = (MS_U16)((u32Val) >> 16);
943 }
944 else
945 {
946 if (u32Reg & 0x01)
947 {
948 RIU8[(u32Reg << 1) - 1] = u32Val;
949 RIU[u32Reg + 1] = (u32Val >> 8);
950 RIU8[((u32Reg + 3) << 1)] = (u32Val >> 24);
951 }
952 else
953 {
954 RIU[u32Reg] = u32Val;
955 RIU[u32Reg + 2] = (u32Val >> 16);
956 }
957 }
958 }
959
960
HAL_MVD_MemRead4Byte(MS_VIRT u32Address)961 MS_U32 HAL_MVD_MemRead4Byte(MS_VIRT u32Address)
962 {
963 volatile MS_U32 u32Val;
964 MS_ASSERT(!(u32Address & 0x03UL));
965
966 HAL_MVD_CPU_Sync();
967 HAL_MVD_ReadMemory();
968
969 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,u32Address,u32Address);
970
971 u32Val = *(volatile MS_U32*) HAL_MVD_PA2NonCacheSeg(u32Address);
972
973 //printf("mvd rd 0x%lx = 0x%lx\n", u32Address, u32Val);
974 return u32Val;
975 }
976
HAL_MVD_MemRead2Byte(MS_VIRT u32Address)977 MS_U16 HAL_MVD_MemRead2Byte(MS_VIRT u32Address)
978 {
979 MS_VIRT u32ReadAddr;
980 MS_U32 u32ReadValue;
981 MS_U16 u16Value;
982 MS_U8 u8Shift;
983 u32ReadAddr = (u32Address >> 2) << 2;
984 u8Shift = (MS_U8)((u32Address & 0x03) * 8);
985 u32ReadValue = HAL_MVD_MemRead4Byte(u32ReadAddr);
986
987 u16Value = (MS_U16)(u32ReadValue >> u8Shift);
988 if(u8Shift == 24)
989 {
990 u32ReadValue = HAL_MVD_MemRead4Byte(u32ReadAddr+4);
991 u16Value = u16Value << 8 || (MS_U16)(u32ReadValue & 0xFF);
992 }
993 return u16Value;
994 }
995
HAL_MVD_MemReadByte(MS_VIRT u32Address)996 MS_U8 HAL_MVD_MemReadByte(MS_VIRT u32Address)
997 {
998 MS_VIRT u32ReadAddr;
999 MS_U32 u32ReadValue;
1000 MS_U8 u8Value;
1001 MS_U8 u8Shift;
1002 u32ReadAddr = (u32Address >> 2) << 2;
1003 u8Shift = (MS_U8)((u32Address & 0x03) * 8);
1004 u32ReadValue = HAL_MVD_MemRead4Byte(u32ReadAddr);
1005 u8Value = (MS_U8)(u32ReadValue >> u8Shift);
1006
1007 return u8Value;
1008 }
1009
HAL_MVD_MemWrite4Byte(MS_VIRT u32Address,MS_U32 u32Value)1010 MS_BOOL HAL_MVD_MemWrite4Byte(MS_VIRT u32Address, MS_U32 u32Value)
1011 {
1012
1013 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,u32Address,u32Address);
1014
1015 *(volatile MS_U32 *) HAL_MVD_PA2NonCacheSeg(u32Address) = u32Value;
1016
1017 HAL_MVD_CPU_Sync();
1018 HAL_MVD_FlushMemory();
1019
1020 return TRUE;
1021 }
1022
HAL_MVD_MemWriteByte(MS_VIRT u32Address,MS_U8 u8Value)1023 MS_BOOL HAL_MVD_MemWriteByte(MS_VIRT u32Address, MS_U8 u8Value)
1024 {
1025 MS_VIRT u32ReadAddr;
1026 MS_U32 u32ReadValue;
1027 MS_U8 u8Shift;
1028
1029 u32ReadAddr = (u32Address >> 2) << 2;
1030 u8Shift = (MS_U8)((u32Address & 0x03UL) * 8);
1031 u32ReadValue = HAL_MVD_MemRead4Byte(u32ReadAddr);
1032 u32ReadValue &= ~(0xFFUL << u8Shift);
1033 u32ReadValue |= ((MS_U32)u8Value << u8Shift);
1034 HAL_MVD_MemWrite4Byte(u32ReadAddr, u32ReadValue);
1035 return TRUE;
1036 }
1037
HAL_MVD_MemWrite2Byte(MS_VIRT u32Address,MS_U16 u16Value)1038 MS_BOOL HAL_MVD_MemWrite2Byte(MS_VIRT u32Address, MS_U16 u16Value)
1039 {
1040 MS_VIRT u32ReadAddr;
1041 MS_U32 u32ReadValue;
1042 MS_U8 u8Shift;
1043
1044 u8Shift = (MS_U8)((u32Address & 0x03UL) * 8) ;
1045 if(u8Shift < 24)
1046 {
1047 u32ReadAddr = (u32Address >> 2) << 2;
1048 u32ReadValue = HAL_MVD_MemRead4Byte(u32ReadAddr);
1049 u32ReadValue &= ~(0xFFFF << u8Shift);
1050 u32ReadValue |= ((MS_U32)u16Value << u8Shift);
1051 HAL_MVD_MemWrite4Byte(u32ReadAddr, u32ReadValue);
1052 }
1053 else
1054 {
1055 HAL_MVD_MemWriteByte(u32Address, (MS_U8)(u16Value));
1056 HAL_MVD_MemWriteByte(u32Address+1, (MS_U8)(u16Value >> 8));
1057 }
1058 return TRUE;
1059 }
1060
1061
HAL_MVD_SetReqMask(MS_BOOL bEnMask)1062 void HAL_MVD_SetReqMask(MS_BOOL bEnMask)
1063 {
1064 HAL_VPU_EX_MIU_RW_Protect(bEnMask);
1065
1066 if (MVDHW_ON_MIU1)
1067 {
1068 HAL_MVD_RegWriteBit(MIU1_RQ2_MASK_L, bEnMask, BIT4); //MVD R/W
1069 HAL_MVD_RegWriteBit(MIU1_RQ0_MASK_H, bEnMask, BIT4); //MVD bbu R/W
1070 }
1071 else
1072 {
1073 HAL_MVD_RegWriteBit(MIU0_RQ2_MASK_L, bEnMask, BIT4); //MVD R/W
1074 HAL_MVD_RegWriteBit(MIU0_RQ0_MASK_H, bEnMask, BIT4); //MVD bbu R/W
1075 }
1076 HAL_MVD_Delayms(1);
1077
1078 return;
1079 }
1080
HAL_MVD_Memset4Byte(MS_VIRT u32Address,MS_U32 u32Value)1081 static MS_BOOL HAL_MVD_Memset4Byte(MS_VIRT u32Address, MS_U32 u32Value)
1082 {
1083 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,u32Address,u32Address);
1084
1085 *(volatile MS_U32 *) HAL_MVD_PA2NonCacheSeg(u32Address) = u32Value;
1086
1087 return TRUE;
1088 }
1089
1090 //------------------------------------------------------------------------------
1091 /// Initialize MVD
1092 /// @return -result of resetting MVD hardware
1093 //------------------------------------------------------------------------------
HAL_MVD_RstHW(void)1094 MS_BOOL HAL_MVD_RstHW(void)
1095 {
1096 MS_U32 u32Time = 0;
1097
1098 OSAL_MVD_LockHwMutex();
1099
1100 HAL_MVD_SetReqMask(ENABLE);
1101
1102 HAL_MVD_RegWriteBit(MVD_CTRL, 1, MVD_CTRL_DISCONNECT_MIU);//disconnect MIU
1103 HAL_MVD_RegWriteBit(MVD_CTRL, 0, MVD_CTRL_DISCONNECT_MIU);//release reset
1104
1105 HAL_MVD_RegWriteBit(MVD_CTRL, 1, MVD_CTRL_RST);//reset MVD
1106 HAL_MVD_RegWriteBit(MVD_CTRL, 0, MVD_CTRL_RST);//release reset
1107
1108 u32Time = HAL_MVD_GetTime();
1109 while ( ((HAL_MVD_RegReadByte(MVD_STATUS) & MVD_STATUS_READY) == 0)
1110 && ((HAL_MVD_GetTime() - u32Time) < 200) );
1111
1112 #if 0 //bring up
1113 printf("====================>>>>MVD Ctrl status1.5a : 0x%x\n",HAL_MVD_RegReadByte(MVD_STATUS));
1114 HAL_MVD_RegWriteBit(MVD_STATUS, 1, MVD_T8_MIU_128_0);//release reset
1115 HAL_MVD_RegWriteBit(MVD_STATUS, 1, MVD_T8_MIU_128_1);//release reset
1116 MVD_DEBUGINFO(printf("MVD Ctrl status : 0x%x\n",HAL_MVD_RegReadByte(MVD_STATUS)));
1117 printf("====================>>>>MVD Ctrl status1.5b : 0x%x\n",HAL_MVD_RegReadByte(MVD_STATUS));
1118 #endif
1119
1120 HAL_MVD_SetReqMask(DISABLE);
1121
1122 OSAL_MVD_UnlockHwMutex();
1123
1124 return TRUE;
1125 }
1126
1127
1128 //------------------------------------------------------------------------------
1129 /// Release CPU
1130 /// @return -release CPU successfully or not
1131 //------------------------------------------------------------------------------
HAL_MVD_ReleaseFW(void)1132 MS_BOOL HAL_MVD_ReleaseFW(void)
1133 {
1134 //For dual decoder, we only release VPU if it is not released yet.
1135 if (TRUE == HAL_VPU_EX_IsRsted())
1136 {
1137 MVD_DEBUGINFO(printf("%s VPU_IsRsted\n", __FUNCTION__));
1138 return TRUE;
1139 }
1140
1141 HAL_VPU_EX_SwRstRelse();
1142 return TRUE;
1143 }
1144
HAL_MVD_PA2NonCacheSeg(MS_PHY u32PhyAddr)1145 MS_VIRT HAL_MVD_PA2NonCacheSeg(MS_PHY u32PhyAddr)
1146 {
1147 return MS_PA2KSEG1(u32PhyAddr);
1148 }
1149
HAL_MVD_GetTime(void)1150 MS_U32 HAL_MVD_GetTime(void)
1151 {
1152 return MsOS_GetSystemTime();
1153 }
1154
HAL_MVD_Delayms(MS_U32 u32msecs)1155 void HAL_MVD_Delayms(MS_U32 u32msecs)
1156 {
1157 MsOS_DelayTaskUs(1000*u32msecs);
1158 }
1159
HAL_MVD_CPU_Sync(void)1160 void HAL_MVD_CPU_Sync(void)
1161 {
1162 MAsm_CPU_Sync();
1163 }
1164
HAL_MVD_FlushMemory(void)1165 void HAL_MVD_FlushMemory(void)
1166 {
1167 MsOS_FlushMemory();
1168 }
1169
HAL_MVD_ReadMemory(void)1170 void HAL_MVD_ReadMemory(void)
1171 {
1172 MsOS_ReadMemory();
1173 }
1174
1175 //Record the memory layout from system configuration
HAL_MVD_SetMEMCfg(MS_U8 u8Idx,MVD_MEMCfg * pMEMCfg)1176 MS_BOOL HAL_MVD_SetMEMCfg(MS_U8 u8Idx, MVD_MEMCfg* pMEMCfg)
1177 {
1178 memcpy(&(pMVDHalContext->stMemCfg[u8Idx]), pMEMCfg, sizeof(MVD_MEMCfg));
1179 //record the MIU settings
1180 pMVDHalContext->stMiuCfg.u32Miu1BaseAddr = pMEMCfg->u32Miu1BaseAddr;
1181 pMVDHalContext->stMiuCfg.u32Miu2BaseAddr = pMEMCfg->u32Miu2BaseAddr;
1182 pMVDHalContext->stMiuCfg.u32Miu3BaseAddr = pMEMCfg->u32Miu3BaseAddr;
1183 pMVDHalContext->stMiuCfg.u8FWMiuSel = pMEMCfg->u8FWMiuSel;
1184 pMVDHalContext->stMiuCfg.u8HWMiuSel = pMEMCfg->u8HWMiuSel;
1185 return TRUE;
1186 }
1187
HAL_MVD_GetMEMCfg(MS_U8 u8Idx)1188 MVD_MEMCfg* HAL_MVD_GetMEMCfg(MS_U8 u8Idx)
1189 {
1190 //printf("%s: u8Idx=0x%x\n", __FUNCTION__, u8Idx);
1191 MVD_MEMCfg* pInfo = NULL;
1192 pInfo = &(pMVDHalContext->stMemCfg[u8Idx]);
1193 return pInfo;
1194 }
1195
HAL_MVD_SetFWCfg(MS_U8 u8Idx,MVD_FWCfg * pFWCfg)1196 MS_BOOL HAL_MVD_SetFWCfg(MS_U8 u8Idx, MVD_FWCfg* pFWCfg)
1197 {
1198 //printf("%s: u8Idx=0x%x\n", __FUNCTION__, u8Idx);
1199 memcpy(&(pMVDHalContext->stFwCfg[u8Idx]), pFWCfg, sizeof(MVD_FWCfg));
1200 memcpy(&(pMVDHalContext->stFwCfg[u8Idx].stFBReduction), &pFWCfg->stFBReduction,sizeof(MVD_FB_Reduction));
1201 return TRUE;
1202 }
1203
HAL_MVD_GetFWCfg(MS_U8 u8Idx)1204 MVD_FWCfg* HAL_MVD_GetFWCfg(MS_U8 u8Idx)
1205 {
1206 MVD_FWCfg* pInfo = NULL;
1207 //printf("%s: u8Idx=0x%x\n", __FUNCTION__, u8Idx);
1208 pInfo = &(pMVDHalContext->stFwCfg[u8Idx]);
1209 return pInfo;
1210 }
1211
HAL_MVD_GetFBMode(MS_U8 u8Idx)1212 MS_U8 HAL_MVD_GetFBMode(MS_U8 u8Idx)
1213 {
1214 MS_U8 u8Mode = MVD3_SD_MODE;
1215 u8Mode = pMVDHalContext->stFwCfg[u8Idx].u8FBMode;
1216 MVD_DEBUGINFO(printf("FBMode=0x%x\n", u8Mode));
1217 return u8Mode;
1218 }
1219
HAL_MVD_GetCodecType(MS_U8 u8Idx)1220 MVD_CodecType HAL_MVD_GetCodecType(MS_U8 u8Idx)
1221 {
1222 MVD_CodecType eCodecType = E_MVD_CODEC_UNKNOWN;
1223 eCodecType = pMVDHalContext->stFwCfg[u8Idx].eCodecType;
1224 return eCodecType;
1225 }
1226
HAL_MVD_GetSrcMode(MS_U8 u8Idx)1227 MVD_SrcMode HAL_MVD_GetSrcMode(MS_U8 u8Idx)
1228 {
1229 MVD_SrcMode eSrcMode = E_MVD_SRC_UNKNOWN;
1230 eSrcMode = pMVDHalContext->stFwCfg[u8Idx].eSrcMode;
1231 return eSrcMode;
1232 }
1233
HAL_MVD_SetSrcMode(MS_U8 u8Idx,MVD_SrcMode mode)1234 MS_BOOL HAL_MVD_SetSrcMode(MS_U8 u8Idx,MVD_SrcMode mode)
1235 {
1236 if(pMVDHalContext != NULL)
1237 {
1238 pMVDHalContext->stFwCfg[u8Idx].eSrcMode = mode;
1239 return TRUE;
1240 }
1241 else
1242 {
1243 return FALSE;
1244 }
1245 }
1246
1247
HAL_MVD_GetCtrlCfg(MS_U8 u8Idx)1248 MVD_CtrlCfg* HAL_MVD_GetCtrlCfg(MS_U8 u8Idx)
1249 {
1250 MVD_CtrlCfg* pInfo = NULL;
1251 pInfo = &(pMVDHalContext->stCtrlCfg[u8Idx]);
1252 return pInfo;
1253 }
1254
HAL_MVD_GetSlqTblInfo(MS_U8 u8Idx)1255 MVD_SLQTBLInfo* HAL_MVD_GetSlqTblInfo(MS_U8 u8Idx)
1256 {
1257 MVD_SLQTBLInfo* pInfo = NULL;
1258 pInfo = &(pMVDHalContext->stSlqTblInfo[u8Idx]);
1259 return pInfo;
1260 }
1261
HAL_MVD_PowerCtrl(MS_BOOL bOn)1262 void HAL_MVD_PowerCtrl(MS_BOOL bOn)
1263 {
1264 HAL_MVD_RegWriteByteMask(REG_CKG_MVD, CKG_MVD_216MHZ, CKG_MVD_MASK);
1265 HAL_MVD_RegWriteBit(REG_CKG_MVD, !bOn, CKG_MVD_GATED);
1266 HAL_MVD_RegWriteBit(REG_CKG_MVD, !bOn, CKG_MVD_INVERT);
1267
1268 HAL_MVD_RegWriteByteMask(REG_CKG_MVD2, CKG_MVD2_216MHZ, CKG_MVD2_MASK);
1269 HAL_MVD_RegWriteBit(REG_CKG_MVD2, !bOn, CKG_MVD2_GATED);
1270 HAL_MVD_RegWriteBit(REG_CKG_MVD2, !bOn, CKG_MVD2_INVERT);
1271
1272 HAL_MVD_RegWriteBit(REG_CKG_MVD_CHROMA_A, !bOn, CKG_MVD_CHROMA_A_GATED);
1273 HAL_MVD_RegWriteBit(REG_CKG_MVD_CHROMA_A, !bOn, CKG_MVD_CHROMA_A_INVERT);
1274
1275 HAL_MVD_RegWriteBit(REG_CKG_MVD_CHROMA_B, !bOn, CKG_MVD_CHROMA_B_GATED);
1276 HAL_MVD_RegWriteBit(REG_CKG_MVD_CHROMA_B, !bOn, CKG_MVD_CHROMA_B_INVERT);
1277
1278 HAL_MVD_RegWriteBit(REG_CKG_MVD_CHROMA_C, !bOn, CKG_MVD_CHROMA_C_GATED);
1279 HAL_MVD_RegWriteBit(REG_CKG_MVD_CHROMA_C, !bOn, CKG_MVD_CHROMA_C_INVERT);
1280
1281 HAL_MVD_RegWriteBit(REG_CKG_MVD_LUMA_A, !bOn, CKG_MVD_LUMA_A_GATED);
1282 HAL_MVD_RegWriteBit(REG_CKG_MVD_LUMA_A, !bOn, CKG_MVD_LUMA_A_INVERT);
1283
1284 HAL_MVD_RegWriteBit(REG_CKG_MVD_LUMA_B, !bOn, CKG_MVD_LUMA_B_GATED);
1285 HAL_MVD_RegWriteBit(REG_CKG_MVD_LUMA_B, !bOn, CKG_MVD_LUMA_B_INVERT);
1286
1287 HAL_MVD_RegWriteBit(REG_CKG_MVD_LUMA_C, !bOn, CKG_MVD_LUMA_C_GATED);
1288 HAL_MVD_RegWriteBit(REG_CKG_MVD_LUMA_C, !bOn, CKG_MVD_LUMA_C_INVERT);
1289
1290 HAL_MVD_RegWriteBit(REG_CKG_MVD_RMEM, !bOn, CKG_MVD_RMEM_GATED);
1291 HAL_MVD_RegWriteBit(REG_CKG_MVD_RMEM, !bOn, CKG_MVD_RMEM_INVERT);
1292
1293 HAL_MVD_RegWriteBit(REG_CKG_MVD_RMEM1, !bOn, CKG_MVD_RMEM1_GATED);
1294 HAL_MVD_RegWriteBit(REG_CKG_MVD_RMEM1, !bOn, CKG_MVD_RMEM1_INVERT);
1295
1296 HAL_MVD_RegWriteBit(REG_CKG_MVD_RREFDAT, !bOn, CKG_MVD_RREFDAT_GATED);
1297 HAL_MVD_RegWriteBit(REG_CKG_MVD_RREFDAT, !bOn, CKG_MVD_RREFDAT_INVERT);
1298
1299 //Set MVD all clock sources equal to clk_miu_p 0: enable 1: disable
1300 //Per Lawrence, mark this line:
1301 // Sync mode is debug mode, so driver shouldn't write 1 to this register in normal case.
1302 //HAL_MVD_RegWriteBit(REG_CKG_MVD_SYNC, !bOn, CKG_MVD_SYNC_GATED);
1303
1304 return;
1305 }
1306
1307 #if 0
1308 void HAL_MVD_Sleep(MS_U32 u32us)
1309 {
1310 MsOS_DelayTaskUs(u32us);
1311 }
1312 #endif
HAL_MVD_ResetHandShake(MS_U8 u8Idx,MVD_HANDSHAKE_CMD cmd)1313 void HAL_MVD_ResetHandShake(MS_U8 u8Idx, MVD_HANDSHAKE_CMD cmd)
1314 {
1315 MS_U32 u32BufAddr = GET_FRMINFO_BUFFADD(u8Idx);
1316 HAL_MVD_CPU_Sync();
1317 HAL_MVD_ReadMemory();
1318 MVD_CMD_HANDSHADE_INDEX u32CmdState;
1319 u32CmdState.value= HAL_MVD_MemRead4Byte(u32BufAddr + OFFSET_CMD_HANDSHAKE_INDEX);
1320 switch (cmd)
1321 {
1322 case MVD_HANDSHAKE_PAUSE:
1323 (u32CmdState.mvdcmd_handshake_pause) = 0;
1324 break;
1325 case MVD_HANDSHAKE_SLQ_RST:
1326 (u32CmdState.mvdcmd_handshake_slq_reset) = 0;
1327 break;
1328 case MVD_HANDSHAKE_STOP:
1329 (u32CmdState.mvdcmd_handshake_stop) = 0;
1330 break;
1331 case MVD_HANDSHAKE_SKIP_DATA:
1332 (u32CmdState.mvdcmd_handshake_skip_data) = 0;
1333 break;
1334 case MVD_HANDSHAKE_SINGLE_STEP:
1335 (u32CmdState.mvdcmd_handshake_single_step) = 0;
1336 break;
1337 case MVD_HANDSHAKE_SCALER_INFO:
1338 (u32CmdState.mvdcmd_handshake_scaler_data_ready) = 0;
1339 break;
1340 case MVD_HANDSHAKE_GET_NXTDISPFRM:
1341 (u32CmdState.mvdcmd_handshake_get_nextdispfrm_ready) = 0;
1342 break;
1343 case MVD_HANDSHAKE_PARSER_RST:
1344 (u32CmdState.mvdcmd_handshake_parser_rst) = 0;
1345 break;
1346 case MVD_HANDSHAKE_RST_CC608:
1347 (u32CmdState.mvdcmd_handshake_cc608_rst) = 0;
1348 break;
1349 case MVD_HANDSHAKE_RST_CC708:
1350 (u32CmdState.mvdcmd_handshake_cc708_rst) = 0;
1351 break;
1352 case MVD_HANDSHAKE_VIRTUAL_COMMAND:
1353 (u32CmdState.mvdcmd_handshake_virtualCommand) = 0;
1354 break;
1355 case MVD_HANDSHAKE_FLUSHQUEUE_COMMAND:
1356 (u32CmdState.mvdcmd_handshake_flush) = 0;
1357 break;
1358 default:
1359 break;
1360 }
1361 HAL_MVD_MemWrite4Byte(u32BufAddr + OFFSET_CMD_HANDSHAKE_INDEX,u32CmdState.value);
1362 MsOS_FlushMemory();
1363 }
1364
1365 //------------------------------------------------------------------------------
1366 /// Wait MVD command ready or timeout
1367 /// @return -MVD command ready or timeout
1368 //------------------------------------------------------------------------------
HAL_MVD_TimeOut(MS_U8 u8Idx)1369 MS_BOOL HAL_MVD_TimeOut(MS_U8 u8Idx)
1370 {
1371 MS_U32 i;
1372 MS_U32 u32StartTime = MsOS_GetSystemTime();
1373
1374 for ( i = 0; i < MVD_PollingTimes; i++ )
1375 {
1376 ///- wait until MVD command ready or timeout
1377 if ( ( HAL_MVD_RegReadByte(MVD_STATUS) & MVD_STATUS_READY ) == MVD_STATUS_READY )
1378 {
1379 return FALSE;
1380 }
1381
1382 if (/*(TRUE == pMVDHalContext->bStopped[u8Idx]) ||*/ ((MsOS_GetSystemTime()-u32StartTime)>1300))
1383 {
1384 MVD_DEBUGINFO(printf("%s: bStopped(%x) or timeout(%d)\n", __FUNCTION__, pMVDHalContext->bStopped[u8Idx], MsOS_GetSystemTime()-u32StartTime));
1385 return TRUE;
1386 }
1387
1388 //HAL_MVD_Sleep(5);
1389 }
1390 MVD_DEBUGERROR( printf("MVD_TimeOut=%x\n", i) );
1391 return TRUE;
1392 }
1393
1394 //------------------------------------------------------------------------------
1395 /// Set MVD firmware command
1396 /// @param -u8cmd \b IN : MVD command
1397 /// @param -pstCmdArg \b IN : pointer to command argument
1398 //------------------------------------------------------------------------------
HAL_MVD_MVDCommand(MS_U8 u8cmd,MVD_CmdArg * pstCmdArg)1399 MS_BOOL HAL_MVD_MVDCommand ( MS_U8 u8cmd, MVD_CmdArg *pstCmdArg )
1400 {
1401 MS_BOOL bRet = TRUE;
1402 #ifdef VDEC3
1403 MS_U32 u32CmdArg;
1404 MS_U32 u32Ret = FALSE;
1405 MS_U32 u32Timeout;
1406 MS_U8 u8HalIdx = pstCmdArg->Arg5;
1407 MS_U32 u32Id = MVD_GetStreamId(u8HalIdx);
1408 MS_U8 u8VPUIdx = HAL_VPU_EX_GetTaskId(u32Id);
1409 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8HalIdx);
1410 CMD_QUEUE *pShm = (CMD_QUEUE *)MsOS_PA2KSEG1(pstMemCfg->u32FWCodeAddr + VCOMMANDQ_INFO_START + u8VPUIdx*0x100000);
1411 MS_VIRT u32BufStart2 = NULL;
1412 MS_BOOL bResponse = FALSE;
1413 #endif
1414 OSAL_MVD_LockHwMutex();
1415
1416 #ifdef VDEC3
1417 if(HAL_MVD_IsDisplayCommand(u8cmd) == TRUE)
1418 {
1419 if(HAL_MVD_IsNeedResponseCommand(u8cmd) == TRUE)
1420 {
1421 // clear handshake dram
1422 u32BufStart2 = GET_VOL_BUFFADD(u8HalIdx);
1423
1424 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,u32BufStart2,u32BufStart2);
1425
1426 MS_U8* temp2 = (MS_U8*)MsOS_PA2KSEG1(u32BufStart2+OFFSET_VCHANDSHAKE);
1427
1428 *temp2 = 0;
1429
1430 MsOS_FlushMemory();
1431 }
1432
1433
1434 u32CmdArg = pstCmdArg->Arg0 | (pstCmdArg->Arg1<<8) | (pstCmdArg->Arg2 << 16) | (pstCmdArg->Arg3 << 24);
1435
1436 u32Timeout = MsOS_GetSystemTime()+VIRTUAL_CMD_TIMEOUT;
1437
1438 do
1439 {
1440 u32Ret = HAL_VPU_EX_DRAMStreamDispCMDQueueSend(u32Id,(void*)pShm,E_HVD_CMDQ_ARG,u32CmdArg);
1441
1442
1443 if(u32Ret == E_HVD_COMMAND_QUEUE_NOT_INITIALED)
1444 {
1445 bRet = FALSE;
1446 break;
1447 }
1448 else if (MsOS_GetSystemTime() > u32Timeout && u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL )
1449 {
1450 bRet = FALSE;
1451 break;
1452 }
1453 }while(u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL);
1454
1455 if(bRet == FALSE || u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL)
1456 {
1457 bRet = FALSE;
1458 goto _CMD_DONE;
1459 }
1460
1461
1462 u32Timeout = MsOS_GetSystemTime()+VIRTUAL_CMD_TIMEOUT;
1463
1464 do
1465 {
1466 u32Ret = HAL_VPU_EX_DRAMStreamDispCMDQueueSend(u32Id,(void*)pShm,E_HVD_CMDQ_CMD,u8cmd|(u8VPUIdx<<24)|(pstCmdArg->Arg4<<16));
1467
1468 if(u32Ret == E_HVD_COMMAND_QUEUE_NOT_INITIALED)
1469 {
1470 bRet = FALSE;
1471 break;
1472 }
1473 else if (MsOS_GetSystemTime() > u32Timeout && u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL)
1474 {
1475 bRet = FALSE;
1476 break;
1477 }
1478 }while(u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL);
1479
1480 if(bRet == FALSE || u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL)
1481 {
1482 bRet = FALSE;
1483 goto _CMD_DONE;
1484 }
1485
1486 if(HAL_MVD_IsNeedResponseCommand(u8cmd) == TRUE)
1487 {
1488 u32Timeout = MsOS_GetSystemTime()+VIRTUAL_CMD_TIMEOUT;
1489
1490 while(MsOS_GetSystemTime() < u32Timeout)
1491 {
1492 #if 0
1493 if (HAL_MVD_IsCmdFinished(u8HalIdx, MVD_HANDSHAKE_VIRTUAL_COMMAND))
1494 {
1495 bResponse = TRUE;
1496 break;
1497 }
1498 #else
1499 if(MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VCHANDSHAKE, sizeof(MS_U8)) == 1)
1500 {
1501 bResponse = TRUE;
1502 break;
1503 }
1504 #endif
1505 }
1506
1507 if(bResponse == FALSE) // fail case
1508 {
1509 bRet = FALSE;
1510 goto _CMD_DONE;
1511 }
1512
1513 pstCmdArg->Arg0 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG0, sizeof(MS_U8));
1514 pstCmdArg->Arg1 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG1, sizeof(MS_U8));
1515 pstCmdArg->Arg2 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG2, sizeof(MS_U8));
1516 pstCmdArg->Arg3 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG3, sizeof(MS_U8));
1517 pstCmdArg->Arg4 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG4, sizeof(MS_U8));
1518 }
1519
1520 }
1521 else if(HAL_MVD_IsNormalCommand(u8cmd) == TRUE)
1522 {
1523 if(HAL_MVD_IsNeedResponseCommand(u8cmd) == TRUE)
1524 {
1525 // clear handshake dram
1526 u32BufStart2 = GET_VOL_BUFFADD(u8HalIdx);
1527
1528 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,u32BufStart2,u32BufStart2);
1529
1530 MS_U8* temp2 = (MS_U8*)MsOS_PA2KSEG1(u32BufStart2+OFFSET_VCHANDSHAKE);
1531
1532 *temp2 = 0;
1533
1534 MsOS_ReadMemory();
1535 MsOS_FlushMemory();
1536 }
1537
1538 u32CmdArg = pstCmdArg->Arg0 | (pstCmdArg->Arg1<<8) | (pstCmdArg->Arg2 << 16) | (pstCmdArg->Arg3 << 24);
1539
1540 u32Timeout = MsOS_GetSystemTime()+VIRTUAL_CMD_TIMEOUT;
1541
1542 do
1543 {
1544 //u32Ret = HAL_VPU_EX_DRAMStreamCMDQueueSend_MVD(pstCmdArg->Arg5,E_HVD_CMDQ_ARG,u32CmdArg);
1545 u32Ret = HAL_VPU_EX_DRAMStreamCMDQueueSend(u32Id,(void*)pShm,E_HVD_CMDQ_ARG,u32CmdArg);
1546
1547 if(u32Ret == E_HVD_COMMAND_QUEUE_NOT_INITIALED)
1548 {
1549 bRet = FALSE;
1550 break;
1551 }
1552 else if (MsOS_GetSystemTime() > u32Timeout && u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL )
1553 {
1554 bRet = FALSE;
1555 break;
1556 }
1557 }while(u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL);
1558
1559
1560 if(bRet == FALSE || u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL)
1561 {
1562 bRet = FALSE;
1563 goto _CMD_DONE;
1564 }
1565
1566
1567 u32Timeout = MsOS_GetSystemTime()+VIRTUAL_CMD_TIMEOUT;
1568 do
1569 {
1570 //u32Ret = HAL_VPU_EX_DRAMStreamCMDQueueSend_MVD(pstCmdArg->Arg5,E_HVD_CMDQ_CMD,u8cmd|(pstCmdArg->Arg5<<24)|(pstCmdArg->Arg4<<16));
1571 u32Ret = HAL_VPU_EX_DRAMStreamCMDQueueSend(u32Id,(void*)pShm,E_HVD_CMDQ_CMD,u8cmd|(u8VPUIdx<<24)|(pstCmdArg->Arg4<<16));
1572
1573 if(u32Ret == E_HVD_COMMAND_QUEUE_NOT_INITIALED)
1574 {
1575 bRet = FALSE;
1576 break;
1577 }
1578 else if (MsOS_GetSystemTime() > u32Timeout && u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL)
1579 {
1580 bRet = FALSE;
1581 break;
1582 }
1583 }while(u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL);
1584
1585 if(bRet == FALSE || u32Ret != E_HVD_COMMAND_QUEUE_SEND_SUCCESSFUL)
1586 {
1587 bRet = FALSE;
1588 goto _CMD_DONE;
1589 }
1590
1591 if(HAL_MVD_IsNeedResponseCommand(u8cmd) == TRUE)
1592 {
1593 u32Timeout = MsOS_GetSystemTime()+VIRTUAL_CMD_TIMEOUT;
1594
1595 while(MsOS_GetSystemTime() < u32Timeout)
1596 {
1597 #if 0
1598 if (HAL_MVD_IsCmdFinished(u8HalIdx, MVD_HANDSHAKE_VIRTUAL_COMMAND))
1599 {
1600 bResponse = TRUE;
1601 break;
1602 }
1603 #else
1604 if(MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VCHANDSHAKE, sizeof(MS_U8)) == 1)
1605 {
1606 bResponse = TRUE;
1607 break;
1608 }
1609 #endif
1610 }
1611
1612 if(bResponse == FALSE) // fail case
1613 {
1614 bRet = FALSE;
1615 goto _CMD_DONE;
1616 }
1617
1618 pstCmdArg->Arg0 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG0, sizeof(MS_U8));
1619 pstCmdArg->Arg1 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG1, sizeof(MS_U8));
1620 pstCmdArg->Arg2 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG2, sizeof(MS_U8));
1621 pstCmdArg->Arg3 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG3, sizeof(MS_U8));
1622 pstCmdArg->Arg4 = MVD_GetFWBuffData(u8HalIdx, FW_BUFF_VOLINFO, OFFSET_VIRTUAL_COMMANDARG4, sizeof(MS_U8));
1623 }
1624 }
1625 else
1626 #endif
1627 {
1628 if ( HAL_MVD_TimeOut(pstCmdArg->Arg5) == TRUE )
1629 {
1630 bRet = FALSE;
1631 goto _CMD_DONE;
1632 }
1633
1634 HAL_MVD_RegWriteByte(MVD_ARG0, pstCmdArg->Arg0);
1635 HAL_MVD_RegWriteByte(MVD_ARG1, pstCmdArg->Arg1);
1636 HAL_MVD_RegWriteByte(MVD_ARG2, pstCmdArg->Arg2);
1637 HAL_MVD_RegWriteByte(MVD_ARG3, pstCmdArg->Arg3);
1638 HAL_MVD_RegWriteByte(MVD_ARG4, pstCmdArg->Arg4);
1639 HAL_MVD_RegWriteByte(MVD_ARG5, pstCmdArg->Arg5);
1640 HAL_MVD_RegWriteByte(MVD_COMMAND, u8cmd);
1641 if ((CMD_GET_AFD != u8cmd) && (CMD_SLQ_GET_TBL_RPTR != u8cmd) &&
1642 (CMD_SLQ_UPDATE_TBL_WPTR != u8cmd) && (CMD_GET_NEXTDISPFRM != u8cmd) &&
1643 (CMD_DECODE_STATUS != u8cmd) && (CMD_RD_PTS != u8cmd) &&
1644 (CMD_GET_INT_STAT != u8cmd) && (CMD_RD_IO != u8cmd))
1645 {
1646 MVD_DEBUG_FWCMD(printf("MVD_CMD: %x; %x, %x, %x, %x, %x, %x\n", u8cmd, pstCmdArg->Arg0,
1647 pstCmdArg->Arg1, pstCmdArg->Arg2, pstCmdArg->Arg3, pstCmdArg->Arg4, pstCmdArg->Arg5));
1648 }
1649
1650 if ( HAL_MVD_TimeOut(pstCmdArg->Arg5) == TRUE )
1651 {
1652 bRet = FALSE;
1653 goto _CMD_DONE;
1654 }
1655
1656 pstCmdArg->Arg0 = HAL_MVD_RegReadByte(MVD_ARG0);
1657 pstCmdArg->Arg1 = HAL_MVD_RegReadByte(MVD_ARG1);
1658 pstCmdArg->Arg2 = HAL_MVD_RegReadByte(MVD_ARG2);
1659 pstCmdArg->Arg3 = HAL_MVD_RegReadByte(MVD_ARG3);
1660 pstCmdArg->Arg4 = HAL_MVD_RegReadByte(MVD_ARG4);
1661 pstCmdArg->Arg5 = HAL_MVD_RegReadByte(MVD_ARG5);
1662 }
1663
1664 _CMD_DONE:
1665 OSAL_MVD_UnlockHwMutex();
1666
1667 if (!bRet)
1668 {
1669 MVD_DEBUG_FWCMD(printf("%s timeout dump pc\n", __FUNCTION__));
1670 MS_U32 x=0;
1671 for (x=0; x<30; x++)
1672 MVD_DEBUG_FWCMD(printf("0x%x\n", HAL_VPU_EX_GetProgCnt()));
1673 MVD_DEBUG_FWCMD(printf("###\n"));
1674 }
1675
1676 return bRet;
1677 }
1678
HAL_MVD_SetSyncClk(MS_BOOL bEnable)1679 void HAL_MVD_SetSyncClk(MS_BOOL bEnable)
1680 {
1681 MS_ASSERT(0==bEnable);//Notice: Euclid & T3 have no sync_mode; Bit4 must be 0.
1682
1683 OSAL_MVD_LockHwMutex();
1684 HAL_MVD_RegWriteBit(MVD_CTRL, bEnable, MVD_CTRL_CLK_SYNCMODE);
1685 OSAL_MVD_UnlockHwMutex();
1686
1687 return;
1688 }
1689
HAL_MVD_InitHW(void)1690 MS_BOOL HAL_MVD_InitHW(void)
1691 {
1692 //Set MVD Clock @ reg_CHIPTOP
1693 HAL_MVD_PowerCtrl(ENABLE);
1694
1695 //Set MVD Clock aync
1696 HAL_MVD_SetSyncClk(DISABLE);
1697
1698 //MVD reset
1699 if(!HAL_MVD_RstHW())
1700 {
1701 MVD_DEBUGERROR(printf("MDrv_MVD_MVDInit:MVD4ResetHW failed\n"));
1702 return FALSE;
1703 }
1704 else
1705 {
1706 MVD_DEBUGINFO(printf("MDrv_MVD_MVDInit:MVD4ResetHW success\n"));
1707 }
1708
1709 return TRUE;
1710 }
1711
1712
1713 //------------------------------------------------------------------------------
1714 /// Get MVD firmware version
1715 /// @return -firmware version
1716 //------------------------------------------------------------------------------
HAL_MVD_GetFWVer(MS_U32 u32VpuSid)1717 MS_U32 HAL_MVD_GetFWVer(MS_U32 u32VpuSid)
1718 {
1719 #if 0
1720 return HAL_VPU_EX_GetFWVer(u32VpuSid, E_VPU_EX_FW_VER_MVD_FW);
1721 #else
1722 //UNUSED(u32VpuSid);
1723 MVD_CmdArg mvdcmd;
1724
1725 SETUP_CMDARG(mvdcmd);
1726 mvdcmd.Arg5 = HAL_VPU_EX_GetTaskId(u32VpuSid);
1727 if (HAL_MVD_MVDCommand( CMD_GET_FW_VERSION, &mvdcmd ) == FALSE)
1728 {
1729 MVD_ERROR( printf( "Command: 0x%x fail!!\r\n", CMD_GET_FW_VERSION ) );
1730 return 0;
1731 }
1732 return COMBU32(mvdcmd.Arg3,mvdcmd.Arg2,mvdcmd.Arg1,mvdcmd.Arg0);
1733 #endif
1734 }
1735
1736 //------------------------------------------------------------------------------
1737 /// Get MVD firmware interface version
1738 /// @return -firmware interface version
1739 //------------------------------------------------------------------------------
HAL_MVD_GetFWIfVer(MS_U32 u32VpuSid)1740 MS_U32 HAL_MVD_GetFWIfVer(MS_U32 u32VpuSid)
1741 {
1742 #if 0
1743 return HAL_VPU_EX_GetFWVer(u32VpuSid, E_VPU_EX_FW_VER_MVD_IF);
1744 #else
1745 UNUSED(u32VpuSid);
1746 MVD_CmdArg mvdcmd;
1747
1748 SETUP_CMDARG(mvdcmd);
1749 if (HAL_MVD_MVDCommand( CMD_INTERFACE_VERSION, &mvdcmd ) == FALSE)
1750 {
1751 MVD_ERROR( printf( "Command: 0x%x fail!!\r\n", CMD_INTERFACE_VERSION ) );
1752 return 0;
1753 }
1754 return COMBU32(mvdcmd.Arg3,mvdcmd.Arg2,mvdcmd.Arg1,mvdcmd.Arg0);
1755 #endif
1756 }
1757
1758 //------------------------------------------------------------------------------
1759 /// Check MVD firmware status
1760 /// @return -firmware is ready or not
1761 //------------------------------------------------------------------------------
1762
1763 #ifdef VDEC3
_MVD_Check_FW_Rdy(MS_U32 u32VpuSid)1764 static MS_BOOL _MVD_Check_FW_Rdy(MS_U32 u32VpuSid)
1765 {
1766 MS_U32 u32Id = MVD_GetStreamId(u32VpuSid);
1767 MS_U8 u8VPUIdx = HAL_VPU_EX_GetTaskId(u32Id);
1768 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u32VpuSid);
1769 MS_U32 u32TimeOut = MsOS_GetSystemTime() + 500;
1770 unsigned int* pVersion = (unsigned int*)MsOS_PA2KSEG1(pstMemCfg->u32FWCodeAddr + OFFSET_BASE + u8VPUIdx*0x100000);
1771 MS_BOOL ret = FALSE;
1772
1773 while(MsOS_GetSystemTime() < u32TimeOut)
1774 {
1775 if(((*pVersion) == FW_VERSION) && ((*(pVersion+4)) == INTERFACE_VERSION))
1776 {
1777 ret = TRUE;
1778 break;
1779 }
1780 }
1781
1782 if (ret == FALSE)
1783 {
1784 MVD_ERROR(printf("MVD f/w header version is wrong,%x,%x,%x,%x\n",(*(pVersion+4)), INTERFACE_VERSION,(*pVersion), FW_VERSION));
1785 }
1786
1787 return ret;
1788 }
1789
1790 #else
_MVD_Check_FW_Rdy(MS_U32 u32VpuSid)1791 static MS_BOOL _MVD_Check_FW_Rdy(MS_U32 u32VpuSid)
1792 {
1793 MS_U32 u32TimeOut = 2000;
1794
1795 //check firmware version consistent with header file
1796 while ((INTERFACE_VERSION != HAL_MVD_GetFWIfVer(u32VpuSid)) && (--u32TimeOut));
1797 if (u32TimeOut == 0)
1798 {
1799 MVD_ERROR(printf("MVD_FW_IF_Version=%lx inconsistent with header file(%x)!\n",
1800 HAL_MVD_GetFWIfVer(u32VpuSid), INTERFACE_VERSION));
1801 return FALSE;
1802 }
1803
1804 if (FW_VERSION != HAL_MVD_GetFWVer(u32VpuSid))
1805 {
1806 MVD_DEBUGINFO(printf("Warning! FWBinVer(%lx) != FWHdrVer(%x)\n", HAL_MVD_GetFWVer(u32VpuSid), FW_VERSION));
1807 }
1808 MVD_DEBUGINFO(printf("MVD version Interface = %x, FW = %x\n", INTERFACE_VERSION, FW_VERSION));
1809
1810 return TRUE;
1811 }
1812 #endif
_DumpCtrl(MS_U8 u8Idx)1813 MS_BOOL _DumpCtrl(MS_U8 u8Idx)
1814 {
1815 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
1816
1817 //printf("u32VA=0x%lx, PA=0x%x\n", u32VA, pstMemCfg->u32FWCodeAddr);
1818 struct _ctl_info *ctl_ptr = (struct _ctl_info *)
1819 HAL_MVD_PA2NonCacheSeg(pstMemCfg->u32FWCodeAddr + CTL_INFO_ADDR);
1820 MS_U32 u32timeout = HAL_MVD_GetTime() + 1000;//u32HVDCmdTimeout;
1821
1822 HAL_MVD_ReadMemory();
1823
1824 MVD_DEBUGINFO(printf("version=0x%x, statue=0x%x, last_ctl_cmd=0x%x, last_ctl_arg=0x%x\n",
1825 ctl_ptr->verion, ctl_ptr->statue, ctl_ptr->last_ctl_cmd, ctl_ptr->last_ctl_arg));
1826
1827 while (CTL_TASK_CMDRDY != ctl_ptr->statue)
1828 {
1829 if (HAL_MVD_GetTime() > u32timeout)
1830 {
1831 MVD_DEBUGERROR(printf("CTRL timeout!!! %d\n", __LINE__));
1832 return FALSE;
1833 }
1834 }
1835
1836 MVD_DEBUGINFO(printf("Version=0x%x, statue=0x%x, last_ctl_cmd=0x%x, last_ctl_arg=0x%x\n",
1837 ctl_ptr->verion, ctl_ptr->statue, ctl_ptr->last_ctl_cmd, ctl_ptr->last_ctl_arg));
1838
1839 MS_U8 i;
1840
1841 for (i = 0; i < 4; i++)
1842 {
1843 MVD_DEBUGINFO(printf("%s: Task %d, status=%d\n", __FUNCTION__, i, ctl_ptr->task_statue[i]));
1844 }
1845 return TRUE;
1846 }
1847
1848
MVD_MapVpuSrcType(MVD_SrcMode eSrcMode)1849 static VPU_EX_SourceType MVD_MapVpuSrcType(MVD_SrcMode eSrcMode)
1850 {
1851 VPU_EX_SourceType eVpuSrcType = E_VPU_EX_INPUT_NONE;
1852 switch (eSrcMode)
1853 {
1854 case E_MVD_TS_MODE:
1855 case E_MVD_TS_FILE_MODE:
1856 eVpuSrcType = E_VPU_EX_INPUT_TSP;
1857 break;
1858
1859 case E_MVD_SLQ_TBL_MODE:
1860 case E_MVD_SLQ_MODE:
1861 case E_MVD_FILE_MODE:
1862 eVpuSrcType = E_VPU_EX_INPUT_FILE;
1863 break;
1864
1865 case E_MVD_SRC_UNKNOWN:
1866 default:
1867 break;
1868 }
1869 return eVpuSrcType;
1870 }
1871
MVD_GetTaskInfo(VPU_EX_TaskInfo * pstTaskInfo,MS_U8 u8Idx,HAL_VPU_StreamId eVpuId)1872 static void MVD_GetTaskInfo(VPU_EX_TaskInfo* pstTaskInfo, MS_U8 u8Idx, HAL_VPU_StreamId eVpuId)
1873 {
1874 pstTaskInfo->u32Id = (u8Idx << 8 | eVpuId);
1875 pstTaskInfo->eDecType = E_VPU_EX_DECODER_MVD;
1876 pstTaskInfo->eVpuId = eVpuId;
1877 pstTaskInfo->eSrcType = MVD_MapVpuSrcType(HAL_MVD_GetSrcMode(u8Idx));
1878 pstTaskInfo->u32HeapSize = MVD_DRAM_SIZE;
1879 }
1880
1881
HAL_MVD_CreateTask(MS_U8 u8Idx,HAL_VPU_StreamId eVpuId)1882 MS_BOOL HAL_MVD_CreateTask(MS_U8 u8Idx, HAL_VPU_StreamId eVpuId)
1883 {
1884 MS_BOOL bRet = FALSE;
1885 MS_BOOL bFWdecideFB = FALSE;
1886 MVD_FWCfg* pstCfg = HAL_MVD_GetFWCfg(u8Idx);
1887 HAL_VPU_EX_SetFWReload(!(pstCfg->bNotReload));
1888
1889 MVD_DEBUGINFO(printf("\n\n Create Task(%x)!!!\n", u8Idx));
1890 VPU_EX_TaskInfo stTaskInfo;
1891 MVD_GetTaskInfo(&stTaskInfo, u8Idx, eVpuId);
1892
1893 VPU_EX_FWCodeCfg stVpuFWCfg;
1894 VPU_EX_NDecInitPara stVpuInitPara;
1895 stVpuInitPara.pFWCodeCfg = &stVpuFWCfg;
1896 stVpuInitPara.pTaskInfo = &stTaskInfo;
1897 stVpuInitPara.pVLCCfg = NULL;
1898
1899 MVD_MEMCfg* pMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
1900 stVpuFWCfg.u32BinAddr = HAL_MVD_PA2NonCacheSeg(pMemCfg->u32FWBinAddr);
1901 stVpuFWCfg.u32BinSize = pMemCfg->u32FWBinSize;
1902 stVpuFWCfg.u32DstAddr = HAL_MVD_PA2NonCacheSeg(pMemCfg->u32FWCodeAddr);
1903 stVpuFWCfg.u32DstSize = pMemCfg->u32FWCodeSize;
1904 stVpuFWCfg.u8SrcType = pMemCfg->eFWSrcType;
1905
1906 #ifdef VDEC3
1907 VPU_EX_FBCfg pFBCfg;
1908 stVpuInitPara.pFBCfg = &pFBCfg;
1909
1910 if(pMVDHalContext->bCMAUsed == TRUE)
1911 {
1912 stVpuInitPara.pFBCfg->u32FrameBufAddr = (MS_VIRT)pMVDHalContext->cmaInitParam.heap_miu_start_offset;
1913 stVpuInitPara.pFBCfg->u32FrameBufSize = (MS_VIRT)pMVDHalContext->cmaInitParam.heap_length;
1914 bFWdecideFB = TRUE;
1915
1916 }
1917 stTaskInfo.u8HalId = u8Idx;
1918 pMVDHalContext->_stMVDStream[u8Idx].u32SLQId = HAL_VPU_EX_GetBBUId(stTaskInfo.u32Id, &stTaskInfo, FALSE);
1919 if(pMVDHalContext->_stMVDStream[u8Idx].u32SLQId == HAL_VPU_INVALID_BBU_ID)
1920 {
1921 MVD_DEBUGINFO(printf("ERROR!!!MVD GetBBU Id Fail \n"));
1922 }
1923 else
1924 {
1925 bRet = HAL_VPU_EX_TaskCreate((MS_U32)eVpuId, (void*)&stVpuInitPara, bFWdecideFB, pMVDHalContext->_stMVDStream[u8Idx].u32SLQId);
1926 }
1927
1928 if(bRet == FALSE)
1929 {
1930 if(!HAL_VPU_EX_FreeBBUId(stTaskInfo.u32Id, pMVDHalContext->_stMVDStream[u8Idx].u32SLQId, &stTaskInfo))
1931 {
1932 MVD_DEBUGERROR(printf("[%s][%d]ERROR!!! Free BBU Id Fail !!!\n",__FUNCTION__,__LINE__));
1933 }
1934 }
1935 #else
1936 bRet = HAL_VPU_EX_TaskCreate((MS_U32)eVpuId, (void*)&stVpuInitPara);
1937 #endif
1938 MVD_DEBUGINFO(printf(" Create Task!!! bRet=%x ###\n\n", bRet));
1939 _DumpCtrl(u8Idx);
1940
1941 return bRet;
1942 }
1943
HAL_MVD_DeleteTask(MS_U8 u8Idx,HAL_VPU_StreamId eVpuId)1944 MS_BOOL HAL_MVD_DeleteTask(MS_U8 u8Idx, HAL_VPU_StreamId eVpuId)
1945 {
1946 MS_BOOL bRet = FALSE;
1947 MVD_DEBUGINFO(printf("\n\n Delete Task(%x)!!!\n", u8Idx));
1948
1949 VPU_EX_TaskInfo stTaskInfo;
1950 MVD_GetTaskInfo(&stTaskInfo, u8Idx, eVpuId);
1951
1952 VPU_EX_FWCodeCfg stVpuFWCfg;
1953 VPU_EX_NDecInitPara stVpuInitPara;
1954 stVpuInitPara.pFWCodeCfg = &stVpuFWCfg;
1955 stVpuInitPara.pTaskInfo = &stTaskInfo;
1956
1957 MVD_MEMCfg* pMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
1958 stVpuFWCfg.u32BinAddr = HAL_MVD_PA2NonCacheSeg(pMemCfg->u32FWBinAddr);
1959 stVpuFWCfg.u32BinSize = pMemCfg->u32FWBinSize;
1960 stVpuFWCfg.u32DstAddr = HAL_MVD_PA2NonCacheSeg(pMemCfg->u32FWCodeAddr);
1961 stVpuFWCfg.u8SrcType = pMemCfg->eFWSrcType;
1962
1963 #ifdef VDEC3
1964 if(!HAL_VPU_EX_FreeBBUId(stTaskInfo.u32Id, pMVDHalContext->_stMVDStream[u8Idx].u32SLQId, &stTaskInfo))
1965 {
1966 MVD_DEBUGINFO(printf("ERROR!!! Free BBU Id Fail !!!\n"));
1967 }
1968 #endif
1969 bRet = HAL_VPU_EX_TaskDelete((MS_U32) eVpuId, &stVpuInitPara);
1970 MVD_DEBUGINFO(printf(" Delete Task!!! ###\n\n"));
1971 _DumpCtrl(u8Idx);
1972 return bRet;
1973 }
1974
HAL_MVD_InitFW(MS_U32 u32VpuSid)1975 MS_BOOL HAL_MVD_InitFW(MS_U32 u32VpuSid)
1976 {
1977 //to fix the timing issue of getting FWIfVer on Chakra2
1978 HAL_MVD_Delayms(1);
1979
1980 //check FW ready
1981 if ( !_MVD_Check_FW_Rdy(u32VpuSid))
1982 {
1983 MS_ASSERT(0);
1984 return FALSE;
1985 }
1986
1987 #if 0
1988 if(pMVDHalContext->_stMVDStream[0].bUsed == FALSE && pMVDHalContext->_stMVDStream[1].bUsed == FALSE) // no mvd is used
1989 {
1990 MVD_CmdArg mvdcmd;
1991 SETUP_CMDARG(mvdcmd);
1992 mvdcmd.Arg0 = 1; //reset mvd engine,if have only one mvd
1993 SET_DECNUM(mvdcmd, ((MS_U8)u32VpuSid));
1994 if (HAL_MVD_MVDCommand( CMD_SW_RESET, &mvdcmd ) == FALSE)
1995 {
1996 MVD_ERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SW_RESET ) );
1997 return FALSE;
1998 }
1999 }
2000 #endif
2001 return TRUE;
2002 }
2003
2004 #define _MVD_INIT_FAIL_RET() \
2005 do { \
2006 HAL_MVD_SetIsUsed(u8HalIdx, FALSE); \
2007 return FALSE; \
2008 } while (0)
2009
2010
HAL_MVD_Init(MS_U8 u8HalIdx,MVD_CodecType eCodecType,MS_U32 u32VpuSid)2011 MS_BOOL HAL_MVD_Init(MS_U8 u8HalIdx,MVD_CodecType eCodecType, MS_U32 u32VpuSid)
2012 {
2013 //OSAL_MVD_MutexInit();
2014 MS_BOOL no_use = FALSE;
2015 MS_BOOL ret;
2016
2017 ret = MDrv_MVD_AUTH_IPCheck(eCodecType,&no_use);
2018 if(ret == FALSE)
2019 {
2020 return FALSE;
2021 }
2022
2023 if (!HAL_MVD_CreateTask(u8HalIdx, (HAL_VPU_StreamId)u32VpuSid))
2024 {
2025 _MVD_INIT_FAIL_RET();
2026 }
2027
2028 pMVDHalContext->bStopped[u8HalIdx] = FALSE;
2029
2030 if (!HAL_MVD_InitFW(u8HalIdx))
2031 {
2032 MVD_DEBUGERROR(printf("%s:HAL_MVD_InitFW(%x) failed\n", __FUNCTION__, u8HalIdx));
2033 if (!HAL_MVD_DeleteTask(u8HalIdx, (HAL_VPU_StreamId)u32VpuSid))
2034 {
2035 MVD_DEBUGERROR(printf("%s:HAL_MVD_DeleteTask failed\n", __FUNCTION__));
2036 }
2037
2038 _MVD_INIT_FAIL_RET();
2039 }
2040 else
2041 {
2042 MVD_DEBUGINFO(printf("%s:HAL_MVD_InitFW(%x) success\n", __FUNCTION__, u8HalIdx));
2043 }
2044
2045 HAL_MVD_SetIsUsed(u8HalIdx, TRUE);
2046
2047 return TRUE;
2048 }
2049
2050 #define _MVD_CMDRDY ((HAL_MVD_RegReadByte(MVD_STATUS) & MVD_STATUS_READY) == MVD_STATUS_READY)
2051 //------------------------------------------------------------------------------
2052 /// Check if MVD command is ready
2053 /// @return TRUE or FALSE
2054 /// - TRUE, Success to process the command
2055 /// - FALSE, Failed due to timeout
2056 //------------------------------------------------------------------------------
HAL_MVD_GetCmdRdy(void)2057 MS_BOOL HAL_MVD_GetCmdRdy(void)
2058 {
2059 MS_U32 timeoutTick = 2000;
2060
2061 while ((!_MVD_CMDRDY) && ((timeoutTick--)!=0));
2062
2063 if (0 == timeoutTick)
2064 return FALSE;
2065 else
2066 return TRUE;
2067 }
2068
HAL_MVD_CheckIdle(void)2069 MS_BOOL HAL_MVD_CheckIdle(void)
2070 {
2071 MS_BOOL bIsIdle = FALSE;
2072 MVD_CmdArg mvdcmd;
2073
2074 //issue CheckIdle command
2075 SETUP_CMDARG(mvdcmd);
2076 SET_CMD_RET_FALSE(CMD_MVD_IDLE, &mvdcmd);
2077
2078 bIsIdle = (mvdcmd.Arg0 == 1);
2079 if (HAL_MVD_GetCmdRdy())
2080 {
2081 return bIsIdle;
2082 }
2083 else
2084 {
2085 return FALSE;
2086 }
2087 }
2088
2089
_MVD_SoftRstHW(void)2090 static MS_BOOL _MVD_SoftRstHW(void)
2091 {
2092 return FALSE;
2093 }
2094
2095 //------------------------------------------------------------------------------
2096 /// Soft-reset MVD
2097 /// Ref AP note p.12 HK2MVD Reset Flow
2098 /// @return TRUE or FALSE
2099 /// - TRUE, Success to soft-reset MVD
2100 /// - FALSE, Failed. Need init MVD again.
2101 //------------------------------------------------------------------------------
HAL_MVD_SoftRstHW(void)2102 MS_BOOL HAL_MVD_SoftRstHW(void)
2103 {
2104 MS_U32 timetick = 2000;
2105
2106 if (HAL_MVD_GetCmdRdy())
2107 {
2108 //idle check
2109 while ((!HAL_MVD_CheckIdle()) && ((timetick--)!=0));
2110
2111 //either MVD is idle or timeout, do ENG/SLQ reset
2112 return _MVD_SoftRstHW(); //Reset HW engine
2113 }
2114 else
2115 {
2116 return FALSE; //here means "CPU hanging"
2117 }
2118 }
2119
2120 //------------------------------------------------------------------------------
2121 /// Clean the IRQ bit (in interrupt handler should call this function while the
2122 /// interrupt has been triggered.
2123 /// @param none
2124 /// @return none
2125 /// @internal
2126 //------------------------------------------------------------------------------
HAL_MVD_ClearIRQ(void)2127 void HAL_MVD_ClearIRQ(void)
2128 {
2129 OSAL_MVD_LockHwMutex();
2130 HAL_MVD_RegWriteBit(MVD_CTRL, 1, MVD_CTRL_CLR_INT);
2131 OSAL_MVD_UnlockHwMutex();
2132 return;
2133 }
2134
2135 //------------------------------------------------------------------------------
2136 /// Set display speed.
2137 ///FW use (# of B frames) / (# of decode frames) < Ratio this formula to adjustment.
2138 ///Once if the ratio is 1, that means, whenever (#Bframes / #decoded) < 1, then
2139 ///FW would drop the B frame.
2140 ///In other words, once AP need to back to normal mode, AP have to set the arg0 to 0.
2141 //------------------------------------------------------------------------------
HAL_MVD_SetSpeed(MS_U8 u8Idx,MVD_SpeedType eSpeedType,MS_U8 u8Multiple)2142 MS_BOOL HAL_MVD_SetSpeed(MS_U8 u8Idx, MVD_SpeedType eSpeedType, MS_U8 u8Multiple)
2143 {
2144 MVD_CmdArg mvdcmd;
2145
2146 SETUP_CMDARG(mvdcmd);
2147
2148 if (E_MVD_SPEED_FAST == eSpeedType)
2149 mvdcmd.Arg0 = 1; //fast forward
2150 else if (E_MVD_SPEED_SLOW == eSpeedType)
2151 mvdcmd.Arg0 = 2; //slow motion
2152 else
2153 mvdcmd.Arg0 = 0; //normal speed
2154
2155 if (u8Multiple == 1)
2156 {
2157 mvdcmd.Arg0 = 0;
2158 //The only way to be NORMAL speed.
2159 }
2160
2161 mvdcmd.Arg1 = u8Multiple;
2162 SET_DECNUM(mvdcmd, u8Idx);
2163 SET_CMD_RET_FALSE(CMD_DISP_SPEED_CTRL, &mvdcmd);
2164 return TRUE;
2165 }
2166
2167 //------------------------------------------------------------------------------
2168 /// Set frame buffer address to MVD
2169 /// @param -u32addr \b IN : start address
2170 //------------------------------------------------------------------------------
HAL_MVD_SetFrameBuffAddr(MS_U8 u8Idx,MS_VIRT u32addr,MS_U8 u8fbMode)2171 void HAL_MVD_SetFrameBuffAddr(MS_U8 u8Idx, MS_VIRT u32addr, MS_U8 u8fbMode)
2172 {
2173 MVD_CmdArg mvdcmd;
2174 if(pMVDHalContext->bCMAUsed)
2175 {
2176 u8fbMode = MVD_CMA_MODE;
2177 }
2178
2179 if ((u32addr>>3) > MAX_ADD_28BIT)// TODO: fixme, in 64bits system, address may be more than 28 bits
2180 {
2181 MVD_DEBUGERROR(printf("MDrv_MVD_SetFrameBuffAddr: only support 28bit add!\n"));
2182 return;
2183 }
2184
2185 MS_ASSERT((u32addr%8)==0);
2186 u32addr >>= 3;
2187
2188 SETUP_CMDARG(mvdcmd);
2189 mvdcmd.Arg0 = L_WORD(u32addr);
2190 mvdcmd.Arg1 = H_WORD(u32addr);
2191 mvdcmd.Arg2 = L_DWORD(u32addr);
2192
2193 //Frame Buffer Mode Setting
2194 mvdcmd.Arg3 = u8fbMode | ((u32addr>>24)&0x0f);
2195 mvdcmd.Arg4 = u8fbMode & 0xff;
2196 MVD_DEBUGINFO(printf("FramebufferAdd 0x%lx, FB Mode 0x%x, arg3=0x%x\n", (unsigned long)u32addr, u8fbMode, mvdcmd.Arg3));
2197 SET_DECNUM(mvdcmd, u8Idx);
2198 if (HAL_MVD_MVDCommand( CMD_FB_BASE, &mvdcmd ) == FALSE)
2199 {
2200 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FB_BASE ) );
2201 return;
2202 }
2203
2204 return;
2205 }
2206
2207 //------------------------------------------------------------------------------
2208 /// Set header buffer address to MVD
2209 /// @param -u32addr \b IN : start address
2210 //------------------------------------------------------------------------------
HAL_MVD_SetHeaderBufferAddr(MS_U8 u8Idx,MS_VIRT u32addr)2211 void HAL_MVD_SetHeaderBufferAddr (MS_U8 u8Idx, MS_VIRT u32addr )
2212 {
2213 MVD_CmdArg mvdcmd;
2214
2215 MS_ASSERT((u32addr%8)==0);
2216 u32addr >>= 3;
2217
2218 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2219 if (HAL_MVD_MVDCommand( CMD_HEADER_INFO_BUF, &mvdcmd ) == FALSE)
2220 {
2221 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_HEADER_INFO_BUF ) );
2222 }
2223 return;
2224 }
2225
2226 //------------------------------------------------------------------------------
2227 /// Set vol info buffer address to MVD
2228 /// @param -u32addr \b IN : start address
2229 //------------------------------------------------------------------------------
HAL_MVD_SetVolInfoBufferAddr(MS_U8 u8Idx,MS_VIRT u32addr)2230 void HAL_MVD_SetVolInfoBufferAddr (MS_U8 u8Idx, MS_VIRT u32addr )
2231 {
2232 MVD_CmdArg mvdcmd;
2233
2234 MS_ASSERT((u32addr%8)==0);
2235 u32addr >>= 3;
2236
2237 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2238 if (HAL_MVD_MVDCommand( CMD_VOL_INFO_BUF, &mvdcmd ) == FALSE)
2239 {
2240 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_VOL_INFO_BUF ) );
2241 }
2242 return;
2243 }
2244
2245 //------------------------------------------------------------------------------
2246 /// Set frame info buffer address to MVD
2247 /// @param -u32addr \b IN : start address
2248 //------------------------------------------------------------------------------
HAL_MVD_SetFrameInfoBufferAddr(MS_U8 u8Idx,MS_VIRT u32addr)2249 void HAL_MVD_SetFrameInfoBufferAddr (MS_U8 u8Idx, MS_VIRT u32addr )
2250 {
2251 MVD_CmdArg mvdcmd;
2252
2253 MS_ASSERT((u32addr%8)==0);
2254 u32addr >>= 3;
2255
2256 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2257 if (HAL_MVD_MVDCommand( CMD_FRAME_INFO_BUF, &mvdcmd ) == FALSE)
2258 {
2259 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FRAME_INFO_BUF ) );
2260 }
2261 return;
2262 }
2263
2264 //------------------------------------------------------------------------------
2265 /// Set IAP buffer address to MVD
2266 /// @param -u32addr \b IN : start address
2267 //------------------------------------------------------------------------------
HAL_MVD_SetIAPBufferAddr(MS_U8 u8Idx,MS_VIRT u32addr)2268 void HAL_MVD_SetIAPBufferAddr (MS_U8 u8Idx, MS_VIRT u32addr )
2269 {
2270 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
2271 MVD_CmdArg mvdcmd;
2272 MS_ASSERT((u32addr%8192)==0);
2273 u32addr >>= 13;
2274
2275 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2276 mvdcmd.Arg4 = pstMemCfg->u8FBMiuSel;
2277 if (HAL_MVD_MVDCommand( CMD_IAP_BUF_START, &mvdcmd ) == FALSE)
2278 {
2279 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_IAP_BUF_START ) );
2280 }
2281 return;
2282 }
2283
2284 //------------------------------------------------------------------------------
2285 /// Set Data Partition buffer address to MVD
2286 /// @param -u32addr \b IN : start address
2287 //------------------------------------------------------------------------------
HAL_MVD_SetDPBufferAddr(MS_U8 u8Idx,MS_VIRT u32addr)2288 void HAL_MVD_SetDPBufferAddr (MS_U8 u8Idx, MS_VIRT u32addr )
2289 {
2290 MVD_CmdArg mvdcmd;
2291 MS_ASSERT((u32addr%8)==0);
2292 u32addr >>= 3;
2293
2294 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2295 if (HAL_MVD_MVDCommand( CMD_DP_BUF_START, &mvdcmd ) == FALSE)
2296 {
2297 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DP_BUF_START ) );
2298 }
2299 return;
2300 }
2301
2302 //------------------------------------------------------------------------------
2303 /// Set Motion Vector buffer address to MVD
2304 /// @param -u32addr \b IN : start address
2305 //------------------------------------------------------------------------------
HAL_MVD_SetMVBufferAddr(MS_U8 u8Idx,MS_VIRT u32addr)2306 void HAL_MVD_SetMVBufferAddr (MS_U8 u8Idx, MS_VIRT u32addr )
2307 {
2308 MVD_CmdArg mvdcmd;
2309 MS_ASSERT((u32addr%2048)==0);
2310 u32addr >>= 3;
2311
2312 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2313 if (HAL_MVD_MVDCommand( CMD_MV_BUF_START, &mvdcmd ) == FALSE)
2314 {
2315 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_MV_BUF_START ) );
2316 }
2317 return;
2318 }
2319
_MVD_SetUserDataBufStart(MS_U8 u8Idx,MS_VIRT u32addr,MS_U8 u8arg3)2320 static void _MVD_SetUserDataBufStart(MS_U8 u8Idx, MS_VIRT u32addr, MS_U8 u8arg3)
2321 {
2322 MVD_CmdArg mvdcmd;
2323
2324 MS_ASSERT((u32addr%8)==0);
2325 u32addr >>= 3;
2326 MVD_DEBUGINFO(printf("%s add=0x%lx arg3=0x%x\n", __FUNCTION__, (unsigned long)u32addr, u8arg3));
2327
2328 SETUP_CMDARG(mvdcmd);
2329 mvdcmd.Arg0 = L_WORD(u32addr);
2330 mvdcmd.Arg1 = H_WORD(u32addr);
2331 mvdcmd.Arg2 = L_DWORD(u32addr);
2332 mvdcmd.Arg4 = H_DWORD(u32addr);
2333 mvdcmd.Arg3 = u8arg3;
2334 SET_DECNUM(mvdcmd, u8Idx);
2335 if (HAL_MVD_MVDCommand( CMD_USER_BUF_START, &mvdcmd ) == FALSE)
2336 {
2337 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_USER_BUF_START ) );
2338 return;
2339 }
2340 return;
2341 }
2342
_MVD_SetUserDataBufSize(MS_U8 u8Idx,MS_U32 u32size,MS_U8 u8arg3)2343 static void _MVD_SetUserDataBufSize(MS_U8 u8Idx, MS_U32 u32size, MS_U8 u8arg3)
2344 {
2345 MVD_CmdArg mvdcmd;
2346
2347 MS_ASSERT((u32size%8)==0);
2348 u32size >>= 3;
2349 MVD_DEBUGINFO(printf("%s add=0x%x arg3=0x%x\n", __FUNCTION__, u32size, u8arg3));
2350
2351 SETUP_CMDARG(mvdcmd);
2352 mvdcmd.Arg0 = L_WORD(u32size);
2353 mvdcmd.Arg1 = H_WORD(u32size);
2354 mvdcmd.Arg2 = L_DWORD(u32size);
2355 mvdcmd.Arg4 = H_DWORD(u32size);
2356 mvdcmd.Arg3 = u8arg3;
2357 if(mvdcmd.Arg3 <= 1) //mean 608 and 708 in MM RVU
2358 {
2359 mvdcmd.Arg2 = 7;//ntsc1+ntsc2+atsc
2360 mvdcmd.Arg4 = 0;
2361 }
2362 SET_DECNUM(mvdcmd, u8Idx);
2363 if (HAL_MVD_MVDCommand( CMD_USER_BUF_SIZE, &mvdcmd ) == FALSE)
2364 {
2365 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_USER_BUF_SIZE ) );
2366 return;
2367 }
2368 return;
2369 }
2370
2371 //------------------------------------------------------------------------------
2372 /// Set user data buffer address to MVD
2373 /// @param -u32addr \b IN : start address
2374 //------------------------------------------------------------------------------
HAL_MVD_SetUserDataBuf(MS_U8 u8Idx,MS_VIRT u32addr,MS_U32 u32size)2375 void HAL_MVD_SetUserDataBuf(MS_U8 u8Idx, MS_VIRT u32addr, MS_U32 u32size)
2376 {
2377 MS_U8 u8ccType = 0;
2378
2379 MS_ASSERT((u32addr%8)==0);
2380 MS_ASSERT((u32size%8)==0);
2381 #ifdef REDLION_LINUX_KERNEL_ENVI
2382 u8ccType = 2;
2383 #elif defined(MVD_SUPPORT_X4_CC)
2384 u8ccType = 4; //display order
2385 #else
2386 u8ccType = 2;// 2 for testing 0;
2387 #endif
2388
2389 #if defined(MVD_SUPPORT_X4_CC)
2390 //set decoding buffer address
2391 _MVD_SetUserDataBufStart(u8Idx, u32addr+u32size, 3);
2392 #endif
2393
2394 //set CC output buffer address
2395 _MVD_SetUserDataBufStart(u8Idx, u32addr, u8ccType);
2396
2397 #if defined(MVD_SUPPORT_X4_CC)
2398 //set decoding buffer size
2399 _MVD_SetUserDataBufSize(u8Idx, u32size, 3);
2400 #endif
2401
2402 //set CC output buffer size
2403 _MVD_SetUserDataBufSize(u8Idx, u32size, u8ccType);
2404
2405 return;
2406 }
2407
HAL_MVD_SetSLQTblBufStartEnd(MS_U8 u8Idx,MS_VIRT u32start,MS_VIRT u32end)2408 void HAL_MVD_SetSLQTblBufStartEnd(MS_U8 u8Idx, MS_VIRT u32start, MS_VIRT u32end)
2409 {
2410 MVD_CmdArg mvdcmd;
2411 MS_U32 u32val = u32end>>3;
2412 MVD_DEBUGINFO(printf("%s st=0x%lx end=0x%lx\n", __FUNCTION__, (unsigned long)u32start, (unsigned long)u32end));
2413
2414 SET_CMDARG(mvdcmd, u32val, u8Idx);
2415 if (HAL_MVD_MVDCommand( CMD_SLQ_TBL_BUF_END, &mvdcmd ) == FALSE)
2416 {
2417 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLQ_TBL_BUF_END ) );
2418 return;
2419 }
2420
2421 u32val = (u32start)>>3;
2422 SET_CMDARG(mvdcmd, u32val, u8Idx);
2423 if (HAL_MVD_MVDCommand( CMD_SLQ_TBL_BUF_START, &mvdcmd ) == FALSE)
2424 {
2425 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLQ_TBL_BUF_START ) );
2426 return;
2427 }
2428
2429 MVD_DEBUGINFO(printf("%s st=0x%lx end=0x%lx OK!!!\n", __FUNCTION__, (unsigned long)u32start, (unsigned long)u32end));
2430 return;
2431 }
2432
2433 //------------------------------------------------------------------------------
2434 /// Issue StepDisplay command.
2435 /// @return -TRUE for success; FALSE for failure.
2436 //------------------------------------------------------------------------------
HAL_MVD_StepDisp(MS_U8 u8Idx)2437 MS_BOOL HAL_MVD_StepDisp(MS_U8 u8Idx)
2438 {
2439 MVD_CmdArg mvdcmd;
2440
2441 MVD_SetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_STEP_DISP_DONE, sizeof(MS_U8), 0);
2442
2443 SETUP_CMDARG(mvdcmd);
2444 SET_DECNUM(mvdcmd, u8Idx);
2445 SET_CMD_RET_FALSE(CMD_STEP_DISP_DECODE_ONE, &mvdcmd);
2446 if (HAL_MVD_Resume(u8Idx) == FALSE)
2447 {
2448 MVD_DEBUGERROR( printf( "Command: HAL_MVD_Resume fail!!\r\n" ) );
2449 return FALSE;
2450 }
2451
2452 return TRUE;
2453 }
2454
2455 //------------------------------------------------------------------------------
2456 /// Get ES read address for TS file mode.
2457 /// @return ES read address
2458 //------------------------------------------------------------------------------
HAL_MVD_GetTsFileESReadPtr(MS_U8 u8Idx)2459 MS_VIRT HAL_MVD_GetTsFileESReadPtr(MS_U8 u8Idx)
2460 {
2461 MS_VIRT u32Add = 0;
2462 MVD_CmdArg mvdcmd;
2463
2464 SETUP_CMDARG(mvdcmd);
2465 mvdcmd.Arg0 = 2; //ES diff
2466 SET_DECNUM(mvdcmd, u8Idx);
2467 if (HAL_MVD_MVDCommand( CMD_PARSER_READ_POSITION, &mvdcmd ) == TRUE)
2468 {
2469 //in order to latch the newest parser status
2470 //u32Diff = (((MS_U32)mvdcmd.Arg3) <<24) | (((MS_U32)mvdcmd.Arg2) <<16) |
2471 // (((MS_U32)mvdcmd.Arg1) << 8) | (((MS_U32)mvdcmd.Arg0));
2472 }
2473 else
2474 {
2475 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\n", CMD_PARSER_READ_POSITION) );
2476 }
2477
2478 SETUP_CMDARG(mvdcmd);
2479 mvdcmd.Arg0 = 1;
2480 SET_DECNUM(mvdcmd, u8Idx);
2481 if (HAL_MVD_MVDCommand( CMD_PARSER_READ_POSITION, &mvdcmd ) == TRUE)
2482 {
2483 u32Add = (((MS_U32)mvdcmd.Arg3) <<24) |
2484 (((MS_U32)mvdcmd.Arg2) <<16) |
2485 (((MS_U32)mvdcmd.Arg1) << 8) |
2486 (((MS_U32)mvdcmd.Arg0));
2487 }
2488 else
2489 {
2490 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\n", CMD_PARSER_READ_POSITION) );
2491 }
2492
2493 return (u32Add*8);
2494 }
2495
2496 //------------------------------------------------------------------------------
2497 /// Get ES write address for TS file mode.
2498 /// @return ES write address
2499 //------------------------------------------------------------------------------
HAL_MVD_GetTsFileESWritePtr(MS_U8 u8Idx)2500 MS_VIRT HAL_MVD_GetTsFileESWritePtr(MS_U8 u8Idx)
2501 {
2502 MS_VIRT u32Diff = 0;
2503 MS_VIRT u32WrPtr = 0;
2504 MVD_CmdArg mvdcmd;
2505 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
2506 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
2507
2508 SETUP_CMDARG(mvdcmd);
2509 mvdcmd.Arg0 = 2; //ES diff
2510 SET_DECNUM(mvdcmd, u8Idx);
2511 if (HAL_MVD_MVDCommand( CMD_PARSER_READ_POSITION, &mvdcmd ) == TRUE)
2512 {
2513 u32Diff = (((MS_U32)mvdcmd.Arg3) <<24) | (((MS_U32)mvdcmd.Arg2) <<16) |
2514 (((MS_U32)mvdcmd.Arg1) << 8) | (((MS_U32)mvdcmd.Arg0));
2515 }
2516 else
2517 {
2518 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\n", CMD_PARSER_READ_POSITION) );
2519 }
2520
2521 u32WrPtr = u32Diff*8 + HAL_MVD_GetTsFileESReadPtr(u8Idx);
2522 if (u32WrPtr > pstSlqTblInfo->u32ESBuffEnd)
2523 {
2524 MVD_DEBUGINFO(printf("ES wrapping Wr=0x%lx ==> ", (unsigned long)u32WrPtr));
2525 u32WrPtr -= pstMemCfg->u32BSSize;
2526 MVD_DEBUGINFO(printf("0x%lx\n", (unsigned long)u32WrPtr));
2527 }
2528 return u32WrPtr;
2529 }
2530
2531 //------------------------------------------------------------------------------
2532 /// Enable/Disable firmware to show the last frame.
2533 /// @return -TRUE for success; FALSE for failure.
2534 //------------------------------------------------------------------------------
HAL_MVD_EnableLastFrameShow(MS_U8 u8Idx,MS_BOOL bEnable)2535 MS_BOOL HAL_MVD_EnableLastFrameShow(MS_U8 u8Idx, MS_BOOL bEnable)
2536 {
2537 MVD_CmdArg mvdcmd;
2538 MVD_SrcMode curSrcMode = HAL_MVD_GetSrcMode(u8Idx);
2539 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
2540 MS_VIRT* pu32FileEndPtr = &pstSlqTblInfo->u32FileEndPtr;
2541
2542 if (E_MVD_SLQ_TBL_MODE == curSrcMode)
2543 {
2544 #if SLQ_NEW_PUSH
2545 if (pstSlqTblInfo->pSlqStatus->bSlqCtrlBit)
2546 {
2547 pstSlqTblInfo->pDrvSlqTbl->u32WrPtr = pstSlqTblInfo->pSlqStatus->u32VaildWptrAddr + SLQ_ENTRY_LEN;
2548 }
2549 #endif //
2550 //save current writePtr
2551 if (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr != pstSlqTblInfo->pDrvSlqTbl->u32EndAdd)
2552 {
2553 *pu32FileEndPtr = pstSlqTblInfo->pDrvSlqTbl->u32WrPtr;
2554 }
2555 else
2556 {
2557 *pu32FileEndPtr = pstSlqTblInfo->pDrvSlqTbl->u32StAdd;
2558 }
2559 MVD_DEBUGINFO(printf("fe=%lx, rd=%lx, wr=%lx\n", (unsigned long)*pu32FileEndPtr,
2560 (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32RdPtr, (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32WrPtr));
2561 }
2562
2563 SETUP_CMDARG(mvdcmd);
2564 mvdcmd.Arg0 = bEnable;
2565 SET_DECNUM(mvdcmd, u8Idx);
2566 SET_CMD_RET_FALSE(CMD_ENABLE_LAST_FRAME_SHOW, &mvdcmd);
2567 return TRUE;
2568 }
2569
2570
HAL_MVD_SlqTblRst(MS_U8 u8Idx)2571 MS_BOOL HAL_MVD_SlqTblRst(MS_U8 u8Idx)
2572 {
2573 MVD_CmdArg mvdcmd;
2574 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
2575
2576 SETUP_CMDARG(mvdcmd);
2577 SET_DECNUM(mvdcmd, u8Idx);
2578 SET_CMD_RET_FALSE(CMD_VC1_HW_SLQ_RESET, &mvdcmd);
2579 pstSlqTblInfo->bEnSlqTblHkCtrl = FALSE;
2580 return TRUE;
2581 }
2582
HAL_MVD_SeekToPTS(MS_U8 u8Idx,MS_U32 u32Pts)2583 MS_BOOL HAL_MVD_SeekToPTS(MS_U8 u8Idx, MS_U32 u32Pts)
2584 {
2585 MVD_CmdArg mvdcmd;
2586
2587 SET_CMDARG(mvdcmd, u32Pts, u8Idx);
2588 SET_CMD_RET_FALSE(CMD_STEP_TO_PTS, &mvdcmd);
2589
2590 if (HAL_MVD_Resume(u8Idx) == FALSE)
2591 {
2592 MVD_DEBUGERROR( printf( "Command: HAL_MVD_Resume fail!!\r\n" ) );
2593 return FALSE;
2594 }
2595 return TRUE;
2596 }
2597
HAL_MVD_SkipToPTS(MS_U8 u8Idx,MS_U32 u32Pts)2598 MS_BOOL HAL_MVD_SkipToPTS(MS_U8 u8Idx, MS_U32 u32Pts)
2599 {
2600 MVD_CmdArg mvdcmd;
2601
2602 SET_CMDARG(mvdcmd, u32Pts, u8Idx);
2603 SET_CMD_RET_FALSE(CMD_SKIP_TO_PTS, &mvdcmd);
2604
2605 if (HAL_MVD_Resume(u8Idx) == FALSE)
2606 {
2607 MVD_DEBUGERROR( printf( "Command: HAL_MVD_Resume fail!!\r\n" ) );
2608 return FALSE;
2609 }
2610 return TRUE;
2611 }
2612
HAL_MVD_TrickPlay(MS_U8 u8Idx,MVD_TrickDec trickDec,MS_U8 u8DispDuration)2613 MS_BOOL HAL_MVD_TrickPlay(MS_U8 u8Idx, MVD_TrickDec trickDec, MS_U8 u8DispDuration)
2614 {
2615 MVD_CmdArg mvdcmd;
2616 MS_U8 u8DecType;
2617
2618 switch (trickDec)
2619 {
2620 case E_MVD_TRICK_DEC_ALL:
2621 u8DecType = 0;
2622 break;
2623 case E_MVD_TRICK_DEC_I:
2624 u8DecType = 1;
2625 break;
2626 case E_MVD_TRICK_DEC_IP:
2627 u8DecType = 2;
2628 break;
2629 default:
2630 return FALSE;
2631 break;
2632 }
2633
2634 SETUP_CMDARG(mvdcmd);
2635 mvdcmd.Arg0 = u8DecType;
2636 mvdcmd.Arg1 = u8DispDuration;
2637 SET_DECNUM(mvdcmd, u8Idx);
2638 SET_CMD_RET_FALSE(CMD_FAST_SLOW, &mvdcmd);
2639
2640 pMVDHalContext->stCtrlCfg[u8Idx].eTrickMode = trickDec;
2641 return TRUE;
2642 }
2643
HAL_MVD_FlushDisplayBuf(MS_U8 u8Idx)2644 MS_BOOL HAL_MVD_FlushDisplayBuf(MS_U8 u8Idx)
2645 {
2646 #define STOP_TIMEOUT 500 //ms
2647 MS_U32 u32StartTime = 0;
2648
2649 HAL_MVD_ResetHandShake(u8Idx, MVD_HANDSHAKE_FLUSHQUEUE_COMMAND);
2650 MVD_CmdArg mvdcmd;
2651 SETUP_CMDARG(mvdcmd);
2652 SET_DECNUM(mvdcmd, u8Idx);
2653 SET_CMD_RET_FALSE(CMD_FLUSH_DISP_QUEUE, &mvdcmd);
2654
2655 u32StartTime = HAL_MVD_GetTime();
2656
2657 while(!HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_FLUSHQUEUE_COMMAND))
2658 {
2659 if ((HAL_MVD_GetTime()-u32StartTime)>STOP_TIMEOUT)
2660 {
2661 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail timeout!!\r\n", CMD_FLUSH_DISP_QUEUE ) );
2662 break;
2663 }
2664 }
2665
2666 return TRUE;
2667 }
2668
2669
HAL_MVD_SetFileModeAVSync(MS_U8 u8Idx,MVD_TIMESTAMP_TYPE eSyncMode)2670 MS_BOOL HAL_MVD_SetFileModeAVSync(MS_U8 u8Idx, MVD_TIMESTAMP_TYPE eSyncMode)
2671 {
2672 MVD_CmdArg mvdcmd;
2673 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
2674
2675 pstCtrlCfg->eFileSyncMode = eSyncMode;
2676 MVD_DEBUGINFO(printf("%s eSyncMode=%d\n", __FUNCTION__, eSyncMode));
2677 SETUP_CMDARG(mvdcmd);
2678 switch (eSyncMode)
2679 {
2680 case E_MVD_TIMESTAMP_PTS:
2681 case E_MVD_TIMESTAMP_PTS_RVU:
2682 mvdcmd.Arg0 = FILE_PTS_MODE;
2683 break;
2684
2685 case E_MVD_TIMESTAMP_DTS:
2686 case E_MVD_TIMESTAMP_DTS_RVU:
2687 mvdcmd.Arg0 = FILE_DTS_MODE;
2688 break;
2689 case E_MVD_TIMESTAMP_NEW_STS:
2690 mvdcmd.Arg0 = FILE_STS_MODE;
2691 break;
2692 case E_MVD_TIMESTAMP_FREERUN:
2693 default:
2694 mvdcmd.Arg0 = NONE_FILE_MODE; //Freerun
2695 break;
2696 }
2697 SET_DECNUM(mvdcmd, u8Idx);
2698 SET_CMD_RET_FALSE(CMD_ENABLE_FILE_SYNC, &mvdcmd);
2699
2700 SETUP_CMDARG(mvdcmd);
2701 switch (eSyncMode) //for set RVU mode
2702 {
2703 case E_MVD_TIMESTAMP_PTS_RVU:
2704 mvdcmd.Arg0 = FILE_PTS_MODE;
2705 break;
2706 case E_MVD_TIMESTAMP_DTS_RVU:
2707 mvdcmd.Arg0 = FILE_DTS_MODE;
2708 break;
2709 case E_MVD_TIMESTAMP_FREERUN:
2710 default:
2711 mvdcmd.Arg0 = 0xFF;
2712 break;
2713 }
2714 SET_DECNUM(mvdcmd, u8Idx);
2715 SET_CMD_RET_FALSE(CMD_RVU_EN, &mvdcmd);
2716 return TRUE;
2717 }
2718
2719
2720
2721
2722 //------------------------------------------------------------------------------
2723 /// Set the start address of PTS table used for SLQ table link mode.
2724 /// @return -TRUE for success; FALSE for failure.
2725 //------------------------------------------------------------------------------
HAL_MVD_SetPtsTblAddr(MS_U8 u8Idx,MS_VIRT u32addr)2726 MS_BOOL HAL_MVD_SetPtsTblAddr(MS_U8 u8Idx, MS_VIRT u32addr)
2727 {
2728 MVD_CmdArg mvdcmd;
2729
2730 MS_ASSERT((u32addr%8)==0);
2731 u32addr >>= 3;
2732
2733 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2734 SET_CMD_RET_FALSE(CMD_PTS_TBL_START, &mvdcmd);
2735 return TRUE;
2736 }
2737
HAL_MVD_SkipToIFrame(MS_U8 u8Idx)2738 MS_BOOL HAL_MVD_SkipToIFrame(MS_U8 u8Idx)
2739 {
2740 MVD_CmdArg mvdcmd;
2741 SETUP_CMDARG(mvdcmd);
2742 SET_DECNUM(mvdcmd, u8Idx);
2743 SET_CMD_RET_FALSE(CMD_START_DEC_STRICT, &mvdcmd);
2744 return TRUE;
2745 }
2746
2747 //Map driver FRC (Frame rate conversion) mode to firmware's.
HAL_MVD_MapFrcMode(MVD_FrcMode eFrcMode)2748 MS_U8 HAL_MVD_MapFrcMode(MVD_FrcMode eFrcMode)
2749 {
2750 MS_U8 frcMode = 0xf;
2751 switch (eFrcMode)
2752 {
2753 case E_MVD_FRC_NORMAL:
2754 frcMode = FrcNormal;
2755 break;
2756 case E_MVD_FRC_DISP_TWICE:
2757 frcMode = FrcDisplayTwice;
2758 break;
2759 case E_MVD_FRC_3_2_PULLDOWN: //film 24 -> 50i
2760 frcMode = Frc32Pulldown;
2761 break;
2762 case E_MVD_FRC_PAL_TO_NTSC:
2763 frcMode = FrcPALtoNTSC;
2764 break;
2765 case E_MVD_FRC_NTSC_TO_PAL:
2766 frcMode = FrcNTSCtoPAL;
2767 break;
2768 case E_MVD_FRC_DISP_ONEFIELD:
2769 frcMode = FrcShowOneFiled;
2770 break;
2771 default:
2772 break;
2773 }
2774 return frcMode;
2775 }
2776
HAL_MVD_DispCtrl(MS_U8 u8Idx,MS_BOOL bDecOrder,MS_BOOL bDropErr,MS_BOOL bDropDisp,MVD_FrcMode eFrcMode)2777 MS_BOOL HAL_MVD_DispCtrl(MS_U8 u8Idx, MS_BOOL bDecOrder, MS_BOOL bDropErr, MS_BOOL bDropDisp, MVD_FrcMode eFrcMode)
2778 {
2779 MVD_CmdArg mvdcmd;
2780 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
2781 MS_BOOL* pbDropErrFrm = &pstCtrlCfg->bDropErrFrm;
2782
2783 SETUP_CMDARG(mvdcmd);
2784 mvdcmd.Arg0 = (MS_U8)bDecOrder;
2785 mvdcmd.Arg1 = (MS_U8)bDropErr;
2786 mvdcmd.Arg2 = (MS_U8)bDropDisp;
2787 mvdcmd.Arg3 = HAL_MVD_MapFrcMode(eFrcMode);
2788 SET_DECNUM(mvdcmd, u8Idx);
2789 SET_CMD_RET_FALSE(CMD_DISPLAY_CTL, &mvdcmd);
2790
2791 pstCtrlCfg->eFrcMode = eFrcMode;
2792
2793 if (*pbDropErrFrm != bDropErr)
2794 {
2795 MVD_DEBUGINFO( printf("bDropErrFrm(%d) != bDropErr(%d)\n", *pbDropErrFrm, bDropErr));
2796 *pbDropErrFrm = bDropErr;
2797 }
2798 pstCtrlCfg->bDropDispfrm = bDropDisp;
2799
2800 return TRUE;
2801 }
2802
2803
HAL_MVD_SkipData(MS_U8 u8Idx)2804 MS_BOOL HAL_MVD_SkipData(MS_U8 u8Idx)
2805 {
2806 MS_U32 u32TimeCnt = 0;
2807 MVD_CmdArg mvdcmd;
2808
2809 HAL_MVD_ResetHandShake(u8Idx, MVD_HANDSHAKE_SKIP_DATA);
2810 SETUP_CMDARG(mvdcmd);
2811 SET_DECNUM(mvdcmd, u8Idx);
2812 SET_CMD_RET_FALSE(CMD_SKIP_DATA, &mvdcmd);
2813
2814 u32TimeCnt = HAL_MVD_GetTime();
2815 while ((HAL_MVD_GetTime() - u32TimeCnt) < SKIP_DATA_TIMEOUT_MS)
2816 {
2817 if (HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_SKIP_DATA))
2818 {
2819 MVD_DEBUGINFO(printf("\nSkip data finished!\n"));
2820 break;
2821 }
2822 }
2823 MVD_DEBUGINFO(printf("====> %s (t1=%u t2=%u diff=%u)\n", __FUNCTION__,
2824 u32TimeCnt, HAL_MVD_GetTime(), (HAL_MVD_GetTime() - u32TimeCnt)));
2825 if (TRUE != HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_SKIP_DATA))
2826 {
2827 MVD_DEBUGINFO(printf("\n***** TS flush timeout *****\n\n"));
2828 return FALSE;
2829 }
2830
2831 return TRUE;
2832 }
2833
HAL_MVD_DispRepeatField(MS_U8 u8Idx,MS_BOOL bEnable)2834 MS_BOOL HAL_MVD_DispRepeatField(MS_U8 u8Idx, MS_BOOL bEnable)
2835 {
2836 MVD_CmdArg mvdcmd;
2837 SETUP_CMDARG(mvdcmd);
2838 mvdcmd.Arg0 = bEnable;
2839 SET_DECNUM(mvdcmd, u8Idx);
2840 SET_CMD_RET_FALSE(CMD_REPEAT_MODE, &mvdcmd);
2841 return TRUE;
2842 }
2843
2844 //------------------------------------------------------------------------------
2845 /// Pause display.
2846 /// @return -TRUE for success; FALSE for failure
2847 //------------------------------------------------------------------------------
HAL_MVD_PauseDisp(MS_U8 u8Idx)2848 MS_BOOL HAL_MVD_PauseDisp(MS_U8 u8Idx)
2849 {
2850 MS_BOOL bRst = TRUE;
2851 MVD_CmdArg mvdcmd;
2852
2853 SETUP_CMDARG(mvdcmd);
2854 mvdcmd.Arg0 = DISPLAY_PAUSE_ON;
2855 SET_DECNUM(mvdcmd, u8Idx);
2856 if (HAL_MVD_MVDCommand(CMD_DISPLAY_PAUSE, &mvdcmd)== FALSE)
2857 {
2858 MVD_DEBUGERROR( printf( "Command: 0x%x(ON) fail!!\r\n", CMD_DISPLAY_PAUSE) );
2859 bRst = FALSE;
2860 }
2861 return bRst;
2862 }
2863
2864 //------------------------------------------------------------------------------
2865 /// Issue Pause command.
2866 /// @return -TRUE for success; FALSE for failure
2867 //------------------------------------------------------------------------------
HAL_MVD_Resume(MS_U8 u8Idx)2868 MS_BOOL HAL_MVD_Resume(MS_U8 u8Idx)
2869 {
2870 MS_BOOL bRst = TRUE;
2871 MVD_CmdArg mvdcmd;
2872
2873 SETUP_CMDARG(mvdcmd);
2874 mvdcmd.Arg0 = DISPLAY_PAUSE_OFF;
2875 SET_DECNUM(mvdcmd, u8Idx);
2876 if (HAL_MVD_MVDCommand(CMD_DISPLAY_PAUSE, &mvdcmd)== FALSE)
2877 {
2878 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DISPLAY_PAUSE) );
2879 bRst = FALSE;
2880 }
2881 return bRst;
2882 }
2883
HAL_MVD_Play(MS_U8 u8Idx)2884 MS_BOOL HAL_MVD_Play(MS_U8 u8Idx)
2885 {
2886 MVD_CmdArg mvdcmd;
2887 SETUP_CMDARG(mvdcmd);
2888 mvdcmd.Arg0 = 1;
2889 SET_DECNUM(mvdcmd, u8Idx);
2890 SET_CMD_RET_FALSE(CMD_DIU_WIDTH_ALIGN, &mvdcmd);
2891
2892 SETUP_CMDARG(mvdcmd);
2893 SET_DECNUM(mvdcmd, u8Idx);
2894 SET_CMD_RET_FALSE(CMD_PLAY, &mvdcmd);
2895
2896 if (HAL_MVD_Resume(u8Idx) == FALSE)
2897 {
2898 MVD_DEBUGERROR( printf( "Command: HAL_MVD_Resume fail!!\r\n" ) );
2899 return FALSE;
2900 }
2901
2902 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
2903 pCtrlCfg->bDecodeIFrame = FALSE;
2904
2905 return TRUE;
2906 }
2907
2908 //------------------------------------------------------------------------------
2909 /// Set base address for ScalerInfo structure to f/w
2910 /// @param -u32addr \b IN : start address (units in byte)
2911 //------------------------------------------------------------------------------
HAL_MVD_SetScalerInfoAddr(MS_U8 u8Idx,MS_VIRT u32addr,MS_U8 u8Arg4)2912 MS_BOOL HAL_MVD_SetScalerInfoAddr(MS_U8 u8Idx, MS_VIRT u32addr,MS_U8 u8Arg4)
2913 {
2914 MVD_CmdArg mvdcmd;
2915
2916 MS_ASSERT((u32addr%8)==0);
2917 u32addr >>= 3;
2918
2919 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2920 mvdcmd.Arg4 = u8Arg4;
2921 SET_CMD_RET_FALSE(CMD_SCALER_INFO_BASE, &mvdcmd);
2922 return TRUE;
2923 }
2924
2925 //------------------------------------------------------------------------------
2926 /// Set the dynamic scale base address
2927 /// @return -TRUE for success; FALSE for failure.
2928 //------------------------------------------------------------------------------
HAL_MVD_SetDynamicScaleAddr(MS_U8 u8Idx,MS_VIRT u32addr)2929 MS_BOOL HAL_MVD_SetDynamicScaleAddr(MS_U8 u8Idx, MS_VIRT u32addr)
2930 {
2931 MVD_CmdArg mvdcmd;
2932
2933 MS_ASSERT((u32addr%8)==0);
2934 u32addr >>= 3;
2935
2936 SET_CMDARG(mvdcmd, u32addr, u8Idx);
2937 SET_CMD_RET_FALSE(CMD_DYNAMIC_SCALE_BASE, &mvdcmd);
2938 return TRUE;
2939 }
2940
2941 //------------------------------------------------------------------------------
2942 /// Set virtual box width/height to F/W.
2943 /// F/W will use the same w/h as scaler to calculate scaling factor.
2944 /// @return -TRUE for success; FALSE for failure.
2945 //------------------------------------------------------------------------------
HAL_MVD_SetVirtualBox(MS_U8 u8Idx,MS_U16 u16Width,MS_U16 u16Height)2946 MS_BOOL HAL_MVD_SetVirtualBox(MS_U8 u8Idx, MS_U16 u16Width, MS_U16 u16Height)
2947 {
2948 MVD_CmdArg mvdcmd;
2949
2950 SETUP_CMDARG(mvdcmd);
2951 mvdcmd.Arg0 = L_WORD(u16Width);
2952 mvdcmd.Arg1 = H_WORD(u16Width);
2953 mvdcmd.Arg2 = L_WORD(u16Height);
2954 mvdcmd.Arg3 = H_WORD(u16Height);
2955 SET_DECNUM(mvdcmd, u8Idx);
2956 SET_CMD_RET_FALSE(CMD_DS_VIRTUAL_BOX, &mvdcmd);
2957 return TRUE;
2958 }
2959
2960 //------------------------------------------------------------------------------
2961 /// Enable VC1 dynamic scaling
2962 /// @return -TRUE for success; FALSE for failure.
2963 //------------------------------------------------------------------------------
HAL_MVD_EnableDynamicScale(MS_U8 u8Idx,MS_U8 u8NewDS)2964 MS_BOOL HAL_MVD_EnableDynamicScale(MS_U8 u8Idx,MS_U8 u8NewDS)
2965 {
2966 MVD_CmdArg mvdcmd;
2967
2968 SETUP_CMDARG(mvdcmd);
2969 mvdcmd.Arg0 = TRUE;
2970 mvdcmd.Arg1 = u8NewDS;
2971 SET_DECNUM(mvdcmd, u8Idx);
2972 SET_CMD_RET_FALSE(CMD_ENABLE_DYNAMIC_SCALE, &mvdcmd);
2973 return TRUE;
2974 }
2975
2976
2977 //------------------------------------------------------------------------------
2978 /// Set blue screen
2979 /// @return -TRUE for success; FALSE for failure.
2980 //------------------------------------------------------------------------------
HAL_MVD_SetBlueScreen(MS_U8 u8Idx,MS_BOOL bEn)2981 MS_BOOL HAL_MVD_SetBlueScreen(MS_U8 u8Idx, MS_BOOL bEn)
2982 {
2983 MVD_CmdArg mvdcmd;
2984
2985 SETUP_CMDARG(mvdcmd);
2986 mvdcmd.Arg0 = bEn; //1 -> show MVOP frame color. 0 -> normal case.
2987 SET_DECNUM(mvdcmd, u8Idx);
2988 SET_CMD_RET_FALSE(CMD_FORCE_BLUE_SCREEN, &mvdcmd);
2989 return TRUE;
2990 }
2991
2992
HAL_MVD_SetFreezeDisp(MS_U8 u8Idx,MS_BOOL bEn)2993 MS_BOOL HAL_MVD_SetFreezeDisp(MS_U8 u8Idx, MS_BOOL bEn)
2994 {
2995 MVD_CmdArg mvdcmd;
2996
2997 SETUP_CMDARG(mvdcmd);
2998 mvdcmd.Arg0 = bEn;
2999 SET_DECNUM(mvdcmd, u8Idx);
3000 SET_CMD_RET_FALSE(CMD_FREEZE_DISP, &mvdcmd);
3001 return TRUE;
3002 }
3003
3004
3005 //------------------------------------------------------------------------------
3006 /// Set base address for DecFrameInfo structure to f/w
3007 /// @param -u32addr \b IN : start address (units in byte)
3008 //------------------------------------------------------------------------------
HAL_MVD_SetDecFrmInfoAddr(MS_U8 u8Idx,MS_VIRT u32addr)3009 void HAL_MVD_SetDecFrmInfoAddr(MS_U8 u8Idx, MS_VIRT u32addr)
3010 {
3011 MVD_CmdArg mvdcmd;
3012
3013 MS_ASSERT((u32addr%8)==0);
3014 u32addr >>= 3;
3015
3016 SET_CMDARG(mvdcmd, u32addr, u8Idx);
3017 if (HAL_MVD_MVDCommand( CMD_DEC_FRAME_INFO_BUF, &mvdcmd ) == FALSE)
3018 {
3019 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DEC_FRAME_INFO_BUF ) );
3020 }
3021 return;
3022 }
3023
3024 //Check if the task has interrupt
HAL_MVD_GetHasInt(MS_U8 u8Idx)3025 MS_BOOL HAL_MVD_GetHasInt(MS_U8 u8Idx)
3026 {
3027 MS_BOOL bHasInt = FALSE;
3028 MS_U32 u32IntCnt = 0;
3029 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
3030
3031 u32IntCnt = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_INT_CNT, sizeof(MS_U32));
3032 if (u32IntCnt != pCtrlCfg->u32IntCnt)
3033 {
3034 MVD_DEBUGINFO(printf("%s %d--> %d\n", __FUNCTION__, pCtrlCfg->u32IntCnt, u32IntCnt));
3035 bHasInt = TRUE;
3036 pCtrlCfg->u32IntCnt = u32IntCnt;
3037 }
3038 return bHasInt;
3039 }
3040
3041 #ifdef VDEC3
HAL_MVD_GetIntState(MS_U8 u8Idx)3042 MS_U32 HAL_MVD_GetIntState(MS_U8 u8Idx)
3043 {
3044 MS_U32 u32IntStat;
3045
3046 u32IntStat = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_INT_STAT, sizeof(MS_U32));
3047
3048 MVD_SetFWBuffData(u8Idx,FW_BUFF_FRMINFO,OFFSET_INT_STAT,sizeof(MS_U32),0);
3049
3050 return u32IntStat;
3051 }
3052 #else
HAL_MVD_GetIntState(MS_U8 u8Idx)3053 MS_U32 HAL_MVD_GetIntState(MS_U8 u8Idx)
3054 {
3055 MS_U32 u32IntStat = 0;
3056 MVD_CmdArg mvdcmd;
3057
3058 SETUP_CMDARG(mvdcmd);
3059 SET_DECNUM(mvdcmd, u8Idx);
3060 if (HAL_MVD_MVDCommand( CMD_GET_INT_STAT, &mvdcmd ) == TRUE)
3061 {
3062 u32IntStat = (((MS_U32)mvdcmd.Arg4) << 16) |
3063 (((MS_U32)mvdcmd.Arg3) << 8) |
3064 (((MS_U32)mvdcmd.Arg2));
3065 }
3066 else
3067 {
3068 if (FALSE == pMVDHalContext->bStopped[u8Idx])
3069 {
3070 MVD_DEBUGERROR(printf("Ctrl: 0x%x fail!!\n", CMD_GET_INT_STAT));
3071 }
3072 else
3073 {
3074 MVD_DEBUGINFO(printf("Cmd 0x%x normal timeout.\n", CMD_GET_INT_STAT));
3075 }
3076 }
3077
3078 return u32IntStat;
3079 }
3080
3081 #endif
3082
3083 ///// functions to check interrupt status /////
MVD_IntHasUsrDataDisp(MS_U32 u32IntStat)3084 MS_BOOL MVD_IntHasUsrDataDisp(MS_U32 u32IntStat)
3085 {
3086 return (((u32IntStat&INT_USER_DATA_DISP)==INT_USER_DATA_DISP) ? TRUE : FALSE);
3087 }
3088
MVD_IntHasUsrData(MS_U32 u32IntStat)3089 MS_BOOL MVD_IntHasUsrData(MS_U32 u32IntStat)
3090 {
3091 return (((u32IntStat&INT_USER_DATA)==INT_USER_DATA) ? TRUE : FALSE);
3092 }
3093
MVD_IntIsDispRdy(MS_U32 u32IntStat)3094 MS_BOOL MVD_IntIsDispRdy(MS_U32 u32IntStat)
3095 {
3096 return (((u32IntStat&INT_DISP_RDY)==INT_DISP_RDY) ? TRUE : FALSE);
3097 }
3098
MVD_IntHasSeqHdr(MS_U32 u32IntStat)3099 MS_BOOL MVD_IntHasSeqHdr(MS_U32 u32IntStat)
3100 {
3101 return (((u32IntStat&INT_SEQ_FOUND)==INT_SEQ_FOUND) ? TRUE : FALSE);
3102 }
3103
MVD_IntHasESDataInvalid(MS_U32 u32IntStat)3104 MS_BOOL MVD_IntHasESDataInvalid(MS_U32 u32IntStat)
3105 {
3106 return (((u32IntStat&INT_VES_VALID)==INT_VES_VALID) ? TRUE : FALSE);
3107 }
3108
MVD_IntHasDecodeErr(MS_U32 u32IntStat)3109 MS_BOOL MVD_IntHasDecodeErr(MS_U32 u32IntStat)
3110 {
3111 return (((u32IntStat&INT_DEC_ERR)==INT_DEC_ERR) ? TRUE : FALSE);
3112 }
3113 //INT_FIRST_FRAME means "1st frame be push to display queue & ready for display"
3114 //So, (1) in IPB or IP stream, that's I-frame
3115 // (2) in PB only stream, that's first P-frame
MVD_IntHas1stFrame(MS_U32 u32IntStat)3116 MS_BOOL MVD_IntHas1stFrame(MS_U32 u32IntStat)
3117 {
3118 return (((u32IntStat&INT_FIRST_FRAME)==INT_FIRST_FRAME) ? TRUE : FALSE);
3119 }
3120
3121 //INT_XC_LOW_DELAY
MVD_IntHasXcLowDelay(MS_U32 u32IntStat)3122 MS_BOOL MVD_IntHasXcLowDelay(MS_U32 u32IntStat)
3123 {
3124 //printf("MVD_IntHasXcLowDelay=%x \n ", u32IntStat);
3125 return (((u32IntStat&INT_XC_LOW_DELAY)==INT_XC_LOW_DELAY) ? TRUE : FALSE);
3126 }
3127
MVD_IntHasDecodeIframe(MS_U32 u32IntStat)3128 MS_BOOL MVD_IntHasDecodeIframe(MS_U32 u32IntStat)
3129 {
3130 return (((u32IntStat&INT_DEC_I)==INT_DEC_I) ? TRUE : FALSE);
3131 }
3132
3133
MVD_IntVSyncInt(MS_U32 u32IntStat)3134 MS_BOOL MVD_IntVSyncInt(MS_U32 u32IntStat)
3135 {
3136 return (((u32IntStat&INT_DISP_VSYNC)==INT_DISP_VSYNC) ? TRUE : FALSE);
3137 }
3138
MVD_IntDecOneFrmInt(MS_U32 u32IntStat)3139 MS_BOOL MVD_IntDecOneFrmInt(MS_U32 u32IntStat)
3140 {
3141 return (((u32IntStat&INT_DEC_DONE)==INT_DEC_DONE) ? TRUE : FALSE);
3142 }
3143
3144
MVD_GetSyncStat(MS_U8 u8Idx,MS_U8 u8ArgIdx)3145 static MS_U8 MVD_GetSyncStat(MS_U8 u8Idx, MS_U8 u8ArgIdx)
3146 {
3147 MS_U8 u8Val = 0xFF;
3148 MVD_CmdArg mvdcmd;
3149 SETUP_CMDARG(mvdcmd);
3150 SET_DECNUM(mvdcmd, u8Idx);
3151 if (HAL_MVD_MVDCommand( CMD_GET_SYNC_STAT, &mvdcmd ) == FALSE)
3152 {
3153 MVD_DEBUGERROR(printf("Ctrl: 0x%x fail!!\r\n", CMD_GET_SYNC_STAT));
3154 return 0xFF;
3155 }
3156 MVD_DEBUGINFO(printf("Sync On/Off %x, Done %x, Stat %x, diff=%d\n",
3157 mvdcmd.Arg0, mvdcmd.Arg1, mvdcmd.Arg2, (int)HAL_MVD_GetPtsStcDiff(u8Idx)));
3158
3159 if (0==u8ArgIdx)
3160 {
3161 u8Val = mvdcmd.Arg0; //On/Off
3162 }
3163 else if (1==u8ArgIdx)
3164 {
3165 u8Val = mvdcmd.Arg1; //Done
3166 }
3167 else if (2==u8ArgIdx)
3168 {
3169 u8Val = mvdcmd.Arg2; //Stat
3170 }
3171 return u8Val;
3172 }
3173
3174 //------------------------------------------------------------------------------
3175 /// Report avsync status
3176 /// avsync_status=avsync_done|(avsync_skip_picture<<1)|(avsync_repeat_picture<<2),
3177 /// 0 for free run
3178 //------------------------------------------------------------------------------
HAL_MVD_GetAVSyncStatus(MS_U8 u8Idx)3179 MS_U8 HAL_MVD_GetAVSyncStatus(MS_U8 u8Idx)
3180 {
3181 return MVD_GetSyncStat(u8Idx, 2);
3182 }
3183
HAL_MVD_SlqTblLoadWrPtr(MS_U8 u8Idx,MS_VIRT u32WrPtr)3184 void HAL_MVD_SlqTblLoadWrPtr(MS_U8 u8Idx, MS_VIRT u32WrPtr)
3185 {
3186 #if 1
3187 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
3188 MVD_CmdArg mvdcmd;
3189 MS_U16 u16Val = 0;
3190
3191 if (FALSE == pstSlqTblInfo->bEnSlqTblHkCtrl)
3192 {
3193 SETUP_CMDARG(mvdcmd);
3194 mvdcmd.Arg0 = 0x10;
3195 mvdcmd.Arg1 = 0x01;
3196 SET_DECNUM(mvdcmd, u8Idx);
3197 if (HAL_MVD_MVDCommand( CMD_RD_IO, &mvdcmd ) == FALSE)
3198 {
3199 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_RD_IO ) );
3200 return;
3201 }
3202 u16Val = (((MS_U32)mvdcmd.Arg2)) | ((MS_U32)mvdcmd.Arg3 << 8);
3203
3204 SETUP_CMDARG(mvdcmd);
3205 mvdcmd.Arg0 = 0x10;
3206 mvdcmd.Arg1 = 0x01;
3207 mvdcmd.Arg2 = u16Val & 0xff;
3208 mvdcmd.Arg3 = ((u16Val>>8 ) & 0xff) | 0x80;
3209 SET_DECNUM(mvdcmd, u8Idx);
3210 if (HAL_MVD_MVDCommand(CMD_WR_IO, &mvdcmd) == FALSE)
3211 {
3212 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_WR_IO ) );
3213 return;
3214 }
3215
3216 pstSlqTblInfo->bEnSlqTblHkCtrl = TRUE;
3217 //printf("@@@ OPEN HK.SLQ.CTRL!\n");
3218 }
3219 #endif
3220 OSAL_MVD_LockHwMutex();
3221
3222 HAL_MVD_RegWriteByte(MVD_SLQ_WADR0, (u32WrPtr & 0xff));
3223 HAL_MVD_RegWriteByte(MVD_SLQ_WADR1, ((u32WrPtr>>8 ) & 0xff));
3224 HAL_MVD_RegWriteByte(MVD_SLQ_WADR2, ((u32WrPtr>>16) & 0xff));
3225 HAL_MVD_RegWriteByte(MVD_SLQ_WADR3, ((u32WrPtr>>24) & 0x01));
3226 HAL_MVD_RegWriteBit(MVD_SLQCTRL, 1, MVD_SLQCTRL_WADR_RELOAD);
3227 HAL_MVD_RegWriteBit(MVD_SLQCTRL, 0, MVD_SLQCTRL_WADR_RELOAD);
3228
3229 OSAL_MVD_UnlockHwMutex();
3230 }
3231
HAL_MVD_SlqTblProbe(MVD_HKSLQ_CMD eCmd)3232 static MS_VIRT HAL_MVD_SlqTblProbe(MVD_HKSLQ_CMD eCmd)
3233 {
3234 MS_VIRT u32Cadr = 0;
3235 OSAL_MVD_LockHwMutex();
3236
3237 switch (eCmd)
3238 {
3239 case MVD_HKSLQ_GET_READPTR:
3240 HAL_MVD_RegWriteBit(MVD_SLQCTRL, 1, MVD_SLQCTRL_RADR_PROBE);
3241 HAL_MVD_RegWriteBit(MVD_SLQCTRL, 0, MVD_SLQCTRL_RADR_PROBE);
3242 break;
3243 case MVD_HKSLQ_GET_WRITEPTR:
3244 HAL_MVD_RegWriteBit(MVD_SLQCTRL, 1, MVD_SLQCTRL_WADR_PROBE);
3245 HAL_MVD_RegWriteBit(MVD_SLQCTRL, 0, MVD_SLQCTRL_WADR_PROBE);
3246 break;
3247 default:
3248 break;
3249 }
3250 u32Cadr = HAL_MVD_RegReadByte(MVD_SLQ_CADR0) |
3251 (HAL_MVD_RegReadByte(MVD_SLQ_CADR1) << 8) |
3252 (HAL_MVD_RegReadByte(MVD_SLQ_CADR2) <<16) |
3253 ((HAL_MVD_RegReadByte(MVD_SLQ_CADR3) & 0x01) <<24);
3254
3255 OSAL_MVD_UnlockHwMutex();
3256 return u32Cadr;
3257 }
3258
HAL_MVD_SlqTblProbeWrPtr(MS_U8 u8Idx)3259 MS_VIRT HAL_MVD_SlqTblProbeWrPtr(MS_U8 u8Idx)
3260 {
3261 return HAL_MVD_SlqTblProbe(MVD_HKSLQ_GET_WRITEPTR);
3262 }
3263
HAL_MVD_SlqTblProbeRdPtr(MS_U8 u8Idx)3264 MS_VIRT HAL_MVD_SlqTblProbeRdPtr(MS_U8 u8Idx)
3265 {
3266 return HAL_MVD_SlqTblProbe(MVD_HKSLQ_GET_READPTR);
3267 }
3268
3269 //------------------------------------------------------------------------------
3270 /// Set firmware as MStreamer mode
3271 /// @return -TRUE for success; FALSE for failure.
3272 //------------------------------------------------------------------------------
HAL_MVD_SetMStreamerMode(MS_U8 u8Idx,MS_U8 u8Mode)3273 MS_BOOL HAL_MVD_SetMStreamerMode(MS_U8 u8Idx, MS_U8 u8Mode)
3274 {
3275 MVD_CmdArg mvdcmd;
3276 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
3277
3278 SETUP_CMDARG(mvdcmd);
3279 mvdcmd.Arg0 = u8Mode; //1: enable, 0:disable MStreamer mode.
3280 SET_DECNUM(mvdcmd, u8Idx);
3281 SET_CMD_RET_FALSE(CMD_SET_MST_MODE, &mvdcmd);
3282
3283 pstCtrlCfg->u8MstMode = u8Mode;
3284 return TRUE;
3285 }
3286
3287 //------------------------------------------------------------------------------
3288 /// Set firmware as MStreamer mode (IP clip mode)
3289 /// @return -TRUE for success; FALSE for failure.
3290 //------------------------------------------------------------------------------
HAL_MVD_ShowDecodeOrder(MS_U8 u8Idx,MS_U8 u8Mode)3291 MS_BOOL HAL_MVD_ShowDecodeOrder(MS_U8 u8Idx, MS_U8 u8Mode)
3292 {
3293 MVD_CmdArg mvdcmd;
3294 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
3295
3296 SETUP_CMDARG(mvdcmd);
3297 mvdcmd.Arg0 = pstCtrlCfg->u8MstMode;
3298 mvdcmd.Arg1 = u8Mode;//a u8Mode; //1: clip mode, 0:normal mode.
3299 SET_DECNUM(mvdcmd, u8Idx);
3300 SET_CMD_RET_FALSE(CMD_SET_MST_MODE, &mvdcmd);
3301 return TRUE;
3302
3303 }
3304
HAL_MVD_IsMStreamerMode(MS_U8 u8Idx)3305 MS_BOOL HAL_MVD_IsMStreamerMode(MS_U8 u8Idx)
3306 {
3307 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
3308 return (MST_MODE_TRUE == pstCtrlCfg->u8MstMode);
3309 }
3310
HAL_MVD_FrameOpt(MS_U8 u8Idx,MS_U8 u8FrmIdx,MVD_FrmOpt eOpt)3311 MS_BOOL HAL_MVD_FrameOpt(MS_U8 u8Idx, MS_U8 u8FrmIdx, MVD_FrmOpt eOpt)
3312 {
3313 MVD_CmdArg mvdcmd;
3314
3315 SETUP_CMDARG(mvdcmd);
3316 mvdcmd.Arg0 = u8FrmIdx;
3317 mvdcmd.Arg1 = eOpt; // 0 = Flip, 1 = Release.
3318 MVD_DEBUGINFO(printf("FLIP_RELEASE_FRAME: idx=0x%x, opt=0x%x\n", u8FrmIdx, eOpt));
3319 SET_DECNUM(mvdcmd, u8Idx);
3320 SET_CMD_RET_FALSE(CMD_FLIP_RELEASE_FRAME, &mvdcmd);
3321
3322 return TRUE;
3323 }
3324
3325 //------------------------------------------------------------------------------
3326 /// Set firmware dynamic allocate FrameBuffer, now support MCU mode only
3327 /// @return -TRUE for success; FALSE for failure.
3328 //------------------------------------------------------------------------------
_MVD_SetDynamicAllocateFB(MS_U8 u8Idx,MS_BOOL bEnable)3329 MS_BOOL _MVD_SetDynamicAllocateFB(MS_U8 u8Idx,MS_BOOL bEnable)
3330 {
3331 MVD_CmdArg mvdcmd;
3332
3333 SETUP_CMDARG(mvdcmd);
3334 mvdcmd.Arg0 = 1-bEnable; //Arg0 : 0(enable) , 1(disable)
3335 SET_DECNUM(mvdcmd, u8Idx);
3336 if (HAL_MVD_MVDCommand( CMD_FIXED_FRAME_BUFFER, &mvdcmd ) == FALSE)
3337 {
3338 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FIXED_FRAME_BUFFER ) );
3339 return FALSE;
3340 }
3341
3342 return TRUE;
3343 }
3344
3345 //------------------------------------------------------------------------------
3346 /// Set firmware as MCU mode
3347 /// @return -TRUE for success; FALSE for failure.
3348 //------------------------------------------------------------------------------
HAL_MVD_SetMcuMode(MS_U8 u8Idx,MS_U8 u8Mode)3349 MS_BOOL HAL_MVD_SetMcuMode(MS_U8 u8Idx, MS_U8 u8Mode)
3350 {
3351 MVD_CmdArg mvdcmd;
3352 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
3353
3354 SETUP_CMDARG(mvdcmd);
3355 mvdcmd.Arg0 = u8Mode; //1: enable, 0:disable MCU
3356 SET_DECNUM(mvdcmd, u8Idx);
3357 SET_CMD_RET_FALSE(CMD_SET_MCU_MODE, &mvdcmd);
3358
3359 pstCtrlCfg->u8McuMode = u8Mode;
3360
3361 return TRUE;
3362 }
3363
HAL_MVD_IsMcuMode(MS_U8 u8Idx)3364 MS_BOOL HAL_MVD_IsMcuMode(MS_U8 u8Idx)
3365 {
3366 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
3367 return (TRUE == pstCtrlCfg->u8McuMode);
3368 }
3369
3370 //------------------------------------------------------------------------------
3371 /// Set firmware as ForceInterlace mode
3372 /// @return -TRUE for success; FALSE for failure.
3373 //------------------------------------------------------------------------------
HAL_MVD_ForceInterlaceMode(MS_U8 u8Idx,MS_U8 u8Mode)3374 MS_BOOL HAL_MVD_ForceInterlaceMode(MS_U8 u8Idx, MS_U8 u8Mode)
3375 {
3376 MVD_CmdArg mvdcmd;
3377
3378 SETUP_CMDARG(mvdcmd);
3379 mvdcmd.Arg0 = u8Mode; //1: enable, 0:disable
3380 mvdcmd.Arg1 = 0;
3381 SET_DECNUM(mvdcmd, u8Idx);
3382 SET_CMD_RET_FALSE(CMD_VC1_FORCE_INTLACE_DISP, &mvdcmd);
3383
3384 return TRUE;
3385 }
3386
3387 //------------------------------------------------------------------------------
3388 /// Set firmware as Progressive mode
3389 /// @return -TRUE for success; FALSE for failure.
3390 //------------------------------------------------------------------------------
HAL_MVD_ForceProgressiveMode(MS_U8 u8Idx,MS_U8 u8Mode)3391 MS_BOOL HAL_MVD_ForceProgressiveMode(MS_U8 u8Idx, MS_U8 u8Mode)
3392 {
3393 MVD_CmdArg mvdcmd;
3394
3395 SETUP_CMDARG(mvdcmd);
3396 mvdcmd.Arg0 = 0;
3397 mvdcmd.Arg1 = u8Mode; //1: enable, 0:disable
3398 SET_DECNUM(mvdcmd, u8Idx);
3399 SET_CMD_RET_FALSE(CMD_VC1_FORCE_INTLACE_DISP, &mvdcmd);
3400
3401 return TRUE;
3402 }
3403
3404 //------------------------------------------------------------------------------
3405 /// Inform firwmare that PTS is updated.
3406 /// @return -TRUE for success; FALSE for failure.
3407 //------------------------------------------------------------------------------
HAL_MVD_UpdatePts(MS_U8 u8Idx)3408 MS_BOOL HAL_MVD_UpdatePts(MS_U8 u8Idx)
3409 {
3410 MVD_CmdArg mvdcmd;
3411
3412 SETUP_CMDARG(mvdcmd);
3413 SET_DECNUM(mvdcmd, u8Idx);
3414 SET_CMD_RET_FALSE(CMD_SEND_UNI_PTS, &mvdcmd);
3415
3416 return TRUE;
3417 }
3418
3419
HAL_MVD_FrameCapture(MS_U8 u8Idx,MS_U8 u8FrmIdx,MS_BOOL bEnable)3420 MS_BOOL HAL_MVD_FrameCapture(MS_U8 u8Idx, MS_U8 u8FrmIdx, MS_BOOL bEnable)
3421 {
3422 MVD_CmdArg mvdcmd;
3423
3424 SETUP_CMDARG(mvdcmd);
3425 mvdcmd.Arg0 = bEnable; //0 or 1 to enable/disable the freeze function
3426 mvdcmd.Arg2 = u8FrmIdx; //specify the freezed frame index
3427 MVD_DEBUGINFO(printf("CAPTURE_FRAME: idx=0x%x, enable=0x%x\n", u8FrmIdx, bEnable));
3428 SET_DECNUM(mvdcmd, u8Idx);
3429 SET_CMD_RET_FALSE(CMD_ENABLE_FREEZE_PIC, &mvdcmd);
3430
3431 return TRUE;
3432 }
3433
3434 //------------------------------------------------------------------------------
3435 /// Set HW buffers' start address to MVD FW
3436 /// Return (the end address - 1)
3437 /// @param -u32Addr \b IN : start address (MIU offset)
3438 //------------------------------------------------------------------------------
HAL_MVD_SetHWBuffer(MS_U8 u8Idx,MS_VIRT u32Add)3439 MS_VIRT HAL_MVD_SetHWBuffer(MS_U8 u8Idx, MS_VIRT u32Add)
3440 {
3441 MS_VIRT tmpAdr;
3442
3443 MVD_DEBUGINFO(printf("====> %s u32Add = 0x%lx\n", __FUNCTION__, (unsigned long)u32Add));
3444 tmpAdr = (MemAlign(u32Add, MVD_FW_IAP_BUF_ALIGN));
3445 MVD_DEBUGINFO(printf("set MVD3_FW_IAP_BUF_ADR =%lx\n",(unsigned long)tmpAdr));
3446 HAL_MVD_SetIAPBufferAddr(u8Idx, tmpAdr);
3447 tmpAdr += MVD_FW_IAP_BUF_LEN;
3448
3449 tmpAdr = (MemAlign(tmpAdr, MVD_FW_DP_BUF_ALIGN));
3450 MVD_DEBUGINFO(printf("set MVD3_FW_DP_BUF_ADR=%lx\n",(unsigned long)tmpAdr));
3451 HAL_MVD_SetDPBufferAddr(u8Idx, tmpAdr);
3452 tmpAdr += MVD_FW_DP_BUF_LEN;
3453
3454 tmpAdr = (MemAlign(tmpAdr, MVD_FW_MV_BUF_ALIGN));
3455 MVD_DEBUGINFO(printf("set MVD3_FW_MV_BUF_ADR=%lx\n",(unsigned long)tmpAdr));
3456 HAL_MVD_SetMVBufferAddr(u8Idx, tmpAdr);
3457 tmpAdr += MVD_FW_MV_BUF_LEN;
3458 MVD_DEBUGINFO(printf("====> %s End of HW buffers = 0x%lx\n", __FUNCTION__, (unsigned long)tmpAdr));
3459
3460 return tmpAdr;
3461 }
3462
3463 //------------------------------------------------------------------------------
3464 /// Set the number of framebuffer
3465 /// @param -u8FrmNum \b IN : the number of framebuffer
3466 //------------------------------------------------------------------------------
HAL_MVD_SetFrameBuffNum(MS_U8 u8Idx,MS_U8 u8FrmNum,MS_U32 u32FBUsedSize)3467 void HAL_MVD_SetFrameBuffNum(MS_U8 u8Idx, MS_U8 u8FrmNum,MS_U32 u32FBUsedSize)
3468 {
3469 #define MVD_FBNUM_DEFAULT 4
3470 #define MVD_FBNUM_MIN MVD_FBNUM_DEFAULT
3471
3472 MVD_CmdArg mvdcmd;
3473
3474 MVD_DEBUGINFO(printf("%s u8FrmNum = %d\n", __FUNCTION__, u8FrmNum));
3475 if (u8FrmNum < MVD_FBNUM_MIN)
3476 {
3477 MVD_DEBUGINFO(printf("%s set u8FrmNum as %d instead of %d!\n",
3478 __FUNCTION__, MVD_FBNUM_MIN, u8FrmNum));
3479 u8FrmNum = MVD_FBNUM_MIN;
3480 }
3481 SETUP_CMDARG(mvdcmd);
3482 mvdcmd.Arg0 = u8FrmNum;
3483 mvdcmd.Arg1 = u32FBUsedSize&0xff;
3484 mvdcmd.Arg2 = (u32FBUsedSize>>8)&0xff;
3485 mvdcmd.Arg3 = (u32FBUsedSize>>16)&0xff;
3486 mvdcmd.Arg4 = (u32FBUsedSize>>24)&0xff;
3487 SET_DECNUM(mvdcmd, u8Idx);
3488 if (HAL_MVD_MVDCommand( CMD_FB_NUM, &mvdcmd ) == FALSE)
3489 {
3490 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FB_NUM ) );
3491 return;
3492 }
3493 return;
3494 }
3495
MVD_WriteFWBuffData(MS_U8 u8Idx,FW_BUFF_TYPE eBuffType,MS_U8 u8Offset,MS_U8 u8Size,MS_U32 u32Val)3496 static MS_BOOL MVD_WriteFWBuffData(MS_U8 u8Idx, FW_BUFF_TYPE eBuffType, MS_U8 u8Offset, MS_U8 u8Size, MS_U32 u32Val)
3497 {
3498 MS_BOOL bRet = FALSE;
3499 MS_VIRT u32BufStart = NULL;
3500 switch (eBuffType)
3501 {
3502 case FW_BUFF_VOLINFO: u32BufStart = GET_VOL_BUFFADD(u8Idx); break;
3503 case FW_BUFF_FRMINFO: u32BufStart = GET_FRMINFO_BUFFADD(u8Idx); break;
3504 case FW_BUFF_HDR: u32BufStart = GET_HDR_BUFFADD(u8Idx); break;
3505 case FW_BUFF_USRDATA: u32BufStart = GET_USRDATA_BUFFADD(u8Idx); break;
3506 case FW_BUFF_FWSLQTAB: u32BufStart = GET_SLQ_BUFFADD(u8Idx); break;
3507 case FW_BUFF_PTSTBL: u32BufStart = GET_PTSTBL_BUFFADD(u8Idx); break;
3508 case FW_BUFF_DS: u32BufStart = GET_DS_BUFFADD(u8Idx); break;
3509 case FW_BUFF_XCINFO: u32BufStart = GET_XCINFO_BUFFADD(u8Idx); break;
3510 case FW_BUFF_DECFRMINFO: u32BufStart = GET_DECFRMINFO_BUFFADD(u8Idx); break;
3511 default:
3512 break;
3513 }
3514 if (NULL == u32BufStart)
3515 {
3516 printf("%s err: u8Idx=0x%x, bufType=0x%x, offset=%d, size=%d\n",
3517 __FUNCTION__, u8Idx, eBuffType, u8Offset, u8Size);
3518 return bRet;
3519 }
3520
3521 if (u8Size == sizeof(MS_U8))
3522 {
3523 bRet = HAL_MVD_MemWriteByte(u32BufStart+u8Offset, (MS_U8)u32Val);
3524 }
3525 else if (u8Size == sizeof(MS_U32))
3526 {
3527 bRet = HAL_MVD_MemWrite4Byte(u32BufStart+u8Offset, u32Val);
3528 }
3529
3530 MVD_DEBUGINFO(printf("%s: u32Val=%d for u8Idx=0x%x, bufType=0x%x, offset=%d, size=%d\n",
3531 __FUNCTION__, u32Val, u8Idx, eBuffType, u8Offset, u8Size));
3532 return bRet;
3533 }
3534
3535 //================== Vol Info ==================//
HAL_MVD_GetBitsRate(MS_U8 u8Idx)3536 MS_U32 HAL_MVD_GetBitsRate(MS_U8 u8Idx)
3537 {
3538 //Ref 13818-2, this flag is unit of 400 bits/sec
3539 return MVD_GetFWBuffData(u8Idx, FW_BUFF_VOLINFO, OFFSET_BIT_RATE, sizeof(MS_U32))*400;
3540 }
3541
HAL_MVD_GetVideoRange(MS_U8 u8Idx)3542 MS_U8 HAL_MVD_GetVideoRange(MS_U8 u8Idx)
3543 {
3544 return (MS_U8)MVD_GetFWBuffData(u8Idx, FW_BUFF_VOLINFO, OFFSET_VIDEO_RANGE, sizeof(MS_U8));
3545 }
3546
HAL_MVD_GetLowDelayFlag(MS_U8 u8Idx)3547 MS_BOOL HAL_MVD_GetLowDelayFlag(MS_U8 u8Idx)
3548 {
3549 return (MS_BOOL)MVD_GetFWBuffData(u8Idx, FW_BUFF_VOLINFO, OFFSET_LOW_DELAY, sizeof(MS_U8));
3550 }
3551
HAL_MVD_GetIs32PullDown(MS_U8 u8Idx)3552 MS_BOOL HAL_MVD_GetIs32PullDown(MS_U8 u8Idx)
3553 {
3554 return (MS_BOOL)MVD_GetFWBuffData(u8Idx, FW_BUFF_VOLINFO, OFFSET_MPEG_FRC_MODE, sizeof(MS_U8));
3555 }
3556
HAL_MVD_GetIsDynScalingEnabled(MS_U8 u8Idx)3557 MS_BOOL HAL_MVD_GetIsDynScalingEnabled(MS_U8 u8Idx)
3558 {
3559 return (MS_BOOL)MVD_GetFWBuffData(u8Idx, FW_BUFF_VOLINFO, OFFSET_DS_ENABLE, sizeof(MS_U8));
3560 }
3561
HAL_MVD_Is1stFrmRdy(MS_U8 u8Idx)3562 MS_BOOL HAL_MVD_Is1stFrmRdy(MS_U8 u8Idx)
3563 {
3564 return (MS_BOOL)MVD_GetFWBuffData(u8Idx, FW_BUFF_VOLINFO, OFFSET_FIRST_DISPLAY, sizeof(MS_U8));
3565 }
3566
3567
3568 //================== FrameInfo ==================//
HAL_MVD_GetPicCounter(MS_U8 u8Idx)3569 MS_U32 HAL_MVD_GetPicCounter(MS_U8 u8Idx)
3570 {
3571 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_FRAME_COUNT, sizeof(MS_U32));
3572 }
3573
HAL_MVD_GetSkipPicCounter(MS_U8 u8Idx)3574 MS_U32 HAL_MVD_GetSkipPicCounter(MS_U8 u8Idx)
3575 {
3576 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SKIP_FRAME_COUNT, sizeof(MS_U32));
3577 }
3578
HAL_MVD_GetPicType(MS_U8 u8Idx)3579 MVD_PicType HAL_MVD_GetPicType(MS_U8 u8Idx)
3580 {
3581 MS_U32 picType = 0xff;
3582 MVD_PicType ret = E_MVD_PIC_UNKNOWN;
3583
3584 if (GET_FRMINFO_BUFFADD(u8Idx)==0)
3585 {
3586 MVD_DEBUGERROR(printf("%s error: pu8MVDGetFrameInfoBufStart=NULL\n", __FUNCTION__));
3587 return E_MVD_PIC_UNKNOWN;
3588 }
3589 picType = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PICTURE_TYPE, sizeof(MS_U32));
3590 switch (picType)
3591 {
3592 case 0:
3593 ret = E_MVD_PIC_I;
3594 break;
3595 case 1:
3596 ret = E_MVD_PIC_P;
3597 break;
3598 case 2:
3599 ret = E_MVD_PIC_B;
3600 break;
3601 default:
3602 break;
3603 }
3604 return ret;
3605 }
3606
HAL_MVD_GetPtsStcDiff(MS_U8 u8Idx)3607 MS_S32 HAL_MVD_GetPtsStcDiff(MS_U8 u8Idx)
3608 {
3609 return (MS_S32)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PTS_STC, sizeof(MS_S32));
3610 }
3611
HAL_MVD_GetDecodedFrameIdx(MS_U8 u8Idx)3612 MS_U8 HAL_MVD_GetDecodedFrameIdx(MS_U8 u8Idx)
3613 {
3614 return (MS_U8)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_FB_INDEX, sizeof(MS_U8));
3615 }
3616
HAL_MVD_GetVldErrCount(MS_U8 u8Idx)3617 MS_U32 HAL_MVD_GetVldErrCount(MS_U8 u8Idx)
3618 {
3619 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_VLD_ERR_COUNT, sizeof(MS_U32));
3620 }
3621
HAL_MVD_GetValidStreamFlag(MS_U8 u8Idx)3622 MS_BOOL HAL_MVD_GetValidStreamFlag(MS_U8 u8Idx)
3623 {
3624 return !(MS_BOOL)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_INVALIDSTREAM, sizeof(MS_U8));
3625 }
3626
HAL_MVD_GetIsIPicFound(MS_U8 u8Idx)3627 MS_U8 HAL_MVD_GetIsIPicFound(MS_U8 u8Idx)
3628 {
3629 return (MS_U8)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_FIRST_I_FOUND, sizeof(MS_U8));
3630 }
3631
3632 //------------------------------------------------------------------------------
3633 /// Set PTS base to MVD F/W
3634 /// @param -u32pts \b IN : pts unit in 90k counter
3635 //------------------------------------------------------------------------------
HAL_MVD_SetPTSBase(MS_U8 u8Idx,MS_U32 u32pts)3636 void HAL_MVD_SetPTSBase(MS_U8 u8Idx, MS_U32 u32pts)
3637 {
3638 MVD_CmdArg mvdcmd;
3639
3640 SET_CMDARG(mvdcmd, u32pts, u8Idx);
3641 if (HAL_MVD_MVDCommand( CMD_PTS_BASE, &mvdcmd ) == FALSE)
3642 {
3643 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PTS_BASE ) );
3644 }
3645 return;
3646 }
3647
HAL_MVD_GetPTS(MS_U8 u8Idx)3648 MS_U32 HAL_MVD_GetPTS(MS_U8 u8Idx)
3649 {
3650 MS_U32 u32PTS = 0;
3651
3652 u32PTS = (MS_U32)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DISP_PTS, sizeof(MS_U32));
3653 u32PTS = _90K_TO_MS(u32PTS);
3654 return u32PTS;
3655 }
3656
HAL_MVD_GetU64PTS(MS_U8 u8Idx,MVD_PtsType eType)3657 MS_U64 HAL_MVD_GetU64PTS(MS_U8 u8Idx,MVD_PtsType eType)
3658 {
3659 MS_U64 u64PTS = 0;
3660 MS_U64 u32_high32_PTS = 0;
3661 MS_U64 u32_low32_PTS = 0;
3662
3663 if(eType==E_MVD_PTS_DISP)
3664 {
3665 u32_low32_PTS = (MS_U64)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DISP_PTS, sizeof(MS_U32));
3666 u32_high32_PTS = (MS_U64)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DISP_PTS_MSB, sizeof(MS_U32));
3667 }
3668 else if(eType==E_MVD_PTS_PRE_PAS)
3669 {
3670 u32_low32_PTS = (MS_U64)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_WRPTR_PTS_LOW, sizeof(MS_U32));
3671 u32_high32_PTS = (MS_U64)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_WRPTR_PTS_HIGH, sizeof(MS_U32));
3672 }
3673
3674 u64PTS = (u32_high32_PTS<<32)|u32_low32_PTS;
3675 if(u64PTS != MVD_U64_MAX)
3676 {
3677 do_div(u64PTS,90);
3678 }
3679 return u64PTS;
3680 }
3681
HAL_MVD_GetNextPTS(MS_U8 u8Idx)3682 MS_U32 HAL_MVD_GetNextPTS(MS_U8 u8Idx)
3683 {
3684 return (MS_U32)_90K_TO_MS(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_NEXT_PTS, sizeof(MS_U32)));
3685 }
3686
HAL_MVD_GetChromaFormat(MS_U8 u8Idx)3687 MS_U32 HAL_MVD_GetChromaFormat(MS_U8 u8Idx)
3688 {
3689 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CHROMA_FORMAT, sizeof(MS_U8));
3690 }
3691
HAL_MVD_GetGOPCount(MS_U8 u8Idx)3692 MS_U32 HAL_MVD_GetGOPCount(MS_U8 u8Idx)
3693 {
3694 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_GOP_I_FCNT, sizeof(MS_U32))
3695 + MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_GOP_P_FCNT, sizeof(MS_U32))
3696 + MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_GOP_B_FCNT, sizeof(MS_U32));
3697 }
3698
HAL_MVD_GetColorFormat(MS_U8 u8Idx)3699 MS_U8 HAL_MVD_GetColorFormat(MS_U8 u8Idx)
3700 {
3701 if (GET_FRMINFO_BUFFADD(u8Idx)==0)
3702 {
3703 MVD_DEBUGERROR(printf("%s error: pu8MVDGetFrameInfoBufStart=NULL\n", __FUNCTION__));
3704 return 0xff;
3705 }
3706
3707 return (MS_U8)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_VIDEO_FORMAT, sizeof(MS_U8));
3708 }
3709
HAL_MVD_GetMatrixCoef(MS_U8 u8Idx)3710 MS_U8 HAL_MVD_GetMatrixCoef(MS_U8 u8Idx)
3711 {
3712 if (GET_FRMINFO_BUFFADD(u8Idx)==0)
3713 {
3714 MVD_DEBUGERROR(printf("%s error: pu8MVDGetFrameInfoBufStart=NULL\n", __FUNCTION__));
3715 return 0xff;
3716 }
3717
3718 return (MS_U8)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_MATRIX_COEF, sizeof(MS_U8));
3719 }
3720
HAL_MVD_StepDecode(MS_U8 u8Idx)3721 MS_BOOL HAL_MVD_StepDecode(MS_U8 u8Idx)
3722 {
3723 MVD_CmdArg mvdcmd;
3724 SETUP_CMDARG(mvdcmd);
3725 SET_DECNUM(mvdcmd, u8Idx);
3726 SET_CMD_RET_FALSE(CMD_SINGLE_STEP, &mvdcmd);
3727
3728 if (HAL_MVD_Resume(u8Idx) == FALSE)
3729 {
3730 MVD_DEBUGERROR(printf("Command: HAL_MVD_Resume fail!!\r\n"));
3731 return FALSE;
3732 }
3733
3734 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
3735 if (pCtrlCfg)
3736 {
3737 pCtrlCfg->bStepDecode = TRUE;
3738 }
3739
3740 return TRUE;
3741 }
3742
HAL_MVD_IsStepDispDone(MS_U8 u8Idx)3743 MS_BOOL HAL_MVD_IsStepDispDone(MS_U8 u8Idx)
3744 {
3745 return (MS_BOOL)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_STEP_DISP_DONE, sizeof(MS_U8));
3746 }
3747
HAL_MVD_IsStep2PtsDone(MS_U8 u8Idx)3748 MS_BOOL HAL_MVD_IsStep2PtsDone(MS_U8 u8Idx)
3749 {
3750 return (MS_BOOL)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_STEP_TO_PTS_DONE, sizeof(MS_U8));
3751 }
3752
3753 //Only for RCV.
HAL_MVD_GetPayloadLen(MS_U8 u8Idx)3754 MS_U32 HAL_MVD_GetPayloadLen(MS_U8 u8Idx)
3755 {
3756 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_RCV_PAYLOAD_LENGTH, sizeof(MS_U32));
3757 }
3758
3759 //Only for RCV.
HAL_MVD_GotFileEndPattern(MS_U8 u8Idx)3760 MS_BOOL HAL_MVD_GotFileEndPattern(MS_U8 u8Idx)
3761 {
3762 return (MS_BOOL)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_MEET_FILE_END_SC, sizeof(MS_U8));
3763 }
3764
HAL_MVD_IsCmdFinished(MS_U8 u8Idx,MVD_HANDSHAKE_CMD eCmd)3765 MS_BOOL HAL_MVD_IsCmdFinished(MS_U8 u8Idx, MVD_HANDSHAKE_CMD eCmd)
3766 {
3767 MVD_CMD_HANDSHADE_INDEX u32CmdState;
3768 MS_BOOL bCmdRdy = FALSE;
3769
3770 HAL_MVD_InvalidBuffRetFalse(GET_FRMINFO_BUFFADD(u8Idx));
3771
3772 u32CmdState.value = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CMD_HANDSHAKE_INDEX, sizeof(MS_U32));
3773 MVD_DEBUGINFO(printf("u32CmdState.value = 0x%x\n", u32CmdState.value));
3774 switch (eCmd)
3775 {
3776 case MVD_HANDSHAKE_PAUSE:
3777 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_pause);
3778 break;
3779 case MVD_HANDSHAKE_SLQ_RST:
3780 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_slq_reset);
3781 break;
3782 case MVD_HANDSHAKE_STOP:
3783 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_stop);
3784 break;
3785 case MVD_HANDSHAKE_SKIP_DATA:
3786 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_skip_data);
3787 break;
3788 case MVD_HANDSHAKE_SINGLE_STEP:
3789 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_single_step);
3790 break;
3791 case MVD_HANDSHAKE_SCALER_INFO:
3792 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_scaler_data_ready);
3793 break;
3794 case MVD_HANDSHAKE_GET_NXTDISPFRM:
3795 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_get_nextdispfrm_ready);
3796 break;
3797 case MVD_HANDSHAKE_PARSER_RST:
3798 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_parser_rst);
3799 break;
3800 case MVD_HANDSHAKE_RST_CC608:
3801 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_cc608_rst);
3802 break;
3803 case MVD_HANDSHAKE_RST_CC708:
3804 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_cc708_rst);
3805 break;
3806 case MVD_HANDSHAKE_VIRTUAL_COMMAND:
3807 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_virtualCommand);
3808 break;
3809 case MVD_HANDSHAKE_FLUSHQUEUE_COMMAND:
3810 bCmdRdy = (MS_BOOL)(u32CmdState.mvdcmd_handshake_flush);
3811 break;
3812 default:
3813 bCmdRdy = FALSE;
3814 break;
3815 }
3816 return bCmdRdy;
3817 }
3818
HAL_MVD_ClearCmdFinished(MS_U8 u8Idx,MVD_HANDSHAKE_CMD eCmd)3819 MS_BOOL HAL_MVD_ClearCmdFinished(MS_U8 u8Idx, MVD_HANDSHAKE_CMD eCmd)
3820 {
3821 MVD_CMD_HANDSHADE_INDEX u32CmdState;
3822
3823 HAL_MVD_InvalidBuffRetFalse(GET_FRMINFO_BUFFADD(u8Idx));
3824
3825 u32CmdState.value = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CMD_HANDSHAKE_INDEX, sizeof(MS_U32));
3826 MVD_DEBUGINFO(printf("before CLR u32CmdState.value = 0x%x\n", u32CmdState.value));
3827 switch (eCmd)
3828 {
3829 case MVD_HANDSHAKE_SCALER_INFO:
3830 u32CmdState.mvdcmd_handshake_scaler_data_ready = 0;
3831 break;
3832 default:
3833 break;
3834 }
3835
3836 //write the value back: may it overwrite the value that f/w is supposed to write?
3837 MVD_WriteFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CMD_HANDSHAKE_INDEX, sizeof(MS_U32), u32CmdState.value);
3838 MVD_DEBUGINFO(printf("after CLR u32CmdState.value = 0x%x\n",
3839 MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CMD_HANDSHAKE_INDEX, sizeof(MS_U32))));
3840 return TRUE;
3841 }
3842
3843
HAL_MVD_GetTimeCode(MS_U8 u8Idx,MVD_FrmInfoType eType,MVD_TimeCode * pInfo)3844 MS_BOOL HAL_MVD_GetTimeCode(MS_U8 u8Idx, MVD_FrmInfoType eType, MVD_TimeCode* pInfo)
3845 {
3846 MS_BOOL bRet = FALSE;
3847 MS_VIRT pu8MVDGetFrameInfoBufStart = GET_FRMINFO_BUFFADD(u8Idx);
3848 if (NULL == pInfo)
3849 {
3850 return FALSE;
3851 }
3852
3853 HAL_MVD_InvalidBuffRetFalse(pu8MVDGetFrameInfoBufStart);
3854
3855 if (E_MVD_FRMINFO_DECODE == eType)
3856 {
3857 pInfo->u8TimeCodeHr = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_HOURS);
3858 pInfo->u8TimeCodeMin = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_MINUTES);
3859 pInfo->u8TimeCodeSec = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_SECONDS);
3860 pInfo->u8TimeCodePic = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_PICTURES);
3861 pInfo->u8DropFrmFlag = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_DROP_FRAME_FLAG);
3862 }
3863 else if (E_MVD_FRMINFO_DISPLAY == eType)
3864 {
3865 pInfo->u8TimeCodeHr = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_HOURS_DISP);
3866 pInfo->u8TimeCodeMin = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_MINUTES_DISP);
3867 pInfo->u8TimeCodeSec = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_SECONDS_DISP);
3868 pInfo->u8TimeCodePic = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_TIME_CODE_PICTURES_DISP);
3869 pInfo->u8DropFrmFlag = HAL_MVD_MemReadByte(pu8MVDGetFrameInfoBufStart+OFFSET_DROP_FRAME_FLAG_DISP);
3870 }
3871 else
3872 {
3873 bRet = FALSE;
3874 }
3875
3876 return bRet;
3877 }
3878
HAL_MVD_GetDispCnt(MS_U8 u8Idx)3879 MS_U32 HAL_MVD_GetDispCnt(MS_U8 u8Idx)
3880 {
3881 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DISPLAYED_CNT, sizeof(MS_U32));
3882 }
3883
HAL_MVD_GetMinTspDataSize(MS_U8 u8HalIdx)3884 MS_U32 HAL_MVD_GetMinTspDataSize(MS_U8 u8HalIdx)
3885 {
3886 #ifdef OFFSET_CUR_MIN_TSP_DATA_SIZE
3887 return MVD_GetFWBuffData(u8HalIdx, FW_BUFF_FRMINFO, OFFSET_CUR_MIN_TSP_DATA_SIZE, sizeof(MS_U32));
3888 #else
3889 return 0x400;
3890 #endif
3891 }
3892
HAL_MVD_GetDropCnt(MS_U8 u8Idx)3893 MS_U32 HAL_MVD_GetDropCnt(MS_U8 u8Idx)
3894 {
3895 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DROP_FRAME_COUNT, sizeof(MS_U32));
3896 }
3897
3898
HAL_MVD_GetXcLowDelayIntState(MS_U8 u8Idx)3899 MS_U32 HAL_MVD_GetXcLowDelayIntState(MS_U8 u8Idx)
3900 {
3901 MS_VIRT pu8MVDGetFrameInfoBufStart = GET_FRMINFO_BUFFADD(u8Idx);
3902
3903 if(pu8MVDGetFrameInfoBufStart==0)
3904 {
3905 MVD_DEBUGERROR(printf("MDrv_MVD_GetXcLowDelayIntState error: pu8MVDGetFrameInfoBufStart=NULL\n"));
3906 return 0;
3907 }
3908
3909 MVD_DEBUGINFO(printf("MDrv_MVD_GetXcLowDelayIntState()=%x,%x,%x,%x,%x\n",
3910 (HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_XC_LOW_DELAY_CNT)),
3911 (HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_XC_LOW_DELAY_INT_STATE)),
3912 (HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_XC_DIFF_FIELD_NO)),
3913 (HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_XC_LOW_DELAY_CNT_LATCH)),
3914 (HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_FRAME_COUNT))));
3915
3916 return HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart+OFFSET_XC_LOW_DELAY_INT_STATE);
3917 }
3918
3919 //Get ErrStatus when ErrCode==ErrShape
MVD_GetErrShapeStat(MS_U32 u32errStat)3920 static MVD_ErrStatus MVD_GetErrShapeStat(MS_U32 u32errStat)
3921 {
3922 MVD_ErrStatus st = E_MVD_ERR_STATUS_UNKOWN;
3923 switch (u32errStat)
3924 {
3925 case 0:
3926 st = E_MVD_ERR_SHAPE_RECTANGULAR;
3927 break;
3928 case 1:
3929 st = E_MVD_ERR_SHAPE_BINARY;
3930 break;
3931 case 2:
3932 st = E_MVD_ERR_SHAPE_BINARY_ONLY;
3933 break;
3934 case 3:
3935 st = E_MVD_ERR_SHAPE_GRAYSCALE;
3936 break;
3937 default:
3938 break;
3939 }
3940 return st;
3941 }
3942
3943 //Get ErrStatus when ErrCode==ErrSprite
MVD_GetErrSpriteStat(MS_U32 u32errStat)3944 static MVD_ErrStatus MVD_GetErrSpriteStat(MS_U32 u32errStat)
3945 {
3946 MVD_ErrStatus st = E_MVD_ERR_STATUS_UNKOWN;
3947 switch (u32errStat)
3948 {
3949 case 0:
3950 st = E_MVD_ERR_USED_SPRITE_UNUSED;
3951 break;
3952 case 1:
3953 st = E_MVD_ERR_USED_SPRITE_STATIC;
3954 break;
3955 case 2:
3956 st = E_MVD_ERR_USED_SPRITE_GMC;
3957 break;
3958 case 3:
3959 st = E_MVD_ERR_USED_SPRITE_RESERVED;
3960 break;
3961 default:
3962 break;
3963 }
3964 return st;
3965 }
3966
HAL_MVD_GetErrInfo(MS_U8 u8Idx,MVD_ErrCode * errCode,MVD_ErrStatus * errStatus)3967 void HAL_MVD_GetErrInfo(MS_U8 u8Idx, MVD_ErrCode *errCode, MVD_ErrStatus *errStatus)
3968 {
3969 MS_U32 errorCode = E_MVD_ERR_UNKNOWN;
3970 MS_U32 errorStatus = E_MVD_ERR_STATUS_UNKOWN;
3971 MS_VIRT pu8MVDGetFrameInfoBufStart = GET_FRMINFO_BUFFADD(u8Idx);
3972
3973 if(pu8MVDGetFrameInfoBufStart==0)
3974 {
3975 MVD_DEBUGERROR(printf("MDrv_MVD_GetErrInfo error!\n"));
3976 return;
3977 }
3978
3979 errorCode = HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart + OFFSET_ERROR_CODE);
3980 errorStatus = HAL_MVD_MemRead4Byte(pu8MVDGetFrameInfoBufStart + OFFSET_ERROR_STATUS);
3981
3982 switch (errorCode)
3983 {
3984 case VOL_SHAPE:
3985 *errCode = E_MVD_ERR_SHAPE;
3986 *errStatus = MVD_GetErrShapeStat(errorStatus);
3987 break;
3988 case VOL_USED_SPRITE:
3989 *errCode = E_MVD_ERR_USED_SPRITE;
3990 *errStatus = MVD_GetErrSpriteStat(errorStatus);
3991 break;
3992 case VOL_NOT_8_BIT:
3993 *errCode = E_MVD_ERR_NOT_8_BIT;
3994 *errStatus = E_MVD_ERR_STATUS_NONE;
3995 break;
3996 case VOL_NERPRED_ENABLE:
3997 *errCode = E_MVD_ERR_NERPRED_ENABLE;
3998 *errStatus = E_MVD_ERR_STATUS_NONE;
3999 break;
4000 case VOL_REDUCED_RES_ENABLE:
4001 *errCode = E_MVD_ERR_REDUCED_RES_ENABLE;
4002 *errStatus = E_MVD_ERR_STATUS_NONE;
4003 break;
4004 case VOL_SCALABILITY:
4005 *errCode = E_MVD_ERR_SCALABILITY;
4006 *errStatus = E_MVD_ERR_STATUS_NONE;
4007 break;
4008 case VOL_H263_ERROR:
4009 *errCode = E_MVD_ERR_H263_ERROR;
4010 *errStatus = E_MVD_ERR_STATUS_NONE;
4011 break;
4012 case VOL_RES_NOT_SUPPORT:
4013 *errCode = E_MVD_ERR_RES_NOT_SUPPORT;
4014 *errStatus = E_MVD_ERR_STATUS_NONE;
4015 break;
4016 case VOL_MPEG4_NOT_SUPPORT:
4017 *errCode = E_MVD_ERR_MPEG4_NOT_SUPPORT;
4018 *errStatus = E_MVD_ERR_STATUS_NONE;
4019 break;
4020 case VOL_PROFILE_NOT_SUPPORT:
4021 *errCode = E_MVD_ERR_PROFILE_NOT_SUPPORT;
4022 *errStatus = E_MVD_ERR_STATUS_NONE;
4023 break;
4024 case VOL_RCV_ERROR_OCCUR:
4025 *errCode = E_MVD_ERR_RCV_ERROR_OCCUR;
4026 *errStatus = E_MVD_ERR_STATUS_NONE;
4027 break;
4028 case VOL_OTHER:
4029 *errCode = E_MVD_ERR_OTHER;
4030 *errStatus = E_MVD_ERR_STATUS_NONE;
4031 break;
4032 default:
4033 *errCode = E_MVD_ERR_UNKNOWN;
4034 *errStatus = E_MVD_ERR_STATUS_UNKOWN;
4035 break;
4036 }
4037
4038 return;
4039 }
4040
4041 //take care MIU1 address
HAL_MVD_GetMemOffset(MS_PHY u32PhyAdd)4042 MS_PHY HAL_MVD_GetMemOffset(MS_PHY u32PhyAdd)
4043 {
4044 if (u32PhyAdd >= pMVDHalContext->stMiuCfg.u32Miu2BaseAddr)
4045 {
4046 return (u32PhyAdd - pMVDHalContext->stMiuCfg.u32Miu2BaseAddr);
4047 }
4048 else if(u32PhyAdd >= pMVDHalContext->stMiuCfg.u32Miu1BaseAddr)
4049 {
4050 return (u32PhyAdd - pMVDHalContext->stMiuCfg.u32Miu1BaseAddr);
4051 }
4052 else
4053 {
4054 return u32PhyAdd;
4055 }
4056 }
4057
4058
HAL_MVD_SLQTblSendPacket(MS_U8 u8Idx,MVD_PacketInfo * pstVideoPKT)4059 MS_BOOL HAL_MVD_SLQTblSendPacket(MS_U8 u8Idx, MVD_PacketInfo *pstVideoPKT)
4060 {
4061 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
4062 MS_VIRT u32EsLast;
4063 MS_VIRT* u32LastEntry = &pstSlqTblInfo->pDrvSlqTbl->u32WrPtr;
4064 MS_VIRT* pu32EsNew = &pstSlqTblInfo->pDrvEsTbl->u32WrPtr;
4065 MS_U32 u32EntryWord = 0;
4066 MS_U32 u32Index = 0;
4067 MS_U32 u32Pts;
4068 MS_VIRT u32MVDFWPtsTblAddr = NULL;
4069 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
4070
4071 MS_U32 u32ESStart=0;
4072 MS_U32 u32ESEnd=0;
4073 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
4074
4075
4076 #if _SLQTBL_DUMP_PKT
4077 // static MS_U32 u32SendTimes[MAX_DEC_NUM]= {0, 0};
4078
4079 printf("Pkt[%x] st=0x%x len=0x%x pts=0x%x id_l=0x%x id_h=0x%x\n", u32SendTimes[u8Idx]++,
4080 pstVideoPKT->u32StAddr, pstVideoPKT->u32Length, pstVideoPKT->u32TimeStamp,
4081 pstVideoPKT->u32ID_L, pstVideoPKT->u32ID_H);
4082 #endif
4083
4084 #ifdef VDEC3
4085 if(pstCtrlCfg->u8McuMode == FALSE)
4086 #endif
4087 {
4088 u32MVDFWPtsTblAddr = GET_PTSTBL_BUFFADD(u8Idx);
4089 MS_ASSERT(u32MVDFWPtsTblAddr != NULL);
4090 if (u32MVDFWPtsTblAddr)
4091 {
4092 MS_VIRT u32PtsTblEntryAddr = 0;
4093 //so far, this is the only place that driver will write f/w 1M area after init.
4094 u32Index = (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr - pstSlqTblInfo->pDrvSlqTbl->u32StAdd)/8;
4095 if(HAL_MVD_IsMcuMode(u8Idx) == FALSE)
4096 {
4097 if (pstVideoPKT->u32TimeStamp != MVD_NULLPKT_PTS)
4098 {
4099 u32Pts = _MS_TO_90K(pstVideoPKT->u32TimeStamp);
4100 }
4101 else
4102 {
4103 u32Pts = MVD_NULLPKT_PTS;
4104 }
4105 }
4106 else
4107 {
4108 u32Pts = pstVideoPKT->u32TimeStamp;
4109 }
4110 u32PtsTblEntryAddr = u32MVDFWPtsTblAddr+u32Index*MVD_FW_SLQTBL_PTS_LEN;
4111 HAL_MVD_MemWrite4Byte(u32PtsTblEntryAddr+4, pstSlqTblInfo->u32DummyPktCnt); //dummyPktCnt
4112 HAL_MVD_MemWrite4Byte(u32PtsTblEntryAddr+8, pstVideoPKT->u32ID_L); //idLow
4113 HAL_MVD_MemWrite4Byte(u32PtsTblEntryAddr+12, pstVideoPKT->u32ID_H); //idHigh
4114 HAL_MVD_MemWrite4Byte(u32PtsTblEntryAddr+16, u32Pts); //PTS
4115 HAL_MVD_MemWrite4Byte(u32PtsTblEntryAddr, (pstSlqTblInfo->u32SlqByteCnt)&0xffffff); //byteCnt
4116 //printf("PTS=0x%x(%x), idx=0x%x add=0x%x\n", pstVideoPKT->u32TimeStamp,
4117 // HAL_MVD_MemRead4Byte(u32PtsTblEntryAddr+16),
4118 // u32Index, u32PtsTblEntryAddr+16);
4119
4120 if ((HAL_MVD_IsMStreamerMode(u8Idx) || HAL_MVD_IsMcuMode(u8Idx))
4121 && (pstCtrlCfg->eFileSyncMode == E_MVD_TIMESTAMP_STS))
4122 {
4123 if(pMVDHalContext->bDropOnePTS[u8Idx] == FALSE)
4124 {
4125 HAL_MVD_MemWrite4Byte(u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_LEN+12, pstVideoPKT->u32ID_H); //idHigh
4126 HAL_MVD_MemWrite4Byte(u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_LEN+16, pstVideoPKT->u32TimeStamp); //PTS
4127
4128 MVD_DBG_STS(printf(">>> drvMVD pts,idH = %lu, %lu\n", HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_LEN+16),
4129 HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_LEN+12)));
4130 if (((MVD_NULLPKT_PTS == pstVideoPKT->u32ID_H) && (MVD_NULLPKT_PTS == pstVideoPKT->u32TimeStamp)) == FALSE)
4131 { //Only update PTS to firmware when pts field is valid.
4132 //Plz refer to MDrv_MVD_PushQueue if (u8MstMode == MST_MODE_TRUE) {}
4133 HAL_MVD_UpdatePts(u8Idx); //for uniplayer or MCU mode
4134 }
4135 }
4136
4137 pMVDHalContext->bDropOnePTS[u8Idx] = FALSE;
4138 }
4139 }
4140 #if _SLQTBL_DUMP_PTS
4141 if (u32Index == 0x177)
4142 {
4143 _SLQTbl_DumpPtsTbl(u8Idx, 0, 0x179);
4144 }
4145 #endif
4146 }
4147 pstSlqTblInfo->u32SlqByteCnt += pstVideoPKT->u32Length;
4148
4149 //update SLQ tbl entry
4150 //u32EsLast = (pstVideoPKT->u32StAddr)+pstSlqTblInfo->pDrvSlqTbl->u32StAdd;
4151 u32EsLast = (pstVideoPKT->u32StAddr)+HAL_MVD_GetMemOffset(pstMemCfg->u32BSAddr);
4152 HAL_MVD_MemWrite4Byte(*pu32EsNew, u32EsLast-HAL_MVD_GetMemOffset(pstMemCfg->u32BSAddr));
4153 u32ESStart = (u32EsLast) & SLQ_TBL_ENTRY_LEN;
4154
4155 u32EsLast += pstVideoPKT->u32Length; //update ES write pointer
4156 //Notice: This is for MVD HW, so no need to minus one.
4157 HAL_MVD_MemWrite4Byte((*pu32EsNew)+4, u32EsLast-HAL_MVD_GetMemOffset(pstMemCfg->u32BSAddr));
4158 u32ESEnd = (u32EsLast) & SLQ_TBL_ENTRY_LEN;
4159
4160 *pu32EsNew += 8;
4161 if (*pu32EsNew >= pstSlqTblInfo->pDrvEsTbl->u32EndAdd)
4162 { //wrap to the beginning of the table
4163 MVD_DEBUGINFO(printf("...ES wrapping to the beginning!\n"));
4164 *pu32EsNew = pstSlqTblInfo->pDrvEsTbl->u32StAdd;
4165 }
4166
4167 //printf("===>[%x] u32ESStart=0x%x u32ESEnd=0x%x u32EsLast=0x%x\n",
4168 // pMVDHalContext->u32SendTimes[u8Idx]++, u32ESStart, u32ESEnd, u32EsLast);
4169
4170 u32EntryWord = u32ESEnd;
4171 HAL_MVD_MemWrite4Byte(*u32LastEntry, u32EntryWord);
4172 //printf("===> u32EntryWord1 addr=0x%x\n", (*u32LastEntry));
4173 //printf("===> u32EntryWord0=0x%x\n", u32EntryWord);
4174
4175 u32EntryWord = u32ESStart;
4176 HAL_MVD_MemWrite4Byte((*u32LastEntry)+4, u32EntryWord);
4177 //printf("===> u32EntryWord1 addr=0x%x\n", (*u32LastEntry)+4);
4178 //printf("===> u32EntryWord1=0x%x\n", u32EntryWord);
4179
4180 *u32LastEntry += 8;
4181 if (*u32LastEntry >= pstSlqTblInfo->pDrvSlqTbl->u32EndAdd)
4182 { //wrap to the beginning of the table
4183 MVD_DEBUGINFO(printf("...wrapping to the beginning!\n"));
4184 *u32LastEntry = pstSlqTblInfo->pDrvSlqTbl->u32StAdd;
4185 //also wrap DivX311 pattern table
4186 pstSlqTblInfo->pDrvDivxTbl->u32WrPtr = pstSlqTblInfo->pDrvDivxTbl->u32StAdd;
4187 }
4188
4189 if (pstSlqTblInfo->pDrvSlqTbl->u32Empty)
4190 {
4191 pstSlqTblInfo->pDrvSlqTbl->u32Empty -= SLQ_ENTRY_LEN;
4192 }
4193
4194 return TRUE;
4195 }
4196
4197 //Table of frame rate code for MPEG-2
4198 #if 0
4199 #define FRM_RATE_CODE_NUM 9
4200 static const MS_U16 stFrameRateCode[FRM_RATE_CODE_NUM]=
4201 {
4202 NULL,23976,24000,25000,29976,30000,50000,59947,60000
4203 };
4204 #endif
MVD_GCD(MS_U32 u32A,MS_U32 u32B)4205 static MS_U32 MVD_GCD(MS_U32 u32A, MS_U32 u32B)
4206 {
4207 MS_S32 i;
4208 MS_U32 x[4]; /* need x[0], x[1], x[i-1] */
4209
4210 if (u32A > u32B)
4211 {
4212 x[0] = u32A; x[1] = u32B;
4213 }
4214 else
4215 {
4216 x[0] = u32B; x[1] = u32A;
4217 }
4218
4219 i = 1;
4220
4221 #define w(x) (((x)<4)?(x):(2+((x)&1)))
4222
4223 while( x[w(i)] != 0 )
4224 {
4225 x[w(i+1)] = x[w(i-1)] % x[w(i)];
4226 i++;
4227 }
4228
4229 return x[w(i-1)];
4230
4231 #undef w
4232 }
HAL_MVD_GetFrameInfo(MS_U8 u8Idx,MVD_FrameInfo * pinfo)4233 void HAL_MVD_GetFrameInfo(MS_U8 u8Idx, MVD_FrameInfo *pinfo)
4234 {
4235 FW_VOL_INFO gvolInfo;
4236 FW_DIVX_INFO* pDivxInfo = &(pMVDHalContext->gdivxInfo[u8Idx]);
4237 MS_VIRT temp = 0;
4238 MS_U32 u32DAR_Width=0,u32DAR_Height=0,u32PAR_Width=0,u32PAR_Height=0,u32GCD=0;
4239 MS_U32 u32Vertical_Size=0, u32Horizontal_Size=0;
4240 //13818-2 page 38 Table 6-3
4241 MS_U8 u8DARTable[5][2] = { {1,1}, {1,1}, {4,3}, {16,9}, {221,100} };
4242 MS_U32 pu8MVDGetVolBufStart = NULL;
4243 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
4244
4245 pu8MVDGetVolBufStart = GET_VOL_BUFFADD(u8Idx);
4246 if (pu8MVDGetVolBufStart == NULL)
4247 {
4248 MVD_DEBUGERROR(printf("MDrv_MVD_GetFrameInfo error: pu8MVDGetVolBufStart=NULL\n"));
4249 return;
4250 }
4251
4252 HAL_MVD_CPU_Sync();
4253 HAL_MVD_ReadMemory();
4254
4255 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,GET_VOL_BUFFADD(u8Idx),temp);
4256
4257 gvolInfo = (*(volatile FW_VOL_INFO*)(HAL_MVD_PA2NonCacheSeg(temp)));
4258
4259 pinfo->u16HorSize = (MS_U16) gvolInfo.width;
4260 pinfo->u16VerSize = (MS_U16) gvolInfo.height;
4261 pinfo->u16par_width = (MS_U16) gvolInfo.par_width;
4262 pinfo->u16par_height = (MS_U16) gvolInfo.par_height;
4263 pinfo->u8AspectRate = gvolInfo.aspect_ratio;
4264
4265 pinfo->u16CropBottom = gvolInfo.CropBottom;
4266 pinfo->u16CropTop = 0;
4267 pinfo->u16CropLeft = 0;
4268
4269 if (pinfo->u16HorSize & MVD_WIDTH_ALIGN_MASK)
4270 {
4271 //Notice: Firmware and driver have to be consistent for this part,
4272 // otherwise the pitch will not match and video is noisy.
4273 pinfo->u16CropRight = MVD_WIDTH_ALIGN_BYTE - (pinfo->u16HorSize & MVD_WIDTH_ALIGN_MASK);
4274 pinfo->u16HorSize = ((pinfo->u16HorSize >> MVD_WIDTH_ALIGN_BITS) + 1) << MVD_WIDTH_ALIGN_BITS;
4275 }
4276 else
4277 {
4278 pinfo->u16CropRight = 0;
4279 }
4280
4281 MVD_CodecType curCodecType = HAL_MVD_GetCodecType(u8Idx);
4282 if ((curCodecType == E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER) ||
4283 (curCodecType == E_MVD_CODEC_DIVX311) || (curCodecType == E_MVD_CODEC_FLV))
4284 {
4285 pinfo->u8Interlace= FALSE; //divx311/flv/svh just has progressive mode
4286 MS_ASSERT(gvolInfo.progressive_sequence == 1); //FW will init it as 1
4287 }
4288 else
4289 {
4290 if (gvolInfo.progressive_sequence == 0)
4291 {
4292 pinfo->u8Interlace=1;
4293 }
4294 else
4295 {
4296 pinfo->u8Interlace=0;
4297 }
4298 }
4299
4300 ///Calculate PAR info
4301 if (pinfo->u16par_width == 0 || pinfo->u16par_height == 0)
4302 {
4303 if ((pinfo->u8AspectRate > 0) && (pinfo->u8AspectRate < 5 ))
4304 {
4305 if (pinfo->u8AspectRate == 1)
4306 { //SAR=1.0 square sample
4307 u32DAR_Width = (MS_U32)pinfo->u16HorSize;
4308 u32DAR_Height = (MS_U32)pinfo->u16VerSize;
4309 pinfo->u16par_width = 1;
4310 pinfo->u16par_height = 1;
4311 }
4312 else
4313 {
4314 u32DAR_Width = (MS_U32)u8DARTable[pinfo->u8AspectRate][0];
4315 u32DAR_Height = (MS_U32)u8DARTable[pinfo->u8AspectRate][1];
4316 u32Vertical_Size = (MS_U32)pinfo->u16VerSize;
4317 u32Horizontal_Size = (MS_U32)(pinfo->u16HorSize - pinfo->u16CropRight);
4318 u32PAR_Width = u32DAR_Width * u32Vertical_Size;
4319 u32PAR_Height = u32DAR_Height * u32Horizontal_Size;
4320 u32GCD = MVD_GCD(u32PAR_Width, u32PAR_Height);
4321 if (0 == u32GCD)
4322 {
4323 pinfo->u16HorSize = 0xFFFF;
4324 pinfo->u16VerSize = 0xFFFF;
4325
4326 return;
4327 }
4328 else
4329 {
4330 pinfo->u16par_width = (MS_U16) (u32PAR_Width / u32GCD);
4331 pinfo->u16par_height = (MS_U16) (u32PAR_Height / u32GCD);
4332 MVD_DEBUGVERBAL(printf("u32PAR_Width:%d,u32PAR_Height:%d,GCD:%d\n",u32PAR_Width,u32PAR_Height,u32GCD));
4333 }
4334 }
4335 }
4336 else
4337 {
4338 //set to 0 to indicate it's abnormal
4339 u32DAR_Width = 0;
4340 u32DAR_Height = 0;
4341 pinfo->u16par_width = 0;
4342 pinfo->u16par_height = 0;
4343 }
4344 MVD_DEBUGVERBAL(printf("u32DAR_Width:%d,u32DAR_Height%d\n",u32DAR_Width,u32DAR_Height));
4345 }
4346 MVD_DEBUGVERBAL(printf("pinfo->u16par_width:%d, pinfo->u16par_height:%d\n",pinfo->u16par_width, pinfo->u16par_height));
4347
4348 if (curCodecType == E_MVD_CODEC_MPEG2)
4349 {
4350 if (gvolInfo.frame_rate < FRM_RATE_CODE_NUM)
4351 {
4352 pinfo->u32FrameRate = stFrameRateCode[gvolInfo.frame_rate];
4353 }
4354 else
4355 {
4356 pinfo->u32FrameRate = 0;
4357 }
4358 }
4359 else if ((curCodecType == E_MVD_CODEC_VC1_ADV) || (curCodecType == E_MVD_CODEC_VC1_MAIN))
4360 {
4361 if ((gvolInfo.vc1_frame_rate != 0) && (gvolInfo.vc1_frame_rate != MVD_U32_MAX))
4362 {
4363 pinfo->u32FrameRate = gvolInfo.vc1_frame_rate;
4364 }
4365 else if(pMVDHalContext->u32DmxFrameRate[u8Idx] != 0 && pMVDHalContext->u32DmxFrameRateBase[u8Idx] != 0)
4366 {
4367 pinfo->u32FrameRate = (pMVDHalContext->u32DmxFrameRate[u8Idx] * 1000) / pMVDHalContext->u32DmxFrameRateBase[u8Idx];
4368 }
4369 else
4370 {
4371 pinfo->u32FrameRate = pDivxInfo->frame_rate; //report framerate specified in MDrv_MVD_SetFrameInfo()
4372 }
4373
4374 MVD_DEBUGVERBAL(printf("MVD: vc1_frameRate=%d\n", pinfo->u32FrameRate));
4375 }
4376 else if (curCodecType == E_MVD_CODEC_MPEG4)
4377 {
4378 if (pDivxInfo->frame_rate != 0)
4379 {
4380 pinfo->u32FrameRate = pDivxInfo->frame_rate;
4381 //report framerate specified in MDrv_MVD_SetFrameInfo(), which is usually obtained from container
4382 }
4383 else if (gvolInfo.frame_rate != 0)
4384 {
4385 pinfo->u32FrameRate = gvolInfo.frame_rate; //report framerate from f/w
4386 }
4387 else if ((gvolInfo.fixed_vop_time_incr != 0) && (gvolInfo.vol_time_incr_res != 0))
4388 {
4389 pinfo->u32FrameRate = (gvolInfo.vol_time_incr_res * 1000) / gvolInfo.fixed_vop_time_incr;
4390 //calculate framerate according to vol header
4391 }
4392 else if(pMVDHalContext->u32DmxFrameRate[u8Idx] != 0 && pMVDHalContext->u32DmxFrameRateBase[u8Idx] != 0)
4393 {
4394 pinfo->u32FrameRate = (pMVDHalContext->u32DmxFrameRate[u8Idx] * 1000) / pMVDHalContext->u32DmxFrameRateBase[u8Idx];
4395 }
4396 else
4397 {
4398 pinfo->u32FrameRate = 60000; //set default frame rate according to chip capability
4399 }
4400 MVD_DEBUGVERBAL(printf("MVD: vol_time_incr_res=%d, fixed_vop_time_incr=%d\n", gvolInfo.vol_time_incr_res, gvolInfo.fixed_vop_time_incr));
4401 }
4402 else
4403 {
4404 if (gvolInfo.frame_rate != 0)
4405 {
4406 pinfo->u32FrameRate = gvolInfo.frame_rate;
4407 }
4408 else
4409 {
4410 pinfo->u32FrameRate = pDivxInfo->frame_rate; //report framerate specified in MDrv_MVD_SetFrameInfo()
4411 }
4412 }
4413 MVD_DEBUGVERBAL(printf("===> MVD: frameRate=%d curCodecType=0x%x\n", pinfo->u32FrameRate, curCodecType));
4414
4415 //for MM
4416 pinfo->u8MPEG1=gvolInfo.mpeg1;
4417 pinfo->u16PTSInterval=gvolInfo.pts_incr;
4418 pinfo->u8PlayMode=gvolInfo.play_mode;
4419 pinfo->u8FrcMode=gvolInfo.mpeg_frc_mode;
4420
4421 //for dynamic scaling
4422 pinfo->bEnableMIUSel = (MS_BOOL)pMVDHalContext->stMiuCfg.u8FWMiuSel;
4423
4424 if(pMVDHalContext->stMiuCfg.u8FWMiuSel >= E_CHIP_MIU_2)
4425 {
4426 MVD_DEBUGERROR(printf("u8MiuSel is %d !!, but return type is only Boolean. Please use MDrv_HVD_EX_GetDSBufMiuSelect() to get right miu select of DS buffer!\n",pMVDHalContext->stMiuCfg.u8FWMiuSel));
4427 }
4428
4429 if (pstMemCfg->bEnableDynScale)
4430 {
4431 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,GET_DS_BUFFADD(u8Idx),pinfo->u32DynScalingAddr);
4432
4433 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
4434 pinfo->u8DynScalingDepth= pCtrlCfg->u8DynScalingDepth;
4435 pinfo->u32DynScalingBufSize= gvolInfo.DSbufsize;
4436 }
4437 else
4438 {
4439 pinfo->u32DynScalingAddr= NULL;
4440 pinfo->u8DynScalingDepth= 0;
4441 pinfo->u32DynScalingBufSize= 0;
4442 }
4443
4444 return;
4445 }
4446
MVD_RstFrmInfo(MS_U8 u8Idx,MVD_FrmInfoType eType)4447 E_MVD_Result MVD_RstFrmInfo(MS_U8 u8Idx, MVD_FrmInfoType eType)
4448 {
4449 E_MVD_Result eRet = E_MVD_RET_OK;
4450 MS_VIRT u32DecFrmInfoAdd = GET_DECFRMINFO_BUFFADD(u8Idx);
4451 if (NULL == u32DecFrmInfoAdd)
4452 {
4453 return E_MVD_RET_FAIL;
4454 }
4455
4456 //printf("%s u32DecFrmInfoAdd = 0x%x\n", __FUNCTION__, u32DecFrmInfoAdd);
4457 if (E_MVD_FRMINFO_DECODE == eType)
4458 {
4459 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_LUMAADDR), _INIT_ADDR);
4460 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_CHROMAADDR), _INIT_ADDR);
4461 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_TIMESTAMP), _INIT_TIMESTAMP);
4462 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_ID_L), _INIT_ID);
4463 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_ID_H), _INIT_ID);
4464 HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_PITCH), _INIT_LEN);
4465 HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_WIDTH), _INIT_LEN);
4466 HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_HEIGHT), _INIT_LEN);
4467 HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_FRAMETYPE), 0xff);
4468 }
4469 else if (E_MVD_FRMINFO_DISPLAY == eType)
4470 {
4471 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_LUMAADDR), _INIT_ADDR);
4472 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_CHROMAADDR), _INIT_ADDR);
4473 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_TIMESTAMP), _INIT_TIMESTAMP);
4474 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_ID_L), _INIT_ID);
4475 HAL_MVD_MemWrite4Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_ID_H), _INIT_ID);
4476 HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_PITCH), _INIT_LEN);
4477 HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_WIDTH), _INIT_LEN);
4478 HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_HEIGHT), _INIT_LEN);
4479 HAL_MVD_MemWrite2Byte((u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_FRAMETYPE), 0xff);
4480 }
4481 else
4482 {
4483 eRet = E_MVD_RET_INVALID_PARAM;
4484 }
4485
4486 return eRet;
4487 }
4488
4489 //Given the start address & the available size for the FW buffers,
4490 //Calculate the start address of each buffers.
MVD_GetFWBuffAdd(MS_VIRT u32Start,MS_U32 u32AvailLen,MVD_FWBuff * pBuff)4491 static MS_BOOL MVD_GetFWBuffAdd(MS_VIRT u32Start, MS_U32 u32AvailLen, MVD_FWBuff* pBuff)
4492 {
4493 MS_VIRT tmpAdr = u32Start;
4494
4495 if(pBuff == NULL)
4496 {
4497 MVD_DEBUGERROR(printf("%s err: NULL pBuff\n", __FUNCTION__));
4498 return FALSE;
4499 }
4500 tmpAdr += MVD_FW_CODE_LEN;
4501 GET_FW_BUFFADD_ALIGN(tmpAdr, FW_BUFF_ALIGN, MVD3_FW_VOL_INFO_BUF_LEN, pBuff->pu8MVDGetVolBufStart);
4502 GET_FW_BUFFADD_ALIGN(tmpAdr, FW_BUFF_ALIGN, MVD3_FW_FRAME_INFO_BUF_LEN, pBuff->pu8MVDGetFrameInfoBufStart);
4503 GET_FW_BUFFADD_ALIGN(tmpAdr, FW_BUFF_ALIGN, MVD3_FW_DIVX_INFO_BUF_LEN, pBuff->pu8MVDSetHeaderBufStart);
4504 GET_FW_BUFFADD_ALIGN(tmpAdr, FW_BUFF_ALIGN,
4505 (MVD3_FW_USER_DATA_BUF_LEN+MVD3_FW_USER_DATA_BUF_BACKUP_LEN), pBuff->u32UserDataBuf);
4506 //MVD3_FW_USER_DATA_BUF_BACKUP_LEN is used as CC decoding buffer for MVD_SUPPORT_X4_CC
4507
4508 GET_FW_BUFFADD_ALIGN(tmpAdr, FW_BUFF_ALIGN, MVD3_FW_SLQ_TAB_TMPBUF_LEN, pBuff->u32MVDFWSLQTABTmpbufAdr);
4509 GET_FW_BUFFADD(tmpAdr, MVD_FW_SLQTBL_PTS_BUF_LEN, pBuff->u32MVDFWPtsTblAddr);
4510 GET_FW_BUFFADD(tmpAdr, MVD_FW_DYN_SCALE_BUF_LEN, pBuff->u32DynScalingAdd);
4511 GET_FW_BUFFADD(tmpAdr, MVD_FW_SCALER_INFO_BUF_LEN, pBuff->u32ScalerInfoAdd);
4512 GET_FW_BUFFADD(tmpAdr, MVD_FW_DECFRM_INFO_BUF_LEN, pBuff->u32DecFrmInfoAdd);
4513 GET_FW_BUFFADD(tmpAdr, MVD_FW_VBBU_TABLE_LEN, pBuff->u32VBBUTableAdd);
4514
4515
4516 MVD_DEBUGINFO(printf("set pu8MVDGetVolBufStart=%lx\n", (unsigned long)pBuff->pu8MVDGetVolBufStart));
4517 MVD_DEBUGINFO(printf("set pu8MVDGetFrameInfoBufStart=%lx\n", (unsigned long)pBuff->pu8MVDGetFrameInfoBufStart));
4518 MVD_DEBUGINFO(printf("set pu8MVDSetHeaderBufStart=%lx\n", (unsigned long)pBuff->pu8MVDSetHeaderBufStart));
4519 MVD_DEBUGINFO(printf("u32UserDataBuf start=%lx\n", (unsigned long)pBuff->u32UserDataBuf));
4520 MVD_DEBUGINFO(printf("u32MVDFWSLQTABTmpbufAdr start=%lx\n", (unsigned long)pBuff->u32MVDFWSLQTABTmpbufAdr));
4521 MVD_DEBUGINFO(printf("PtsTblAddr start=%lx\n", (unsigned long)pBuff->u32MVDFWPtsTblAddr));
4522 MVD_DEBUGINFO(printf("u32DynScalingAdd start=%lx\n", (unsigned long)pBuff->u32DynScalingAdd));
4523 MVD_DEBUGINFO(printf("ScalerInfo start=%lx end=%lx\n",
4524 (unsigned long)pBuff->u32ScalerInfoAdd, (pBuff->u32ScalerInfoAdd+MVD_FW_SCALER_INFO_BUF_LEN)));
4525 MVD_DEBUGINFO(printf("DecFrmInfo start=%lx end=%lx\n",
4526 (unsigned long)pBuff->u32DecFrmInfoAdd, (pBuff->u32DecFrmInfoAdd+MVD_FW_DECFRM_INFO_BUF_LEN)));
4527
4528 MS_U32 u32ShMemBoundary = (MVD_FW_CODE_LEN==MVD_FW_CODE_LEN_V00) ? MVD_FW_MPOOL_START_OFFSET : MVD_FW_TASK_OFFSET;
4529 #if v3_temp
4530
4531 if ((pBuff->u32VBBUTableAdd+MVD_FW_VBBU_TABLE_LEN-u32Start) > u32ShMemBoundary)
4532 {
4533 //shared memory should not overlap with FW memory pool.
4534 MVD_DEBUGERROR(printf("%s err: 0x%lx out of memory boundary!\n", __FUNCTION__,
4535 (pBuff->u32VBBUTableAdd+MVD_FW_VBBU_TABLE_LEN-u32Start)));
4536 return FALSE;
4537 }
4538 #else
4539 if ((pBuff->u32DecFrmInfoAdd+MVD_FW_DECFRM_INFO_BUF_LEN-u32Start) > u32ShMemBoundary)
4540 {
4541 //shared memory should not overlap with FW memory pool.
4542 MVD_DEBUGERROR(printf("%s err: 0x%x out of memory boundary!\n", __FUNCTION__,
4543 (pBuff->u32DecFrmInfoAdd+MVD_FW_DECFRM_INFO_BUF_LEN-u32Start)));
4544 return FALSE;
4545 }
4546 #endif
4547
4548 return TRUE;
4549 }
4550
4551 //Set buffer address to f/w
4552 //Init the memory erea if necessary
MVD_SetFWBuffAdd(MS_U8 u8Idx,MVD_FWBuff * pBuff)4553 static MS_BOOL MVD_SetFWBuffAdd(MS_U8 u8Idx, MVD_FWBuff* pBuff)
4554 {
4555 MS_U32 i;
4556 MVD_SrcMode curSrcMode = E_MVD_SRC_UNKNOWN;
4557 MVD_MEMCfg* pstMemCfg = NULL;
4558 MVD_CtrlCfg* pCtrlCfg = NULL;
4559
4560 if(pBuff == NULL)
4561 {
4562 MVD_DEBUGERROR(printf("%s err: NULL pBuff\n", __FUNCTION__));
4563 return FALSE;
4564 }
4565
4566 pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
4567
4568 MVD_DEBUGINFO(printf("\nMIU is (shm,hw,fw)=(%x,%x,%x)\n",u8SHMMiuSel,pstMemCfg->u8HWMiuSel,pstMemCfg->u8FWMiuSel));
4569
4570 curSrcMode = HAL_MVD_GetSrcMode(u8Idx);
4571
4572 HAL_MVD_SetVolInfoBufferAddr(u8Idx, pBuff->pu8MVDGetVolBufStart);
4573 _MVD_Memset(pBuff->pu8MVDGetVolBufStart, 0, MVD3_FW_VOL_INFO_BUF_LEN);
4574
4575 pBuff->u32VolAdd = pBuff->pu8MVDGetVolBufStart;
4576
4577 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,pBuff->u32VolAdd,pBuff->u32VolAdd);
4578
4579 pBuff->u32VolAdd = HAL_MVD_PA2NonCacheSeg(pBuff->u32VolAdd);
4580 MVD_DEBUGINFO(printf("gvolInfo = 0x%lx, volBuf=0x%lx\n", (unsigned long)pBuff->u32VolAdd, (unsigned long)pBuff->pu8MVDGetVolBufStart));
4581
4582 HAL_MVD_SetFrameInfoBufferAddr(u8Idx, pBuff->pu8MVDGetFrameInfoBufStart);
4583 _MVD_Memset(pBuff->pu8MVDGetFrameInfoBufStart, 0, MVD3_FW_FRAME_INFO_BUF_LEN);
4584
4585 HAL_MVD_SetHeaderBufferAddr(u8Idx, pBuff->pu8MVDSetHeaderBufStart);
4586 HAL_MVD_SetUserDataBuf(u8Idx, pBuff->u32UserDataBuf, MVD3_FW_USER_DATA_BUF_LEN);
4587 pCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
4588 pCtrlCfg->u32UsrDataRd = pBuff->u32UserDataBuf;
4589
4590
4591 if((curSrcMode != E_MVD_TS_FILE_MODE)
4592 && (curSrcMode != E_MVD_TS_MODE))
4593 {
4594 _MVD_Memset(pBuff->u32MVDFWSLQTABTmpbufAdr, 0, MVD3_FW_SLQ_TAB_TMPBUF_LEN);
4595 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWSLQTABTmpbufAdr, 0xBE010000UL);
4596 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWSLQTABTmpbufAdr+4, 0x000000FAUL);
4597
4598 HAL_MVD_SetPtsTblAddr(u8Idx, pBuff->u32MVDFWPtsTblAddr);
4599 for (i=0; i<MVD_FW_SLQTBL_PTS_BUF_LEN; i+=MVD_FW_SLQTBL_PTS_LEN)
4600 {
4601 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWPtsTblAddr+i, 0); //byteCnt
4602 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWPtsTblAddr+i+4, 0); //dummyPktCnt
4603 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWPtsTblAddr+i+8, 0); //idLow
4604 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWPtsTblAddr+i+12, 0); //idHigh
4605
4606 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWPtsTblAddr+i+16, MVD_NULLPKT_PTS); //PTS
4607 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWPtsTblAddr+i+20, 0); //reserved0
4608 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWPtsTblAddr+i+24, 0); //reserved1
4609 HAL_MVD_MemWrite4Byte(pBuff->u32MVDFWPtsTblAddr+i+28, 0); //reserved2
4610 }
4611 //MS_ASSERT((u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_BUF_LEN)<=(u32start+u32len));
4612 MVD_DEBUGINFO(printf("PTS tbl start=%lx end=%lx\n",
4613 (unsigned long)pBuff->u32MVDFWPtsTblAddr, (unsigned long)(pBuff->u32MVDFWPtsTblAddr+MVD_FW_SLQTBL_PTS_BUF_LEN)));
4614
4615 pBuff->u32VBBUTableAdd = VBBU_TABLE_START+u8Idx*0x100000;
4616 }
4617
4618 if (pstMemCfg->bEnableDynScale)
4619 {
4620 HAL_MVD_SetDynamicScaleAddr(u8Idx, pBuff->u32DynScalingAdd);
4621 HAL_MVD_EnableDynamicScale(u8Idx,0); //default old DS style
4622 pCtrlCfg->u8DynScalingDepth = 32; //HAL_MVD_GetDynamicScaleDepth
4623 MVD_DEBUGINFO(printf("u8EnableMIUSel = 0x%x\n", pMVDHalContext->stMiuCfg.u8FWMiuSel));
4624 MVD_DEBUGINFO(printf("u32DynScalingAddr= 0x%lx\n", (unsigned long)pBuff->u32DynScalingAdd));
4625 MVD_DEBUGINFO(printf("u8DynScalingDepth= 0x%x\n", pCtrlCfg->u8DynScalingDepth));
4626 }
4627 MVD_DEBUGINFO(printf("DynScaling start=%lx end=%lx\n",
4628 (unsigned long)pBuff->u32DynScalingAdd, (unsigned long)(pBuff->u32DynScalingAdd+MVD_FW_DYN_SCALE_BUF_LEN)));
4629
4630 HAL_MVD_SetDecFrmInfoAddr(u8Idx, pBuff->u32DecFrmInfoAdd);
4631
4632 MVD_RstFrmInfo(u8Idx, E_MVD_FRMINFO_DECODE);
4633 MVD_RstFrmInfo(u8Idx, E_MVD_FRMINFO_DISPLAY);
4634 MVD_DEBUGINFO(printf("DecFrmInfo start=%lx\n", (unsigned long)pBuff->u32DecFrmInfoAdd));
4635
4636 if (curSrcMode == E_MVD_SLQ_TBL_MODE)
4637 {
4638 HAL_MVD_SLQTblInit(u8Idx);
4639 }
4640
4641 return TRUE;
4642 }
4643
4644 #ifdef VDEC3
4645 #else
MVD_IsNextDispFrmRdy(MS_U8 u8Idx)4646 static MS_BOOL MVD_IsNextDispFrmRdy(MS_U8 u8Idx)
4647 {
4648 #define NXT_DISP_TIMEOUT 20000//0x20
4649 MS_U32 u32TimeOut = 0;
4650 MVD_CmdArg mvdcmd;
4651
4652 HAL_MVD_ResetHandShake(u8Idx, MVD_HANDSHAKE_GET_NXTDISPFRM);
4653 SETUP_CMDARG(mvdcmd);
4654 SET_DECNUM(mvdcmd, u8Idx);
4655 SET_CMD_RET_FALSE(CMD_GET_NEXTDISPFRM, &mvdcmd);
4656
4657 while(!HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_GET_NXTDISPFRM) && (u32TimeOut < NXT_DISP_TIMEOUT))
4658 {
4659 u32TimeOut++;
4660 }
4661 if(u32TimeOut >= NXT_DISP_TIMEOUT)
4662 {
4663 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_GET_NEXTDISPFRM ) );
4664 return FALSE;
4665 }
4666 return TRUE;
4667 }
4668 #endif
4669
HAL_MVD_GetExtDispInfo(MS_U8 u8Idx,MVD_ExtDispInfo * pInfo)4670 void HAL_MVD_GetExtDispInfo(MS_U8 u8Idx, MVD_ExtDispInfo* pInfo)
4671 {
4672 pInfo->u16VSize = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DISP_V_SIZE, sizeof(MS_U16));
4673 pInfo->u16HSize = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DISP_H_SIZE, sizeof(MS_U16));
4674 pInfo->u16VOffset = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CENTRE_V_OFFSET, sizeof(MS_U16));
4675 pInfo->u16HOffset = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CENTRE_H_OFFSET, sizeof(MS_U16));
4676 }
4677
HAL_MVD_GetFrmInfo(MS_U8 u8Idx,MVD_FrmInfoType eType,MVD_FrmInfo * pInfo)4678 E_MVD_Result HAL_MVD_GetFrmInfo(MS_U8 u8Idx, MVD_FrmInfoType eType, MVD_FrmInfo* pInfo)
4679 {
4680 MS_U32 u32Id = MVD_GetStreamId(u8Idx);
4681 MS_U8 u8VPUIdx = HAL_VPU_EX_GetTaskId(u32Id);
4682 E_MVD_Result eRet = E_MVD_RET_OK;
4683 MS_VIRT u32DecFrmInfoAdd = GET_DECFRMINFO_BUFFADD(u8Idx);
4684 #if v3_temp
4685 MVD_MEMCfg* pstMemCfg = NULL;
4686 pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
4687 #endif
4688 if (NULL == pInfo)
4689 {
4690 MVD_DEBUGERROR(printf("GetFrmInfo NULL pInfo!\n"));
4691 return E_MVD_RET_INVALID_PARAM;
4692 }
4693 if (NULL == u32DecFrmInfoAdd)
4694 {
4695 MVD_DEBUGERROR(printf("GetFrmInfo NULL u32DecFrmInfoAdd!\n"));
4696 return E_MVD_RET_FAIL;
4697 }
4698 //printf("%s u32DecFrmInfoAdd = 0x%x\n", __FUNCTION__, u32DecFrmInfoAdd);
4699
4700 if (E_MVD_FRMINFO_DECODE == eType)
4701 {
4702 pInfo->u32LumaAddr = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_LUMAADDR);
4703 pInfo->u32ChromaAddr= HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_CHROMAADDR);
4704 pInfo->u32TimeStamp = _90K_TO_MS(HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_TIMESTAMP));
4705 pInfo->u32ID_L = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_ID_L);
4706 pInfo->u32ID_H = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_ID_H);
4707 pInfo->u16Pitch = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_PITCH);
4708 pInfo->u16Width = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_WIDTH);
4709 pInfo->u16Height= HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_HEIGHT);
4710 pInfo->eFrmType = (MVD_PicType)HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DEC_FRAMETYPE);
4711 }
4712 else if (E_MVD_FRMINFO_DISPLAY == eType)
4713 {
4714 pInfo->u32LumaAddr = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_LUMAADDR);
4715 pInfo->u32ChromaAddr= HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_CHROMAADDR);
4716 pInfo->u32TimeStamp = _90K_TO_MS(HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_TIMESTAMP));
4717 pInfo->u32ID_L = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_ID_L);
4718 pInfo->u32ID_H = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_ID_H);
4719 pInfo->u16Pitch = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_PITCH);
4720 pInfo->u16Width = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_WIDTH);
4721 pInfo->u16Height= HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_HEIGHT);
4722 pInfo->eFrmType = (MVD_PicType)HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_DISP_FRAMETYPE);
4723 }
4724
4725 else if (E_MVD_FRMINFO_NEXT_DISPLAY == eType)
4726 {
4727 #if v3_temp
4728 DISPQ_IN_DRAM* pTemp = (DISPQ_IN_DRAM*)(MS_PA2KSEG1(pstMemCfg->u32FWCodeAddr+DISP_QUEUE_START+ u8VPUIdx*0x100000));
4729 if (pTemp->dispQ_rd == pTemp->dispQ_wr)
4730 {
4731 MVD_DEBUGINFO(printf("NextDispFrm not ready!\n"));
4732 return E_MVD_RET_FAIL;
4733 }
4734 pInfo->u16FrmIdx = pTemp->disp_info[pTemp->dispQ_rd].u16NextDispFrameIdx;
4735
4736 pInfo->u32LumaAddr = pTemp->disp_info[pTemp->dispQ_rd].u32NextDispLumaAddr;
4737
4738 pInfo->u32ChromaAddr= pTemp->disp_info[pTemp->dispQ_rd].u32NextDispChromaAddr;
4739 // 64BIT_PTS = (TimeStamp | (ID_H<<32)) , unit: 90K
4740 pInfo->u32TimeStamp = pTemp->disp_info[pTemp->dispQ_rd].u32NextDispTimeStamp;
4741
4742 pInfo->u32ID_H = pTemp->disp_info[pTemp->dispQ_rd].u32NextDispID_H;
4743
4744 pInfo->u16Width = pTemp->disp_info[pTemp->dispQ_rd].u16NextDispWidth;
4745
4746 if(HAL_MVD_IsMcuMode(u8Idx))
4747 {
4748 //bit[19-20] Picture format,
4749 //bit[18-17] Disp times, 1~3
4750 //bit[16] Top field first , 0-> bottom first, 1-> top first
4751 //bit[15:8] Range reduction of luma data
4752 //bit[7:0] Range reduction of chroma data
4753 pInfo->u32ID_L = (MS_U32)pTemp->disp_info[pTemp->dispQ_rd].u8NextDispRangeRed_UV
4754 | (MS_U32)(pTemp->disp_info[pTemp->dispQ_rd].u8NextDispRangeRed_Y << 8)
4755 | (MS_U32)(pTemp->disp_info[pTemp->dispQ_rd].u16ExtData << 16)
4756 | (MS_U32)(pTemp->disp_info[pTemp->dispQ_rd].u8Progressive << 19);
4757
4758 if (pInfo->u16Width & MVD_WIDTH_ALIGN_MASK)
4759 {
4760 pInfo->u16Width = ((pInfo->u16Width >> MVD_WIDTH_ALIGN_BITS) + 1) << MVD_WIDTH_ALIGN_BITS;
4761 }
4762 }
4763 else
4764 {
4765 pInfo->u32ID_L = pTemp->disp_info[pTemp->dispQ_rd].u32DispID_L;
4766 }
4767 pInfo->u16Pitch = pTemp->disp_info[pTemp->dispQ_rd].u16NextDispPitch;
4768 pInfo->u16Height= pTemp->disp_info[pTemp->dispQ_rd].u16NextDispHeight;
4769 pInfo->eFrmType = pTemp->disp_info[pTemp->dispQ_rd].u16NextDispeFrameType;
4770
4771 pTemp->bUsedByOutside[pInfo->u16FrmIdx]++;
4772
4773 pTemp->dispQ_rd = (pTemp->dispQ_rd+1)%DISPQ_SIZE;
4774 MsOS_FlushMemory();
4775 #else
4776 if (!MVD_IsNextDispFrmRdy(u8Idx))
4777 {
4778 MVD_DEBUGINFO(printf("NextDispFrm not ready!\n"));
4779 return E_MVD_RET_FAIL;
4780 }
4781 pInfo->u16FrmIdx= HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_FRAMEIDX);
4782 if (pInfo->u16FrmIdx == 0xFFFF)
4783 {
4784 MVD_DEBUGINFO(printf("GetFrmInfo no available frame!\n"));
4785 return E_MVD_RET_FAIL;
4786 }
4787 pInfo->u32LumaAddr = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_LUMAADDR);
4788 pInfo->u32ChromaAddr= HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_CHROMAADDR);
4789 // 64BIT_PTS = (TimeStamp | (ID_H<<32)) , unit: 90K
4790 pInfo->u32TimeStamp = (HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_TIMESTAMP));
4791 pInfo->u32ID_H = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_ID_H);
4792 pInfo->u16Width = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_WIDTH);
4793 if(HAL_MVD_IsMcuMode(u8Idx))
4794 {
4795 //bit[18-17] Disp times, 1~3
4796 //bit[16] Top field first , 0-> bottom first, 1-> top first
4797 //bit[15:8] Range reduction of luma data
4798 //bit[7:0] Range reduction of chroma data
4799 pInfo->u32ID_L = (MS_U32)HAL_MVD_MemReadByte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_RANGERED_UV)
4800 | (MS_U32)(HAL_MVD_MemReadByte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_RANGERED_Y) << 8)
4801 | (MS_U32)(HAL_MVD_MemReadByte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_EXT_DATA) << 16);
4802 if (pInfo->u16Width & MVD_WIDTH_ALIGN_MASK)
4803 {
4804 pInfo->u16Width = ((pInfo->u16Width >> MVD_WIDTH_ALIGN_BITS) + 1) << MVD_WIDTH_ALIGN_BITS;
4805 }
4806 }
4807 else
4808 {
4809 pInfo->u32ID_L = HAL_MVD_MemRead4Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_ID_L);
4810 }
4811 pInfo->u16Pitch = HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_PITCH);
4812 pInfo->u16Height= HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_HEIGHT);
4813 pInfo->eFrmType = (MVD_PicType)HAL_MVD_MemRead2Byte(u32DecFrmInfoAdd + OFFSET_DECFRAMEINFO_NEXTDISP_FRAMETYPE);
4814 #endif
4815 #if 0
4816 printf("NxtFrm:: Idx=0x%x, ", pInfo->u16FrmIdx);
4817 printf("Type=0x%x, ", pInfo->eFrmType );
4818 printf("Luma=0x%x, ", pInfo->u32LumaAddr );
4819 printf("Chroma=0x%x, ", pInfo->u32ChromaAddr);
4820 printf("Pts=%lu, ", pInfo->u32TimeStamp );
4821 printf("ID_H=%lu, ", pInfo->u32ID_H );
4822 printf("ID_L=0x%x\n", pInfo->u32ID_L );
4823 #endif
4824 MVD_DBG_STS(printf("<<< drvMVD pts,idH = %lu, %lu\n", pInfo->u32TimeStamp, pInfo->u32ID_H));
4825 }
4826 else
4827 {
4828 eRet = E_MVD_RET_INVALID_PARAM;
4829 }
4830
4831 if ((pInfo->u32LumaAddr == _INIT_ADDR) || (pInfo->u32ChromaAddr== _INIT_ADDR) ||
4832 (pInfo->u16Pitch == _INIT_LEN) || (pInfo->u16Width == _INIT_LEN) ||
4833 (pInfo->u16Height== _INIT_LEN))
4834 {
4835 MVD_DEBUGINFO(printf("GetFrmInfo not ready!\n"));
4836 return E_MVD_RET_FAIL;
4837 }
4838
4839 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,(pInfo->u32LumaAddr * 8),pInfo->u32LumaAddr);
4840 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,(pInfo->u32ChromaAddr * 8),pInfo->u32ChromaAddr);
4841
4842 //printf("===> Luma=0x%x, Chroma=0x%x\n", pInfo->u32LumaAddr, pInfo->u32ChromaAddr);
4843 return eRet;
4844 }
4845
4846
4847
HAL_MVD_SetDynScalingParam(MS_U8 u8Idx,MS_PHY u32StAddr,MS_SIZE u32Size)4848 E_MVD_Result HAL_MVD_SetDynScalingParam(MS_U8 u8Idx, MS_PHY u32StAddr, MS_SIZE u32Size)
4849 {
4850 #define SCALER_INFO_TIMEOUT 0x1000
4851 MS_U32 u32TimeOut = 0;
4852 MS_VIRT u32SrcAdd = NULL;
4853 MS_U32 i;
4854 MS_VIRT u32ScalerInfoAdd = GET_XCINFO_BUFFADD(u8Idx);
4855 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
4856
4857 if ((u32StAddr==NULL) || (u32Size==0) || (u32Size>MVD_FW_SCALER_INFO_BUF_LEN))
4858 {
4859 MVD_DEBUGERROR(printf("%s invalid para u32StAddr=0x%lx, u32Size=0x%lx\n",
4860 __FUNCTION__, (unsigned long)u32StAddr, (unsigned long)u32Size));
4861 return E_MVD_RET_INVALID_PARAM;
4862 }
4863 if (TRUE != pstMemCfg->bEnableDynScale)
4864 {
4865 MVD_DEBUGERROR(printf("%s !bEnableDynScale\n", __FUNCTION__));
4866 return E_MVD_RET_FAIL;
4867 }
4868
4869 //copy data
4870 u32SrcAdd = HAL_MVD_PA2NonCacheSeg(u32StAddr);
4871 u32Size = ((u32Size+3)>>2)<<2;
4872 MVD_DEBUGINFO(printf("u32Size= 0x%lx, u32SrcAdd= 0x%lx\n", (unsigned long)u32Size, (unsigned long)u32SrcAdd));
4873 for (i=0; i<u32Size; i=i+4)
4874 {
4875 HAL_MVD_MemWrite4Byte(u32ScalerInfoAdd+i, *(volatile MS_U32*)(u32SrcAdd+i));
4876 MVD_DEBUGINFO(printf("0x%lx = 0x%x\n", (unsigned long)(u32ScalerInfoAdd+i), HAL_MVD_MemRead4Byte(u32ScalerInfoAdd+i)));
4877 }
4878
4879 //notify f/w
4880 HAL_MVD_ResetHandShake(u8Idx, MVD_HANDSHAKE_SCALER_INFO);
4881 if (TRUE!=HAL_MVD_SetScalerInfoAddr(u8Idx, u32ScalerInfoAdd,((MS_U8*)u32SrcAdd)[0])) //Set the buffer address (MIU offset) to f/w
4882 {
4883 MVD_DEBUGERROR(printf("%s fail to set ScalerInfoAdd\n", __FUNCTION__));
4884 return E_MVD_RET_FAIL;
4885 }
4886
4887 //check f/w already handle the data
4888 while((TRUE!=HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_SCALER_INFO)) && (u32TimeOut < SCALER_INFO_TIMEOUT))
4889 {
4890 u32TimeOut++;
4891 }
4892 if(u32TimeOut >= SCALER_INFO_TIMEOUT)
4893 {
4894 MVD_DEBUGERROR(printf("%s timeout!!!\n", __FUNCTION__));
4895 return E_MVD_RET_FAIL;
4896 }
4897
4898 //clear ack bit
4899 HAL_MVD_ClearCmdFinished(u8Idx, MVD_HANDSHAKE_SCALER_INFO);
4900
4901 MVD_DEBUGINFO(printf("=====> %s u32TimeOut = 0x%x\n", __FUNCTION__, u32TimeOut));
4902 return E_MVD_RET_OK;
4903 }
4904
4905 //Map driver CodecType to firmware CodecType
MVD_MapCodecType(MVD_CodecType type)4906 static MS_U8 MVD_MapCodecType(MVD_CodecType type)
4907 {
4908 MS_U8 u8type = 0xff;
4909 switch (type)
4910 {
4911 case E_MVD_CODEC_MPEG2:
4912 u8type = CODEC_MPEG2;
4913 break;
4914 case E_MVD_CODEC_MPEG4:
4915 u8type = CODEC_MPEG4;
4916 break;
4917 case E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER:
4918 u8type = CODEC_MPEG4_SHORT_VIDEO_HEADER;
4919 break;
4920 case E_MVD_CODEC_DIVX311:
4921 u8type = CODEC_DIVX311;
4922 break;
4923
4924 case E_MVD_CODEC_FLV:
4925 u8type = 0x03;
4926 break;
4927
4928 case E_MVD_CODEC_VC1_MAIN: //RCV
4929 u8type = 0x05;
4930 break;
4931
4932 case E_MVD_CODEC_VC1_ADV: //VC1
4933 u8type = 0x04;
4934 break;
4935
4936 default:
4937 break;
4938 }
4939
4940 return u8type;
4941 }
4942
4943 //Map driver SrcType to firmware SrcType
MVD_MapSrcMode(MVD_SrcMode mode)4944 static MS_U8 MVD_MapSrcMode(MVD_SrcMode mode)
4945 {
4946 MS_U8 u8mode = 0xff;
4947 switch (mode)
4948 {
4949 case E_MVD_TS_MODE:
4950 u8mode = STREAM_MODE;
4951 break;
4952 case E_MVD_FILE_MODE:
4953 u8mode = FILE_MODE;
4954 break;
4955 case E_MVD_SLQ_MODE:
4956 u8mode = SLQ_MODE;
4957 break;
4958 case E_MVD_SLQ_TBL_MODE:
4959 u8mode = SLQ_TBL_MODE;
4960 break;
4961 case E_MVD_TS_FILE_MODE:
4962 u8mode = TS_FILE_MODE;
4963 break;
4964
4965 default:
4966 break;
4967 }
4968
4969 return u8mode;
4970 }
4971
4972
MVD_CheckFrmBuffSizeMin(MVD_FWCfg * fwCfg,MVD_MEMCfg * memCfg)4973 static MS_BOOL MVD_CheckFrmBuffSizeMin(MVD_FWCfg* fwCfg, MVD_MEMCfg* memCfg)
4974 {
4975 MS_BOOL ret = TRUE;
4976
4977 if (_IS_VC1(fwCfg->eCodecType))
4978 {
4979 MVD_DEBUGERROR(printf("Framebuffer size(0x%lx) < (0x%x+0x%lx)!\n",
4980 (unsigned long)memCfg->u32FBSize, (MVD_HD_FBSIZE*MVD_FBNUM_MIN), MVD_HW_BUF_TOTAL_LEN));
4981 ret = FALSE;
4982 }
4983 else if (memCfg->u32FBSize < (MVD4_MPEG_FBSIZE_SDMIN+MVD_HW_BUF_TOTAL_LEN))
4984 {
4985 MVD_DEBUGERROR(printf("Framebuffer size(0x%lx) < (0x%x+0x%lx)\n",
4986 (unsigned long)memCfg->u32FBSize, MVD4_MPEG_FBSIZE_SDMIN, MVD_HW_BUF_TOTAL_LEN));
4987 ret = FALSE;
4988 }
4989 return ret;
4990 }
4991
MVD_GetUsedFrmBuffSize(MS_U8 u8FBMode,MS_U8 u8FBNum)4992 MS_U32 MVD_GetUsedFrmBuffSize(MS_U8 u8FBMode, MS_U8 u8FBNum)
4993 {
4994 MS_U32 u32Size = 0;
4995 if (MVD3_DHD_MODE == u8FBMode)
4996 {
4997 u32Size = MVD_DHD_FBSIZE;
4998 if (MVD_FBNUM_MAX == u8FBNum)
4999 {
5000 u32Size *= MVD_FBNUM_MAX;
5001 }
5002 else if (MVD_FBNUM_MIN == u8FBNum)
5003 {
5004 u32Size *= MVD_FBNUM_MIN;
5005 }
5006 }
5007 else if (MVD3_HD_MODE == u8FBMode)
5008 {
5009 u32Size = MVD_HD_FBSIZE;
5010 if (MVD_FBNUM_MAX == u8FBNum)
5011 {
5012 u32Size *= MVD_FBNUM_MAX;
5013 }
5014 else if (MVD_FBNUM_MIN == u8FBNum)
5015 {
5016 u32Size *= MVD_FBNUM_MIN;
5017 }
5018 }
5019 else if (MVD3_SD_MODE == u8FBMode)
5020 {
5021 u32Size = MVD4_MPEG_FBSIZE_SDMIN;
5022 }
5023 return u32Size;
5024 }
5025
5026 //------------------------------------------------------------------------------
5027 /// Determine u8FBMode & u8FBNum according to the assigned FBSize
5028 //------------------------------------------------------------------------------
HAL_MVD_CheckFrmBuffSize(MS_U8 u8Idx,MVD_FWCfg * fwCfg,MVD_MEMCfg * memCfg)5029 MS_BOOL HAL_MVD_CheckFrmBuffSize(MS_U8 u8Idx, MVD_FWCfg* fwCfg, MVD_MEMCfg* memCfg)
5030 {
5031 MS_BOOL ret = TRUE;
5032 MS_U8* pu8FBMode = &(fwCfg->u8FBMode);
5033 MS_U8* pu8FBNum = &(fwCfg->u8FBNum);
5034 MS_U32 u32AvailFrmBuffSize = memCfg->u32FBSize - MVD_HW_BUF_TOTAL_LEN;
5035
5036 ret = MDrv_MVD_AUTH_IPCheck(fwCfg->eCodecType,&(memCfg->bSupportSDModeOnly));
5037 if(ret == FALSE)
5038 {
5039 return FALSE;
5040 }
5041
5042 *pu8FBMode = 0xff;
5043
5044 #if defined(MVD_SUPPORT_SD_ONLY)
5045 *pu8FBMode = MVD3_SD_MODE;
5046 #else
5047 if(memCfg->bSupportSDModeOnly)
5048 {
5049 *pu8FBMode = MVD3_SD_MODE;
5050 }
5051 #endif //MVD_SUPPORT_SD_ONLY
5052
5053 //For SD only cases: defined(MVD_SUPPORT_SD_ONLY) and bSupportSDModeOnly
5054 if (MVD3_SD_MODE == *pu8FBMode)
5055 {
5056 ret = MVD_CheckFrmBuffSizeMin(fwCfg, memCfg);
5057
5058 //set frmBuffNum as 4
5059 *pu8FBNum = MVD_FBNUM_MIN;
5060 MVD_DEBUGINFO(printf("[MVD_SD_MODE] u8FBNum=%d, FBSize=0x%lx\n", *pu8FBNum, (unsigned long)memCfg->u32FBSize));
5061 goto _GET_USED_SIZE;
5062 }
5063
5064 if (u32AvailFrmBuffSize >= (MVD_DHD_FBSIZE*MVD_FBNUM_MAX))
5065 {
5066 MVD_DEBUGINFO(printf("%s(%d) DHD*5\n", __FUNCTION__, __LINE__));
5067 //Dual HD: (1920*2)*1088 or 1920*(1088*2)
5068 if (!_IS_VC1(fwCfg->eCodecType)) //mpeg2/4
5069 {
5070 *pu8FBMode = MVD3_DHD_MODE;
5071 }
5072 else
5073 {
5074 *pu8FBMode = MVD3_DHD_MODE_MIN;
5075 }
5076 *pu8FBNum = MVD_FBNUM_MAX;
5077 }
5078 else if (u32AvailFrmBuffSize >= (MVD_DHD_FBSIZE*MVD_FBNUM_MIN))
5079 {
5080 MVD_DEBUGINFO(printf("%s(%d) DHD*4\n", __FUNCTION__, __LINE__));
5081 //Dual HD: (1920*2)*1088 or 1920*(1088*2)
5082 if (!_IS_VC1(fwCfg->eCodecType)) //mpeg2/4
5083 {
5084 *pu8FBMode = MVD3_DHD_MODE;
5085 }
5086 else
5087 {
5088 *pu8FBMode = MVD3_DHD_MODE_MIN;
5089 }
5090 *pu8FBNum = MVD_FBNUM_MIN;
5091 }
5092 else if (u32AvailFrmBuffSize >= (MVD_HD_FBSIZE*MVD_FBNUM_MAX))
5093 {
5094 MVD_DEBUGINFO(printf("%s(%d) HD*5\n", __FUNCTION__, __LINE__));
5095 *pu8FBMode = MVD3_HD_MODE;
5096 *pu8FBNum = MVD_FBNUM_MAX;
5097 }
5098 else if (u32AvailFrmBuffSize >= (MVD_HD_FBSIZE*MVD_FBNUM_MIN))
5099 {
5100 MVD_DEBUGINFO(printf("%s(%d) HD*4\n", __FUNCTION__, __LINE__));
5101 *pu8FBMode = MVD3_HD_MODE;
5102 *pu8FBNum = MVD_FBNUM_MIN;
5103 }
5104 else
5105 {
5106 MVD_DEBUGINFO(printf("%s(%d) SD\n", __FUNCTION__, __LINE__));
5107 ret = MVD_CheckFrmBuffSizeMin(fwCfg, memCfg);
5108 if (TRUE == ret)
5109 {
5110 *pu8FBMode = MVD3_SD_MODE;
5111 *pu8FBNum = MVD_FBNUM_MIN;
5112 MVD_DEBUGINFO(printf("Framebuffer [SD] mode\n"));
5113 }
5114 }
5115
5116
5117 //Keep FBNum=4 for mpeg2/4, not-mstreamer/uniplayer/mcu mode.
5118 if (!_IS_VC1(fwCfg->eCodecType)) //mpeg2/4
5119 {
5120 if (*pu8FBNum != MVD_FBNUM_DEFAULT)
5121 {
5122 *pu8FBNum = MVD_FBNUM_DEFAULT;
5123 }
5124 }
5125
5126 _GET_USED_SIZE:
5127 fwCfg->u32FBUsedSize = u32AvailFrmBuffSize;
5128
5129 MVD_DEBUGINFO(printf("%s u8FBMode=0x%x, u8FBNum=%d, FBSize=0x%lx, used=0x%lx\n",
5130 __FUNCTION__, fwCfg->u8FBMode, fwCfg->u8FBNum, (unsigned long)memCfg->u32FBSize, (unsigned long)fwCfg->u32FBUsedSize));
5131 return ret;
5132 }
5133
HAL_MVD_SetCodecInfo(MS_U8 u8Idx,MVD_CodecType eCodecType,MVD_SrcMode eSrcMode,MS_U8 bDisablePESParsing)5134 MS_BOOL HAL_MVD_SetCodecInfo(MS_U8 u8Idx, MVD_CodecType eCodecType, MVD_SrcMode eSrcMode, MS_U8 bDisablePESParsing)
5135 {
5136 MVD_CmdArg stCmdArg;
5137 //printf("u8CodecType=0x%x\n", u8CodecType);
5138 //printf("eSrcMode=0x%x\n", eSrcMode);
5139 SETUP_CMDARG(stCmdArg);
5140 stCmdArg.Arg0 = MVD_MapCodecType(eCodecType);
5141 stCmdArg.Arg1 = MVD_MapSrcMode(eSrcMode);
5142 stCmdArg.Arg2 = bDisablePESParsing;
5143 //arg2 is only valid for STREAM_MODE and TS_FILE_MODE
5144 //set as 0 to enable MVD parser and parser interrupt
5145 stCmdArg.Arg3 = 0;
5146 MVD_DEBUGINFO(printf("MDrv_MVD_SetCodecInfo: Cmd: %x, Arg0: %x, Arg1: %x. Arg2: %x\n",
5147 CMD_CODEC_INFO, stCmdArg.Arg0, stCmdArg.Arg1, stCmdArg.Arg2));
5148 SET_DECNUM(stCmdArg, u8Idx);
5149 SET_CMD_RET_FALSE(CMD_CODEC_INFO, &stCmdArg);
5150
5151 HAL_MVD_SetSrcMode(u8Idx,eSrcMode);
5152
5153 //set code offset to MVD
5154 MS_VIRT u32Addr, u32Len;
5155 HAL_MVD_MemGetMap(u8Idx, E_MVD_MMAP_FW, &u32Addr, &u32Len);
5156
5157 if (u32Len==0) printf("%s err: u32Len=0!\n", __FUNCTION__);
5158 MS_U32 i=0;
5159 i = u32Addr >> 3;
5160 SET_CMDARG(stCmdArg, i, u8Idx);
5161 SET_CMD_RET_FALSE(CMD_CODE_OFFSET, &stCmdArg);
5162
5163 #define _mvdAssert(x) if(!x) printf("%s(%d) inconsistent cfg!\n", __FUNCTION__, __LINE__);
5164 MVD_FWCfg* pCurFwCfg = HAL_MVD_GetFWCfg(u8Idx);
5165 _mvdAssert(pCurFwCfg->eCodecType == eCodecType);
5166 _mvdAssert(pCurFwCfg->eSrcMode == eSrcMode);
5167 _mvdAssert(pCurFwCfg->bDisablePESParsing == bDisablePESParsing);
5168
5169 //Refer to msAPI_VDPlayer_DecodeMPEG4.c (core\kernel\api\videoplayer)
5170 if (eSrcMode == E_MVD_SLQ_TBL_MODE)
5171 {
5172 if ((eCodecType == E_MVD_CODEC_MPEG4) ||
5173 (eCodecType == E_MVD_CODEC_DIVX311) ||
5174 (eCodecType == E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER))
5175 {
5176 // Enable PackMode
5177 SETUP_CMDARG(stCmdArg);
5178 stCmdArg.Arg0 = 3;
5179 SET_DECNUM(stCmdArg, u8Idx);
5180 if (HAL_MVD_MVDCommand( CMD_PARSE_M4V_PACKMD, &stCmdArg ) == FALSE)
5181 {
5182 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PARSE_M4V_PACKMD ) );
5183 return FALSE;
5184 }
5185
5186 // Set DIU width of rounding mode (align to 8byte)
5187 SETUP_CMDARG(stCmdArg);
5188 stCmdArg.Arg0 = 1;
5189 SET_DECNUM(stCmdArg, u8Idx);
5190 if (HAL_MVD_MVDCommand(CMD_DIU_WIDTH_ALIGN, &stCmdArg) == FALSE)
5191 {
5192 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DIU_WIDTH_ALIGN ) );
5193 return FALSE;
5194 }
5195 }
5196 }
5197
5198 //set internal buffers after setting codecinfo for V3
5199 if (!HAL_MVD_SetInternalBuffAddr(u8Idx, u32Addr, u32Len))
5200 {
5201 MVD_DEBUGERROR(printf("MDrv_MVD_Init:_MVD_MVDSetInternalBuffAddr failed\n"));
5202 return FALSE;
5203 }
5204 else
5205 {
5206 MVD_DEBUGINFO(printf("MDrv_MVD_Init:_MVD_MVDSetInternalBuffAddr success\n"));
5207 }
5208
5209 return TRUE;
5210 }
5211
MVD_GetBDMAType(void)5212 BDMA_CpyType MVD_GetBDMAType(void)
5213 {
5214 BDMA_CpyType bdmaCpyType = E_BDMA_CPYTYPE_MAX;
5215
5216 if (pMVDHalContext->stMiuCfg.u8HWMiuSel == MIU_SEL_0)
5217 {
5218 if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_0)
5219 {
5220 bdmaCpyType = E_BDMA_SDRAM2SDRAM;
5221 }
5222 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_1)
5223 {
5224 bdmaCpyType = E_BDMA_SDRAM2SDRAM1;
5225 }
5226 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_2)
5227 {
5228 bdmaCpyType = E_BDMA_SDRAM2SDRAM2;
5229 }
5230 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_3)
5231 {
5232 bdmaCpyType = E_BDMA_SDRAM2SDRAM3;
5233 }
5234 else
5235 {
5236 MS_ASSERT(0);
5237 }
5238 }
5239 else if (pMVDHalContext->stMiuCfg.u8HWMiuSel == MIU_SEL_1)
5240 {
5241 if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_0)
5242 {
5243 bdmaCpyType = E_BDMA_SDRAM12SDRAM;
5244 }
5245 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_1)
5246 {
5247 bdmaCpyType = E_BDMA_SDRAM12SDRAM1;
5248 }
5249 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_2)
5250 {
5251 bdmaCpyType = E_BDMA_SDRAM12SDRAM2;
5252 }
5253 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_3)
5254 {
5255 bdmaCpyType = E_BDMA_SDRAM12SDRAM3;
5256 }
5257 else
5258 {
5259 MS_ASSERT(0);
5260 }
5261 }
5262 else if (pMVDHalContext->stMiuCfg.u8HWMiuSel == MIU_SEL_2)
5263 {
5264 if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_0)
5265 {
5266 bdmaCpyType = E_BDMA_SDRAM22SDRAM;
5267 }
5268 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_1)
5269 {
5270 bdmaCpyType = E_BDMA_SDRAM22SDRAM1;
5271 }
5272 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_2)
5273 {
5274 bdmaCpyType = E_BDMA_SDRAM22SDRAM2;
5275 }
5276 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_3)
5277 {
5278 bdmaCpyType = E_BDMA_SDRAM22SDRAM3;
5279 }
5280 else
5281 {
5282 MS_ASSERT(0);
5283 }
5284 }
5285 else if (pMVDHalContext->stMiuCfg.u8HWMiuSel == MIU_SEL_3)
5286 {
5287 if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_0)
5288 {
5289 bdmaCpyType = E_BDMA_SDRAM32SDRAM;
5290 }
5291 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_1)
5292 {
5293 bdmaCpyType = E_BDMA_SDRAM32SDRAM1;
5294 }
5295 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_2)
5296 {
5297 bdmaCpyType = E_BDMA_SDRAM32SDRAM2;
5298 }
5299 else if (pMVDHalContext->stMiuCfg.u8FWMiuSel == MIU_SEL_3)
5300 {
5301 bdmaCpyType = E_BDMA_SDRAM32SDRAM3;
5302 }
5303 else
5304 {
5305 MS_ASSERT(0);
5306 }
5307 }
5308 else
5309 {
5310 MS_ASSERT(0);
5311 }
5312
5313 return bdmaCpyType;
5314 }
5315
5316 //Init static variables.
5317 //Exception: stMemCfg & stMiuCfg since they are set before calling this function.
HAL_MVD_InitVar(MS_U8 u8Idx)5318 void HAL_MVD_InitVar(MS_U8 u8Idx)
5319 {
5320 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
5321 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
5322
5323 memset(pstCtrlCfg, 0, sizeof(MVD_CtrlCfg));
5324 pstCtrlCfg->eTrickMode = E_MVD_TRICK_DEC_ALL;
5325 pstCtrlCfg->eFrcMode = E_MVD_FRC_NORMAL;
5326 pstCtrlCfg->ePreSpeedType = E_MVD_SPEED_DEFAULT;
5327 pstCtrlCfg->eFileSyncMode = E_MVD_TIMESTAMP_FREERUN;
5328
5329 //determine if we need to BDMA SLQ table from DrvProcBuff to BitstreamBuff
5330 #ifndef MSOS_TYPE_LINUX_KERNEL//BDMA
5331 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
5332 pstCtrlCfg->bSlqTblSync = ((pstMemCfg->u32DrvBufAddr < pstMemCfg->u32BSAddr) ||
5333 ((pstMemCfg->u32DrvBufAddr+pstMemCfg->u32DrvBufSize) > (pstMemCfg->u32BSAddr+pstMemCfg->u32BSSize)));
5334 MVD_DEBUGINFO(printf("bSlqTblSync = %x\n", pstCtrlCfg->bSlqTblSync));
5335 if (pstCtrlCfg->bSlqTblSync)
5336 {
5337 const BDMA_Info* pBDMA;
5338 pBDMA = MDrv_BDMA_GetInfo();
5339 if ((pBDMA == NULL) || (pBDMA->bInit != TRUE))
5340 {
5341 if (E_BDMA_OK != MDrv_BDMA_Init(pstMemCfg->u32Miu1BaseAddr))
5342 {
5343 printf("%s fail at MDrv_BDMA_Init!!!\n", __FUNCTION__);
5344 }
5345 }
5346 pstSlqTblInfo->bdmaCpyType = MVD_GetBDMAType();
5347 }
5348 #else
5349 pstCtrlCfg->bSlqTblSync = 0;
5350 #endif
5351 memset(pstSlqTblInfo, 0, sizeof(MVD_SLQTBLInfo));
5352 pstSlqTblInfo->u32LastPts = MVD_NULLPKT_PTS;
5353 pstSlqTblInfo->u32PreEsRd = MVD_U32_MAX;
5354 pstSlqTblInfo->u32PreEsWr = 0;
5355 pstSlqTblInfo->pSlqStatus = &(pMVDHalContext->_SlqStatus[u8Idx]);
5356 pstSlqTblInfo->pDrvSlqTbl = &(pMVDHalContext->_drvSlqTbl[u8Idx]);
5357 pstSlqTblInfo->pDrvEsTbl = &(pMVDHalContext->_drvEsTbl[u8Idx]);
5358 pstSlqTblInfo->pDrvDivxTbl = &(pMVDHalContext->_drvDivxTbl[u8Idx]);
5359 #if SLQ_NEW_PUSH
5360 pstSlqTblInfo->pSlqStatus->u32SlqPatternAddr = 0;
5361 pstSlqTblInfo->pSlqStatus->u32SlqPushLength = 0;
5362 pstSlqTblInfo->pSlqStatus->bSlqPicStart = FALSE;
5363 pstSlqTblInfo->pSlqStatus->bSlqPicCollect = FALSE;
5364 pstSlqTblInfo->pSlqStatus->bSlqPicWaitNextStart = FALSE;
5365 pstSlqTblInfo->pSlqStatus->bSlqEnLastFrameShow =FALSE;
5366 pstSlqTblInfo->pSlqStatus->bSlqFireRdy = FALSE;
5367 pstSlqTblInfo->pSlqStatus->bSlqCtrlBit =FALSE;
5368 #endif
5369 }
5370
5371 //------------------------------------------------------------------------------
5372 /// Issue Stop command.
5373 //------------------------------------------------------------------------------
HAL_MVD_Stop(MS_U8 u8Idx)5374 MS_BOOL HAL_MVD_Stop(MS_U8 u8Idx)
5375 {
5376 MVD_CmdArg mvdcmd;
5377 MS_BOOL bRet = TRUE;
5378
5379 #define STOP_TIMEOUT 500 //ms
5380 MS_U32 u32StartTime = 0;
5381 u32StartTime = HAL_MVD_GetTime();
5382
5383 SETUP_CMDARG(mvdcmd);
5384 SET_DECNUM(mvdcmd, u8Idx);
5385 HAL_MVD_ResetHandShake(u8Idx, MVD_HANDSHAKE_STOP);
5386
5387 if (HAL_MVD_MVDCommand(CMD_STOP, &mvdcmd) == FALSE)
5388 {
5389 MVD_DEBUGERROR(printf("Command: 0x%x fail!!\r\n", CMD_STOP));
5390 HAL_MVD_Delayms(1);
5391 if ( HAL_MVD_TimeOut(u8Idx) == TRUE )
5392 {
5393 MVD_DEBUGERROR(printf("*** MVD ERR: STOP TIMEOUT!!! ***\n"));
5394 }
5395 }
5396
5397 while(!HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_STOP))
5398 {
5399 if ((HAL_MVD_GetTime()-u32StartTime)>STOP_TIMEOUT)
5400 {
5401 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail timeout!!\r\n", CMD_STOP ) );
5402 break;
5403 }
5404 }
5405
5406 pMVDHalContext->bStopped[u8Idx] = TRUE;
5407 return bRet;
5408 }
5409
HAL_MVD_DeinitHW(void)5410 MS_BOOL HAL_MVD_DeinitHW(void)
5411 {
5412 //MVD HW reset
5413 if (!HAL_MVD_RstHW())
5414 {
5415 MVD_DEBUGERROR(printf("MDrv_MVD_Exit:MVD4ResetHW failed\n"));
5416 }
5417 else
5418 {
5419 MVD_DEBUGINFO(printf("MDrv_MVD_Exit:MVD4ResetHW success\n"));
5420 }
5421 HAL_MVD_PowerCtrl(DISABLE);
5422 return TRUE;
5423 }
5424
HAL_MVD_Exit(MS_U8 u8Idx)5425 MS_BOOL HAL_MVD_Exit(MS_U8 u8Idx)
5426 {
5427 MVD_DEBUGINFO(printf("MDrv_MVD_Exit:start\n"));
5428
5429 HAL_MVD_SetIsUsed(u8Idx, FALSE);
5430 pMVDHalContext->bAutoInsertDummyPattern[u8Idx] = FALSE;
5431 pMVDHalContext->bDropOnePTS[u8Idx] = FALSE;
5432 pMVDHalContext->u32DmxFrameRate[u8Idx] = 0;
5433 pMVDHalContext->u32DmxFrameRateBase[u8Idx] = 0;
5434
5435 return TRUE;
5436 }
5437
5438
5439 //------------------------------------------------------------------------------
5440 /// Set DivX311 stream info.
5441 /// @param divxInfo \b IN : DivX311 stream info.
5442 //------------------------------------------------------------------------------
MVD_WriteDivx311Data(MS_U8 u8Idx,FW_DIVX_INFO * divxInfo)5443 static void MVD_WriteDivx311Data(MS_U8 u8Idx, FW_DIVX_INFO *divxInfo)
5444 {
5445 MS_VIRT pu8MVDSetHeaderBufStart = GET_HDR_BUFFADD(u8Idx);
5446 HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_VOL_HANDLE_DONE,divxInfo->vol_handle_done);
5447 HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_WIDTH,divxInfo->width);
5448 HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_HEIGHT,divxInfo->height);
5449 HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_FRAME_COUNT,divxInfo->frame_count);
5450 HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_FRAME_TIME,divxInfo->frame_time);
5451 HAL_MVD_MemWrite2Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_PTS_INCR,divxInfo->pts_incr);
5452 HAL_MVD_MemWrite4Byte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_FRAME_RATE,divxInfo->frame_rate);
5453 HAL_MVD_MemWriteByte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_ASPECT_RATIO,divxInfo->aspect_ratio);
5454 HAL_MVD_MemWriteByte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_PROGRESSIVE_SEQUENCE,divxInfo->progressive_sequence);
5455 HAL_MVD_MemWriteByte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_MPEG1,divxInfo->mpeg1);
5456 HAL_MVD_MemWriteByte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_PLAY_MODE,divxInfo->play_mode);
5457 HAL_MVD_MemWriteByte(pu8MVDSetHeaderBufStart+OFFSET_DIVX_MPEG_FRC_MODE,divxInfo->mpeg_frc_mode);
5458 return;
5459 }
5460
HAL_MVD_SetFrameInfo(MS_U8 u8Idx,MVD_FrameInfo * pinfo)5461 void HAL_MVD_SetFrameInfo(MS_U8 u8Idx, MVD_FrameInfo *pinfo )
5462 {
5463 if (GET_HDR_BUFFADD(u8Idx)==0)
5464 {
5465 MVD_DEBUGERROR(printf("MDrv_MVD_SetFrameInfo error: pu8MVDSetHeaderBufStart=NULL\n"));
5466 return;
5467 }
5468
5469 FW_DIVX_INFO* pDivxInfo = &(pMVDHalContext->gdivxInfo[u8Idx]);
5470 pDivxInfo->width=pinfo->u16HorSize;
5471 pDivxInfo->height=pinfo->u16VerSize;
5472 pDivxInfo->aspect_ratio=pinfo->u8AspectRate;
5473 pDivxInfo->frame_rate = pinfo->u32FrameRate;
5474
5475 //for MM
5476 pDivxInfo->mpeg1=pinfo->u8MPEG1;
5477 pDivxInfo->pts_incr=pinfo->u16PTSInterval;
5478 pDivxInfo->play_mode=pinfo->u8PlayMode;
5479 pDivxInfo->mpeg_frc_mode=pinfo->u8FrcMode;
5480
5481 if(pinfo->u8Interlace==0)
5482 pDivxInfo->progressive_sequence=1;
5483 else
5484 pDivxInfo->progressive_sequence=0;
5485
5486 pDivxInfo->frame_count=0;
5487 pDivxInfo->frame_time=0;
5488 pDivxInfo->vol_handle_done=0;
5489 // pDivxInfo->invalidstream=0;
5490 MVD_DEBUGINFO(printf("set vol info,pts_incr=%d,\n",pDivxInfo->pts_incr));
5491 MVD_DEBUGINFO(printf("set vol info,width=%x,height=%x,frame_rate=%d,aspect_ratio=%x,\n",
5492 (unsigned int)pDivxInfo->width,(unsigned int)pDivxInfo->height,pDivxInfo->frame_rate,pDivxInfo->aspect_ratio));
5493 MVD_DEBUGINFO(printf("set vol info,progressive_sequence=%x,mpeg1=%x,play_mode=%x,\n",
5494 pDivxInfo->progressive_sequence,pDivxInfo->mpeg1,pDivxInfo->play_mode));
5495
5496 MVD_WriteDivx311Data(u8Idx, pDivxInfo);
5497 return;
5498 }
5499
5500
5501
5502 ///////////////////////////////////////////////////////////////////////////////
5503 /// Get Hardware Pointer of MVD CC Ring Buffer
5504 /// Return value:: The HW Pointer Address of MVD CC Ring Buffer
5505 /// @param u8CC608 \b IN
5506 /// - # TRUE for CC608 parser
5507 /// - # FALSE for CC708 parser
5508 ///////////////////////////////////////////////////////////////////////////////
HAL_CC_CM_GetMVDRB_HWAddr(MS_U8 u8CC608)5509 MS_VIRT HAL_CC_CM_GetMVDRB_HWAddr(MS_U8 u8CC608)
5510 {
5511 #if 1
5512 MVD_CmdArg mvdcmd;
5513 MS_VIRT u32CCWrPtr = 0;
5514
5515 SETUP_CMDARG(mvdcmd);
5516 mvdcmd.Arg3 = u8CC608;
5517 if (HAL_MVD_MVDCommand( CMD_RD_USER_WP, &mvdcmd ) == FALSE)
5518 {
5519 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_RD_USER_WP ) );
5520 return MVD_U32_MAX;
5521 }
5522 u32CCWrPtr = COMBU32(mvdcmd.Arg3, mvdcmd.Arg2, mvdcmd.Arg1, mvdcmd.Arg0);
5523 return u32CCWrPtr;
5524 #else
5525 MS_U32 u32MVDCC_Temp1 = 0;
5526 if (HAL_MVD_TimeOut(pstCmdArg->Arg5) == FALSE)
5527 {
5528 //HAL_MVD_ARGINIT();
5529 HAL_MVD_RegWriteByte(MVD_ARG5, 0);
5530 HAL_MVD_RegWriteByte(MVD_ARG4, 0);
5531 HAL_MVD_RegWriteByte(MVD_ARG3, (MS_U8)u8CC608);
5532 HAL_MVD_RegWriteByte(MVD_COMMAND, (MS_U8)(CMD_RD_USER_WP));//CMD_GET_CCBUF_HWADDR
5533
5534 if (HAL_MVD_TimeOut(pstCmdArg->Arg5) == FALSE)
5535 {
5536 u32MVDCC_Temp1 = 0;
5537 u32MVDCC_Temp1 = (((MS_U32)HAL_MVD_RegReadByte(MVD_ARG0)) & 0x000000FF);
5538 u32MVDCC_Temp1 += ((((MS_U32)HAL_MVD_RegReadByte(MVD_ARG1)) & 0x000000FF) << 8);
5539 u32MVDCC_Temp1 += ((((MS_U32)HAL_MVD_RegReadByte(MVD_ARG2)) & 0x000000FF) << 16);
5540 u32MVDCC_Temp1 = (u32MVDCC_Temp1 << 3);
5541 return (u32MVDCC_Temp1);
5542 }
5543 else
5544 {
5545 MVD_DEBUGINFO(printf("\nF:GHAV"));
5546 }
5547 }
5548 else
5549 {
5550 MVD_DEBUGINFO(printf("\nF:GHA"));
5551 }
5552
5553 return 0xffffffff;
5554 #endif
5555 }
5556
HAL_MVD_GetUsrDataIsAvailable(MS_U8 u8Idx)5557 MS_BOOL HAL_MVD_GetUsrDataIsAvailable(MS_U8 u8Idx)
5558 {
5559 volatile MVD_CtrlCfg* pCtrlCfg = (volatile MVD_CtrlCfg*)HAL_MVD_GetCtrlCfg(u8Idx);
5560 MS_VIRT u32UsrDataWr = 0;
5561 MS_BOOL bIsAvail = FALSE;
5562
5563 #if defined(MVD_SUPPORT_X4_CC)
5564 u32UsrDataWr = HAL_CC_CM_GetMVDRB_HWAddr(4);
5565 #else
5566 u32UsrDataWr = HAL_CC_CM_GetMVDRB_HWAddr(2);
5567 #endif
5568 bIsAvail = !(pCtrlCfg->u32UsrDataRd == u32UsrDataWr);
5569 MVD_DEBUGINFO(printf("IsAvail:%x rd=%lx wr=%lx\n", bIsAvail,
5570 (unsigned long)pCtrlCfg->u32UsrDataRd, (unsigned long)u32UsrDataWr));
5571 return bIsAvail;
5572 }
5573
5574 //------------------------------------------------------------------------------
5575 /// Get info of user data
5576 //------------------------------------------------------------------------------
HAL_MVD_GetUsrDataInfo(MS_U8 u8Idx,MVD_UsrDataInfo * pUsrInfo)5577 MS_BOOL HAL_MVD_GetUsrDataInfo(MS_U8 u8Idx, MVD_UsrDataInfo* pUsrInfo)
5578 {
5579 MS_VIRT u32UsrData = NULL;
5580 MS_VIRT u32UsrDataWr = 0;
5581 #if defined(MVD_SUPPORT_X4_CC)
5582 FW_USER_DATA_BUF_EXT stUsrDataExt;
5583 #else
5584 FW_USER_DATA_BUF stUsrDataInfo;
5585 #endif
5586 volatile MVD_CtrlCfg* pCtrlCfg = (volatile MVD_CtrlCfg*)HAL_MVD_GetCtrlCfg(u8Idx);
5587
5588 if ((!pUsrInfo) || (GET_FRMINFO_BUFFADD(u8Idx)==0))
5589 {
5590 MVD_DEBUGERROR(printf("%s: NULL ptr.\n", __FUNCTION__));
5591 return FALSE;
5592 }
5593
5594 //get write pointer
5595 #if defined(MVD_SUPPORT_X4_CC)
5596 u32UsrDataWr = HAL_CC_CM_GetMVDRB_HWAddr(4);
5597 #else
5598 u32UsrDataWr = HAL_CC_CM_GetMVDRB_HWAddr(2);
5599 #endif
5600 if (pCtrlCfg->u32UsrDataRd == (GET_USRDATA_BUFFADD(u8Idx)+MVD3_FW_USER_DATA_BUF_LEN))
5601 {
5602 pCtrlCfg->u32UsrDataRd = GET_USRDATA_BUFFADD(u8Idx); //wrap to BufStart
5603 }
5604 MVD_DEBUGINFO(printf("CC Rd=0x%lx Wr=0x%lx\n", (unsigned long)pCtrlCfg->u32UsrDataRd, (unsigned long)u32UsrDataWr));
5605
5606 if (pCtrlCfg->u32UsrDataRd == u32UsrDataWr)
5607 {
5608 MVD_DEBUGERROR(printf("%s: no data? Rd=0x%lx Wr=0x%lx\n", __FUNCTION__, (unsigned long)pCtrlCfg->u32UsrDataRd, (unsigned long)u32UsrDataWr));
5609 return FALSE;
5610 }
5611
5612 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,pCtrlCfg->u32UsrDataRd,u32UsrData);
5613
5614 u32UsrData = HAL_MVD_PA2NonCacheSeg(u32UsrData);
5615
5616 HAL_MVD_CPU_Sync();
5617 HAL_MVD_ReadMemory();
5618
5619 #if defined(MVD_SUPPORT_X4_CC)
5620 stUsrDataExt = *(volatile FW_USER_DATA_BUF_EXT*)u32UsrData;
5621
5622 pUsrInfo->u32Pts = stUsrDataExt.pts;
5623 pUsrInfo->u8PicStruct = stUsrDataExt.PicStruct;
5624 pUsrInfo->u8PicType = stUsrDataExt.picType;
5625 pUsrInfo->u8TopFieldFirst = stUsrDataExt.top_ff;
5626 pUsrInfo->u8RptFirstField = stUsrDataExt.rpt_ff;
5627 pUsrInfo->u16TmpRef = stUsrDataExt.tmpRef;
5628 pUsrInfo->u8ByteCnt = stUsrDataExt.userdatabytecnt;
5629 pUsrInfo->u32DataBuf = u32UsrData + MVD_FW_USER_DATA_EXT_HDR_LEN;
5630 #else
5631 stUsrDataInfo = *(volatile FW_USER_DATA_BUF*)u32UsrData;
5632
5633 pUsrInfo->u8PicType = stUsrDataInfo.picType;
5634 pUsrInfo->u8TopFieldFirst = stUsrDataInfo.top_ff;
5635 pUsrInfo->u8RptFirstField = stUsrDataInfo.rpt_ff;
5636 pUsrInfo->u16TmpRef = stUsrDataInfo.tmpRef;
5637 pUsrInfo->u8ByteCnt = stUsrDataInfo.userdatabytecnt;
5638 pUsrInfo->u32DataBuf = u32UsrData + MVD_FW_USER_DATA_HDR_LEN;
5639 #endif
5640 //update read pointer
5641 pCtrlCfg->u32UsrDataRd += MVD_FW_USER_DATA_PKT_LEN;
5642 #if 0
5643 printf("xxInfo: ");
5644 printf("%02d, ", pUsrInfo->u16TmpRef);
5645 printf("%d, ", pUsrInfo->u8PicStruct);
5646 printf("%d, ", pUsrInfo->u8TopFieldFirst);
5647 printf("0x%x, ", pUsrInfo->u32DataBuf);
5648 printf("%d, ", pUsrInfo->u8ByteCnt);
5649 printf("%ld, ", pUsrInfo->u32Pts);
5650 printf("%d\n", pUsrInfo->u8PicType);
5651 #endif
5652 return TRUE;
5653 }
5654
5655
HAL_MVD_Map2DrvSlqTbl(MS_U8 u8Idx,MS_VIRT u32HWPtr)5656 MS_VIRT HAL_MVD_Map2DrvSlqTbl(MS_U8 u8Idx, MS_VIRT u32HWPtr)
5657 {
5658 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
5659 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
5660 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
5661 MS_VIRT u32HWSt = HAL_MVD_GetMemOffset(pstMemCfg->u32BSAddr);
5662 MS_VIRT u32DrvPtr;
5663
5664 if ((u32HWPtr<u32HWSt) && (u32HWPtr!=0))
5665 {
5666 MVD_DEBUGERROR(printf("Invalid u32HWPtr=0x%lx\n", (unsigned long)u32HWPtr));
5667 return 0;
5668 }
5669 if ((pstCtrlCfg->bSlqTblSync) && (u32HWPtr!=0))
5670 {
5671 u32DrvPtr = pstSlqTblInfo->pDrvSlqTbl->u32StAdd + (u32HWPtr - u32HWSt);
5672 return u32DrvPtr;
5673 }
5674 return u32HWPtr;
5675 }
5676
5677
MVD_SLQTblGetFileEndPkt(MS_U8 u8Idx,MVD_PacketInfo * pFileEnd)5678 static void MVD_SLQTblGetFileEndPkt(MS_U8 u8Idx, MVD_PacketInfo* pFileEnd)
5679 {
5680 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
5681 MS_VIRT u32EndPattern = HAL_MVD_GetMemOffset(pstMemCfg->u32DrvBufAddr+SLQ_TBL_SIZE*3);
5682
5683 pFileEnd->u32StAddr = SLQ_TBL_SIZE*3;//u32EndPattern - HAL_MVD_GetMemOffset(pstMemCfg->u32DrvBufAddr);
5684 pFileEnd->u32Length = END_PATTERN_SIZE;
5685 pFileEnd->u32TimeStamp = MVD_NULLPKT_PTS;
5686 pFileEnd->u32ID_L = MVD_U32_MAX;
5687 pFileEnd->u32ID_H = MVD_U32_MAX;
5688 MVD_DEBUGINFO(printf("u32EndPattern(0x%lx)=0x%x 0x%x 0x%x 0x%x\n", (unsigned long)pFileEnd->u32StAddr,
5689 HAL_MVD_MemRead4Byte(u32EndPattern), HAL_MVD_MemRead4Byte(u32EndPattern+4),
5690 HAL_MVD_MemRead4Byte(u32EndPattern+8), HAL_MVD_MemRead4Byte(u32EndPattern+12)));
5691 }
5692
5693
MVD_SLQTblGetDummyPkt(MVD_PacketInfo * pDummy)5694 static void MVD_SLQTblGetDummyPkt(MVD_PacketInfo* pDummy)
5695 {
5696 //MS_U32 u32DummyES = HAL_MVD_GetMemOffset(pstMemCfg->u32DrvBufAddr+SLQ_TBL_SIZE*2);
5697
5698 pDummy->u32StAddr = SLQ_TBL_SIZE*2;//u32DummyES - HAL_MVD_GetMemOffset(pstMemCfg->u32DrvBufAddr);
5699 pDummy->u32Length = DUMMY_SIZE;
5700 pDummy->u32TimeStamp = MVD_NULLPKT_PTS;
5701 pDummy->u32ID_L = MVD_U32_MAX;
5702 pDummy->u32ID_H = MVD_U32_MAX;
5703 #if 0
5704 printf("u32DummyES(0x%x-->0x%x, size=0x%x)=0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", u32DummyES,
5705 pDummy->u32StAddr, pDummy->u32Length, HAL_MVD_MemRead4Byte(u32DummyES),
5706 HAL_MVD_MemRead4Byte(u32DummyES+4),HAL_MVD_MemRead4Byte(u32DummyES+8),HAL_MVD_MemRead4Byte(u32DummyES+12));
5707 #endif
5708
5709 }
5710
5711
HAL_MVD_SLQTblInsertPattern(MS_U8 u8Idx,MVD_PatternType ePattern)5712 MS_BOOL HAL_MVD_SLQTblInsertPattern(MS_U8 u8Idx, MVD_PatternType ePattern)
5713 {
5714 MS_U32 i;
5715 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
5716
5717 if (pstSlqTblInfo->pDrvSlqTbl->u32Empty < SLQ_TBL_SAFERANGE)
5718 {
5719 MVD_DEBUGINFO(printf("SLQTbl full!(0x%lx) Cannot insert pattern any more!\n", (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32Empty));
5720 return FALSE;
5721 }
5722
5723 #if SLQ_NEW_PUSH
5724 if(pstSlqTblInfo->pSlqStatus->bSlqCtrlBit)
5725 {
5726 if(pstSlqTblInfo->pSlqStatus->bSlqPicWaitNextStart)
5727 {
5728 pstSlqTblInfo->pDrvSlqTbl->u32WrPtr = pstSlqTblInfo->pSlqStatus->u32VaildWptrAddr;
5729 }
5730 pstSlqTblInfo->pSlqStatus->bSlqCtrlBit = FALSE;
5731 }
5732 #endif // #if SLQ_NEW_PUSH
5733 for (i =0; i<2; i++)
5734 { //insert dummy pattern
5735 MVD_PacketInfo stDummyPkt;
5736
5737 if (E_MVD_PATTERN_FLUSH == ePattern)
5738 {
5739 MVD_SLQTblGetDummyPkt(&stDummyPkt);
5740 }
5741 else if (E_MVD_PATTERN_FILEEND == ePattern)
5742 {
5743 MVD_SLQTblGetFileEndPkt(u8Idx, &stDummyPkt);
5744 }
5745 else
5746 {
5747 MVD_DEBUGERROR(printf("Invalid MVD_PatternType! Won't insert pattern!\n"));
5748 return FALSE;
5749 }
5750 #if SLQ_NEW_PUSH
5751 pstSlqTblInfo->pSlqStatus->bSlqFireRdy = TRUE;
5752 #endif
5753 //printf("WrPtr 0x%x ", pstSlqTblInfo->pDrvSlqTbl->u32WrPtr);
5754 HAL_MVD_SLQTblSendPacket(u8Idx, &stDummyPkt);
5755 //printf("==> 0x%x\n", pstSlqTblInfo->pDrvSlqTbl->u32WrPtr);
5756 HAL_MVD_SetSLQWritePtr(u8Idx, FALSE);
5757 }
5758 return TRUE;
5759 }
5760
5761
5762 #define FLAG_LAST_FRM_SHOW (MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CMD_LAST_FRAME_SHOW, sizeof(MS_U32)))
HAL_MVD_IsDispFinish(MS_U8 u8Idx)5763 E_MVD_Result HAL_MVD_IsDispFinish(MS_U8 u8Idx)
5764 {
5765 MS_U32 u32TimeCnt;
5766 MVD_SrcMode curSrcMode = HAL_MVD_GetSrcMode(u8Idx);
5767 MS_U32 u32FeByteCnt = 0;
5768 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
5769 MS_VIRT u32FileEndPtr = pstSlqTblInfo->u32FileEndPtr;
5770 MS_U32 u32Id = MVD_GetStreamId(u8Idx);
5771 MS_U8 u8VPUIdx = HAL_VPU_EX_GetTaskId(u32Id);
5772 #ifdef VDEC3
5773 MS_VIRT u32VBBUAddr = HAL_MVD_GetVBBUTableAddr(u8VPUIdx);
5774 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
5775 #endif
5776
5777 //printf("MDrv_MVD_IsDispFinish::");
5778 if (GET_FRMINFO_BUFFADD(u8Idx)==0)
5779 {
5780 MVD_DEBUGERROR(printf("%s err: pu8MVDGetFrameInfoBufStart=NULL\n", __FUNCTION__));
5781 return E_MVD_RET_FAIL;
5782 }
5783
5784 //printf("0x%x\n", FLAG_LAST_FRM_SHOW);
5785 if ((E_MVD_SLQ_TBL_MODE == curSrcMode) && (TRUE != FLAG_LAST_FRM_SHOW))
5786 {
5787 //insert pattern when each time checking IsDispFinish
5788 #ifdef VDEC3
5789 if(pstCtrlCfg->u8McuMode == TRUE)
5790 {
5791 u32TimeCnt= HAL_MVD_GetTime();
5792 while ((HAL_MVD_GetTime() - u32TimeCnt) < 20) // timeout 20 ms
5793 {
5794 if(HAL_VPU_EX_GetVBBUVacancy(u32VBBUAddr) > 0)
5795 {
5796 HAL_VPU_EX_PacketInfo stVpuPkt;
5797 MVD_PacketInfo stDummyPkt;
5798 MVD_SLQTblGetFileEndPkt(u8Idx,&stDummyPkt);
5799
5800 stVpuPkt.u32Offset = stDummyPkt.u32StAddr;
5801 stVpuPkt.u32Length = stDummyPkt.u32Length;
5802 stVpuPkt.u64TimeStamp = (MS_U64)stDummyPkt.u32TimeStamp;
5803 //If in display queue mode
5804 stVpuPkt.u64TimeStamp |= ((MS_U64)stDummyPkt.u32ID_H << 32);
5805 stVpuPkt.u32ID_H = stDummyPkt.u32ID_H;
5806 stVpuPkt.u32ID_L = stDummyPkt.u32ID_L;
5807
5808 HAL_VPU_EX_Push2VBBU(u32Id, &stVpuPkt,u32VBBUAddr);
5809 }
5810
5811 if (TRUE == FLAG_LAST_FRM_SHOW)
5812 {
5813 break;
5814 }
5815 }
5816
5817 if (TRUE != FLAG_LAST_FRM_SHOW)
5818 {
5819 MVD_DEBUGERROR(printf("MDrv_MVD_IsDispFinish TIMEOUT\n"));
5820 return E_MVD_RET_TIME_OUT;
5821 }
5822 else
5823 {
5824 return E_MVD_RET_OK;
5825 }
5826 }
5827 else
5828 #endif
5829 {
5830 //insert pattern when each time checking IsDispFinish
5831 if (HAL_MVD_SLQTblInsertPattern(u8Idx, E_MVD_PATTERN_FILEEND))
5832 {
5833 u32FeByteCnt += END_PATTERN_SIZE;
5834 }
5835
5836 if ((u32FileEndPtr == HAL_MVD_Map2DrvSlqTbl(u8Idx, HAL_MVD_GetSLQReadPtr(u8Idx))) &&
5837 (HAL_MVD_IsMcuMode(u8Idx) == FALSE) &&
5838 (HAL_MVD_IsMStreamerMode(u8Idx) == FALSE))
5839 {
5840 //insert padding pattern until timeout
5841 u32TimeCnt= HAL_MVD_GetTime();
5842 while ((HAL_MVD_GetTime() - u32TimeCnt) < CMD_TIMEOUT_MS)
5843 {
5844 if (TRUE == FLAG_LAST_FRM_SHOW)
5845 {
5846 //printf("\nDisp finished!\n");
5847 break;
5848 }
5849 //insert file-end pattern again
5850 if (HAL_MVD_SLQTblInsertPattern(u8Idx, E_MVD_PATTERN_FILEEND))
5851 {
5852 u32FeByteCnt += END_PATTERN_SIZE;
5853 }
5854 }
5855 if ((HAL_MVD_GetTime() - u32TimeCnt) >= CMD_TIMEOUT_MS)
5856 {
5857 MVD_DEBUGERROR(printf("\n***** MDrv_MVD_IsDispFinish TIMEOUT!!! *****\n\n"));
5858 if (E_MVD_CODEC_VC1_MAIN == HAL_MVD_GetCodecType(u8Idx))
5859 {
5860 if ((HAL_MVD_GetPayloadLen(u8Idx) > 0x200000)
5861 && (TRUE != HAL_MVD_GotFileEndPattern(u8Idx)))
5862 {
5863 MVD_DEBUGERROR(printf("RCV payloadLen(0x%x) invalid!\n",
5864 HAL_MVD_GetPayloadLen(u8Idx)));
5865 }
5866 }
5867 MVD_DEBUGERROR(printf("***** fe=%lx, rd=%lx(%lx,%lx), wr=%lx, empty=%lx, u32FeByteCnt=%x\n",
5868 (unsigned long)u32FileEndPtr, (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32RdPtr, (unsigned long)HAL_MVD_Map2DrvSlqTbl(u8Idx, HAL_MVD_GetSLQReadPtr(u8Idx)),
5869 (unsigned long)HAL_MVD_GetSLQReadPtr(u8Idx), (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32WrPtr, (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32Empty, u32FeByteCnt));
5870 return E_MVD_RET_TIME_OUT;
5871 }
5872 else
5873 {
5874 return E_MVD_RET_OK;
5875 }
5876 }
5877 else
5878 {
5879 //just return fail if readPtr is not closed to file-end ptr
5880 MVD_DEBUGINFO(printf("fe=%lx, rd=%lx(%lx), wr=%lx, empty=%lx\n", (unsigned long)u32FileEndPtr, (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32RdPtr,
5881 (unsigned long)HAL_MVD_Map2DrvSlqTbl(u8Idx, (unsigned long)HAL_MVD_GetSLQReadPtr(u8Idx)), (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32WrPtr, (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32Empty));
5882 return E_MVD_RET_FAIL;
5883 }
5884 }
5885 }
5886
5887 if (FLAG_LAST_FRM_SHOW)
5888 {
5889 return E_MVD_RET_OK;
5890 }
5891 else
5892 {
5893 return E_MVD_RET_FAIL;
5894 }
5895 }
5896
5897 //------------------------------------------------------------------------------
5898 /// Set MVD SLQ start & end address
5899 /// @param -u32start \b IN : start address
5900 /// @param -u32end \b IN : end address
5901 //------------------------------------------------------------------------------
HAL_MVD_SetSLQStartEnd(MS_U8 u8Idx,MS_U32 u32start,MS_U32 u32end)5902 static void HAL_MVD_SetSLQStartEnd(MS_U8 u8Idx, MS_U32 u32start, MS_U32 u32end)
5903 {
5904 MVD_CmdArg mvdcmd;
5905
5906 if ((u32start > SLQ_ADDR_LEN) || ((u32end+1) > SLQ_ADDR_LEN))
5907 {
5908 MVD_DEBUGERROR(printf("MDrv_MVD_SetSLQStartEnd: only support 27bit add!\n"));
5909 }
5910
5911 SET_CMDARG(mvdcmd, (u32end+1), u8Idx);
5912 if (HAL_MVD_MVDCommand( CMD_SLQ_END, &mvdcmd ) == FALSE)
5913 {
5914 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLQ_END ) );
5915 return;
5916 }
5917
5918 SET_CMDARG(mvdcmd, u32start, u8Idx);
5919 if (HAL_MVD_MVDCommand( CMD_SLQ_START, &mvdcmd ) == FALSE)
5920 {
5921 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLQ_START ) );
5922 return;
5923 }
5924
5925 return;
5926 }
5927
HAL_MVD_DecodeIFrame(MS_U8 u8Idx,MS_PHY u32FrameBufAddr,MS_PHY u32StreamBufAddr,MS_PHY u32StreamBufEndAddr)5928 MS_BOOL HAL_MVD_DecodeIFrame(MS_U8 u8Idx, MS_PHY u32FrameBufAddr, MS_PHY u32StreamBufAddr, MS_PHY u32StreamBufEndAddr )
5929 {
5930 MS_U32 u32deley = 0;
5931 MS_U32 u32time = 0;
5932 MVD_CmdArg mvdcmd;
5933 MS_VIRT u32MVDFWSLQTABTmpbufAdr = GET_SLQ_BUFFADD(u8Idx);
5934
5935 MVD_DEBUGINFO(printf("%s offset FBAdd=0x%lx streamStart=0x%lx streamEnd=0x%lx\n",
5936 __FUNCTION__, (unsigned long)u32FrameBufAddr, (unsigned long)u32StreamBufAddr, (unsigned long)u32StreamBufEndAddr));
5937
5938 HAL_MVD_SetCodecInfo(u8Idx, E_MVD_CODEC_MPEG2, E_MVD_SLQ_MODE, DISABLE_PARSER);
5939 HAL_MVD_SetFrameBuffAddr(u8Idx, u32FrameBufAddr, HAL_MVD_GetFBMode(u8Idx));
5940
5941 SETUP_CMDARG(mvdcmd);
5942 mvdcmd.Arg0 = 1;
5943 SET_DECNUM(mvdcmd, u8Idx);
5944 SET_CMD_RET_FALSE(CMD_DISPLAY_CTL, &mvdcmd);
5945
5946 if (HAL_MVD_StepDecode(u8Idx) == FALSE)
5947 {
5948 MVD_DEBUGERROR( printf( "HAL_MVD_StepDecode fail!!\r\n") );
5949 return FALSE;
5950 }
5951
5952 SETUP_CMDARG(mvdcmd);
5953 mvdcmd.Arg0 = 1;
5954 mvdcmd.Arg1 = 1;
5955 SET_DECNUM(mvdcmd, u8Idx);
5956 SET_CMD_RET_FALSE(CMD_FAST_SLOW, &mvdcmd);
5957
5958 //set data
5959 HAL_MVD_Delayms(2);
5960
5961 HAL_MVD_CPU_Sync();
5962 HAL_MVD_FlushMemory();
5963
5964 //wait vld init success or data may lost!
5965 #define WAIT_INIT_SUCCESS_TIME 100 //100ms
5966 u32deley = HAL_MVD_GetTime();
5967 while ((HAL_MVD_GetDecodeStatus(u8Idx)==DEC_STAT_IDLE) && (u32time<WAIT_INIT_SUCCESS_TIME))
5968 {
5969 u32time = HAL_MVD_GetTime()-u32deley;
5970 }
5971 if (u32time>=WAIT_INIT_SUCCESS_TIME)
5972 {
5973 MVD_DEBUGERROR(printf("%s: wait init_success timeout!!!\n", __FUNCTION__));
5974 }
5975 HAL_MVD_SetSLQStartEnd(u8Idx, u32StreamBufAddr, u32StreamBufEndAddr);
5976 MVD_DEBUGINFO(printf("set MVD3_FW_SLQ_TAB_TMPBUF_ADR=%lx\n",(unsigned long)u32MVDFWSLQTABTmpbufAdr));
5977
5978 HAL_MVD_CPU_Sync();
5979 HAL_MVD_FlushMemory();
5980 HAL_MVD_SetSLQStartEnd(u8Idx, u32MVDFWSLQTABTmpbufAdr, u32MVDFWSLQTABTmpbufAdr+MVD3_FW_SLQ_TAB_TMPBUF_LEN);
5981
5982 HAL_MVD_CPU_Sync();
5983 HAL_MVD_ReadMemory();
5984
5985 // wait decode complete
5986 #define WAIT_DECODE_DONE_TIME 33 //To decode 1 frame should take less than 33ms
5987 u32deley = HAL_MVD_GetTime();
5988 u32time = 0;
5989 while (HAL_MVD_GetPicCounter(u8Idx)<1 && (u32time<WAIT_DECODE_DONE_TIME))
5990 {
5991 u32time = HAL_MVD_GetTime()-u32deley;
5992 }
5993 if (u32time >= WAIT_DECODE_DONE_TIME)
5994 {
5995 MVD_DEBUGERROR(printf ("MDrv_MVD_DecodeIFrame time out(du=%d, st=%d, now=%d)\n", u32time, u32deley, HAL_MVD_GetTime()));
5996 MVD_DEBUGERROR(printf("frmCnt=%d state=0x%x lastCmd=0x%x\n", HAL_MVD_GetPicCounter(u8Idx), HAL_MVD_GetDecodeStatus(u8Idx), HAL_MVD_GetLastCmd(u8Idx)));
5997 return FALSE;
5998 }
5999 MVD_DEBUGINFO(printf ("MDrv_MVD_DecodeIFrame time (%d, %d)\n", u32time, u32deley));
6000 //printf("frmCnt=%ld state=0x%x lastCmd=0x%x\n", HAL_MVD_GetPicCounter(u8Idx), HAL_MVD_GetDecodeStatus(u8Idx), HAL_MVD_GetLastCmd(u8Idx));
6001
6002 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
6003 pCtrlCfg->bDecodeIFrame = TRUE;
6004
6005 return TRUE;
6006 }
6007
6008
6009 //------------------------------------------------------------------------------
6010 /// Set bit stream buffer address to MVD
6011 /// @param -u32start \b IN : start address
6012 /// @param -u32end \b IN : end address
6013 //------------------------------------------------------------------------------
MVD_SetBitStreamAddr(MS_U8 u8Idx,MS_VIRT u32start,MS_VIRT u32end)6014 static void MVD_SetBitStreamAddr(MS_U8 u8Idx, MS_VIRT u32start, MS_VIRT u32end)
6015 {
6016 MVD_CmdArg mvdcmd;
6017 MS_ASSERT((u32start%8)==0);
6018 u32start >>= 3;
6019 SET_CMDARG(mvdcmd, u32start, u8Idx);
6020 if (HAL_MVD_MVDCommand( CMD_STREAM_BUF_START, &mvdcmd ) == FALSE)
6021 {
6022 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_STREAM_BUF_START ) );
6023 return;
6024 }
6025
6026 MS_ASSERT((u32end%8)==0);
6027 u32end >>= 3;
6028 SET_CMDARG(mvdcmd, u32end, u8Idx);
6029 if (HAL_MVD_MVDCommand( CMD_STREAM_BUF_END, &mvdcmd ) == FALSE)
6030 {
6031 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_STREAM_BUF_END ) );
6032 return;
6033 }
6034 return;
6035 }
6036
HAL_MVD_SetInternalBuffAddr(MS_U8 u8Idx,MS_VIRT u32start,MS_U32 u32len)6037 MS_BOOL HAL_MVD_SetInternalBuffAddr(MS_U8 u8Idx, MS_VIRT u32start, MS_U32 u32len)
6038 {
6039 MS_VIRT tmpAdr, tmpLen;
6040 MVD_FWCfg* pFwCfg = NULL;
6041 MVD_FWBuff* pBuff = &(pMVDHalContext->stFWBuff[u8Idx]);
6042 MVD_MEMCfg* pstMemCfg = NULL;
6043 MVD_SLQTBLInfo* pstSlqTblInfo = NULL;
6044 MS_U32 u32Id = MVD_GetStreamId(u8Idx);
6045 MS_U8 u8VPUIdx = HAL_VPU_EX_GetTaskId(u32Id);
6046 MS_VIRT u32BuffStart = u32start+(MVD_FW_TASK_OFFSET*u8VPUIdx);
6047 MS_VIRT VPUSHMAddr = HAL_VPU_EX_GetSHMAddr();
6048 MS_VIRT u32StartOffset;
6049 MS_U8 u8MiuSel;
6050
6051 if(VPUSHMAddr != 0)
6052 {
6053 _phy_to_miu_offset(u8MiuSel, u32StartOffset, VPUSHMAddr);
6054
6055 u32StartOffset -= MVD_FW_CODE_LEN;
6056
6057 if(u8Idx == 0)
6058 {
6059 u32BuffStart = u32StartOffset; // for main decoder
6060 }
6061 else if(u8Idx == 1)
6062 {
6063 u32BuffStart = u32StartOffset + 0x20000; // VPUSHMAddr+128K bytes
6064 }
6065 }
6066
6067 MVD_DEBUGINFO(printf("MVD FW shared mem start = 0x%lx\n", (unsigned long)u32BuffStart));
6068 MVD_GetFWBuffAdd(u32BuffStart, u32len, pBuff);
6069 MVD_SetFWBuffAdd(u8Idx, pBuff);
6070
6071 tmpAdr = pBuff->u32DecFrmInfoAdd + MVD_FW_DECFRM_INFO_BUF_LEN;
6072
6073 HAL_MVD_MemGetMap(u8Idx, E_MVD_MMAP_FB, &tmpAdr, &tmpLen);
6074 MVD_DEBUGINFO(printf("set MVD_FRAMEBUFFER_ADR=%lx\n",(unsigned long)tmpAdr));
6075 HAL_MVD_SetFrameBuffAddr(u8Idx, tmpAdr, HAL_MVD_GetFBMode(u8Idx));
6076 pFwCfg = HAL_MVD_GetFWCfg(u8Idx);
6077 HAL_MVD_SetFrameBuffNum(u8Idx, pFwCfg->u8FBNum,pFwCfg->u32FBUsedSize);
6078
6079 // If VD_MHEG5(CPU) and MVD HW engine are run on different MIU,
6080 // IAP, DP, and MV buffers are allocated after FB.
6081 // The reason is that these 3 buffers are used by MVD HW engine.
6082 if(pMVDHalContext->bCMAUsed == FALSE)
6083 {
6084 tmpAdr += pFwCfg->u32FBUsedSize;
6085 pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
6086 if (pstMemCfg->u32FBSize < (pFwCfg->u32FBUsedSize + MVD_HW_BUF_TOTAL_LEN))
6087 {
6088 MVD_DEBUGERROR(printf("MVD HW buffers larger than FB size!!!\n"));
6089 }
6090 MVD_DEBUGINFO(printf("MVD FB boundary =0x%lx\n",(unsigned long)tmpAdr));
6091 tmpAdr = HAL_MVD_SetHWBuffer(u8Idx, tmpAdr);
6092 }
6093
6094 HAL_MVD_MemGetMap(u8Idx, E_MVD_MMAP_BS, &tmpAdr, &tmpLen);
6095 MVD_DEBUGINFO(printf("set MVD_BITSTREAM_ADR=%lx\n",(unsigned long)tmpAdr));
6096 MVD_SetBitStreamAddr(u8Idx, tmpAdr,tmpAdr+tmpLen);
6097 pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
6098 pstSlqTblInfo->u32ESBuffEnd = tmpAdr+tmpLen;
6099
6100 if((pFwCfg->stFBReduction.LumaFBReductionMode != E_MVD_FB_REDUCTION_NONE)
6101 || (pFwCfg->stFBReduction.ChromaFBReductionMode != E_MVD_FB_REDUCTION_NONE))
6102 {
6103 //for chips not support reduction mode, just ignore related config.
6104 MVD_DEBUGERROR(printf("MVD Err: Not support FB reduction mode!!\n"));
6105 }
6106
6107 return TRUE;
6108 }
6109
6110 //------------------------------------------------------------------------------
6111 /// Issue "Decode Pause" command.
6112 //------------------------------------------------------------------------------
HAL_MVD_DecodePause(MS_U8 u8Idx)6113 void HAL_MVD_DecodePause(MS_U8 u8Idx)
6114 {
6115 MVD_CmdArg mvdcmd;
6116 SETUP_CMDARG(mvdcmd);
6117 SET_DECNUM(mvdcmd, u8Idx);
6118 if (HAL_MVD_MVDCommand(CMD_PAUSE, &mvdcmd)== FALSE)
6119 {
6120 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PAUSE) );
6121 return;
6122 }
6123
6124 return;
6125 }
6126
6127
6128 //------------- Below functions are for MediaCodec SLQ Table --------------------
6129 #if _SLQTBL_DUMP_PTS
_SLQTbl_DumpPtsTbl(MS_U8 u8Idx,MS_U32 u32EntryStart,MS_U32 u32EntryEnd)6130 static void _SLQTbl_DumpPtsTbl(MS_U8 u8Idx, MS_U32 u32EntryStart, MS_U32 u32EntryEnd)
6131 {
6132 MS_U32 i;
6133 MS_VIRT u32EsRp, u32EsStart, u32EsEnd;
6134 MS_VIRT u32MVDFWPtsTblAddr = GET_PTSTBL_BUFFADD(u8Idx);
6135
6136 for (i=u32EntryStart; i<u32EntryEnd; i++)
6137 {
6138 u32EsRp = pstSlqTblInfo->pDrvEsTbl->u32StAdd + i*8;
6139
6140 u32EsEnd = HAL_MVD_MemRead4Byte(u32EsRp+4);
6141 u32EsStart = HAL_MVD_MemRead4Byte(u32EsRp); //report StartAdd as read_pointer
6142 printf("ES[%x] Start=0x%x End=0x%x u32EsRp=%x\n",
6143 i, u32EsStart, u32EsEnd, u32EsRp);
6144 }
6145
6146 printf("\n=======Dump PTS table========\n");
6147 printf("addr\t byte_cnt\t dummy_cnt\t id_low\t id_high\t time_stamp\n");
6148 for (i=u32EntryStart; i<u32EntryEnd; i++)
6149 {
6150 printf("0x%x\t 0x%08lx\t 0x%08lx\t 0x%08lx\t 0x%08lx\t 0x%08lx\n", u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN,
6151 HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN), //byteCnt
6152 HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN+4), //dummyPktCnt
6153 HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN+8), //idLow
6154 HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN+12),//idHigh
6155 HAL_MVD_MemRead4Byte(u32MVDFWPtsTblAddr+i*MVD_FW_SLQTBL_PTS_LEN+16) //pts
6156 );
6157 }
6158 printf("=====================================\n");
6159 }
6160 #endif
6161
6162
6163 #if SLQ_NEW_PUSH
MVD_SLQTblGetHdrPkt(MS_U8 u8Idx,MVD_PacketInfo * pDivxHdr,MVD_PacketInfo * pDivxData)6164 void MVD_SLQTblGetHdrPkt(MS_U8 u8Idx, MVD_PacketInfo* pDivxHdr, MVD_PacketInfo* pDivxData)
6165 #else
6166 static void MVD_SLQTblGetDivxHdrPkt(MS_U8 u8Idx, MVD_PacketInfo* pDivxHdr, MVD_PacketInfo* pDivxData)
6167 #endif
6168 {
6169 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
6170 MS_VIRT u32DivXPattern = pstSlqTblInfo->pDrvDivxTbl->u32WrPtr;
6171 MS_U32 u32FrmSize = pDivxData->u32Length;
6172 MVD_CodecType curCodecType = HAL_MVD_GetCodecType(u8Idx);
6173 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
6174 #ifdef VDEC3
6175 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
6176 #endif
6177 #if SLQ_NEW_PUSH
6178 if(pstSlqTblInfo->pSlqStatus->bSlqCtrlBit && pstCtrlCfg->u8McuMode == FALSE)
6179 {
6180 if(pstSlqTblInfo->pSlqStatus->bSlqPicWaitNextStart && pstSlqTblInfo->pSlqStatus->bSlqPicStart)
6181 {
6182 //printf("Show KC the SlqPushLength = 0x%x\n",pstSlqTblInfo->pSlqStatus->u32SlqPushLength);
6183 if (E_MVD_CODEC_DIVX311 == curCodecType)
6184 {
6185 HAL_MVD_MemWrite4Byte(pstSlqTblInfo->pSlqStatus->u32SlqPatternAddr +4, pstSlqTblInfo->pSlqStatus->u32SlqPushLength);
6186 HAL_MVD_MemWrite4Byte(pstSlqTblInfo->pSlqStatus->u32SlqPatternAddr , DIVX_PATTERN);
6187 }
6188 else if(E_MVD_CODEC_VC1_MAIN == curCodecType)
6189 {//rcv
6190 HAL_MVD_MemWrite4Byte(pstSlqTblInfo->pSlqStatus->u32SlqPatternAddr +4, RCV_PATTERN);
6191 HAL_MVD_MemWrite4Byte(pstSlqTblInfo->pSlqStatus->u32SlqPatternAddr , pstSlqTblInfo->pSlqStatus->u32SlqPushLength);
6192 }
6193 else if (E_MVD_CODEC_VC1_ADV == curCodecType)
6194 {
6195 HAL_MVD_MemWrite4Byte(pstSlqTblInfo->pSlqStatus->u32SlqPatternAddr , VC1_PATTERN);
6196 }
6197 pstSlqTblInfo->pSlqStatus->u32SlqPushLength = 0;
6198 pstSlqTblInfo->pSlqStatus->u32SlqPatternAddr = 0;
6199 pstSlqTblInfo->pSlqStatus->bSlqFireRdy =TRUE;
6200 pstSlqTblInfo->pSlqStatus->u32VaildWptrAddr = pstSlqTblInfo->pDrvSlqTbl->u32WrPtr;// - 16;
6201 pstSlqTblInfo->pSlqStatus->bSlqPicWaitNextStart = FALSE;
6202 pstSlqTblInfo->pSlqStatus->bSlqPicCollect = FALSE;
6203 }
6204
6205 if(pstSlqTblInfo->pSlqStatus->bSlqPicStart)
6206 {
6207 pstSlqTblInfo->pSlqStatus->u32SlqPatternAddr = u32DivXPattern;
6208 pstSlqTblInfo->pSlqStatus->u32SlqPushLength += u32FrmSize;
6209 pstSlqTblInfo->pSlqStatus->bSlqPicCollect = TRUE;
6210 pstSlqTblInfo->pSlqStatus->bSlqPicWaitNextStart =TRUE;
6211 }
6212 else if(pstSlqTblInfo->pSlqStatus->bSlqPicCollect)
6213 {
6214 pstSlqTblInfo->pSlqStatus->u32SlqPushLength += u32FrmSize;
6215 pstSlqTblInfo->pSlqStatus->bSlqPicWaitNextStart =TRUE;
6216 }
6217 }
6218 else
6219 {
6220 HAL_MVD_MemWrite4Byte(u32DivXPattern, DIVX_PATTERN);
6221 HAL_MVD_MemWrite4Byte(u32DivXPattern +4,u32FrmSize);
6222 }
6223 #else
6224 HAL_MVD_MemWrite4Byte(u32DivXPattern, DIVX_PATTERN);
6225 HAL_MVD_MemWrite4Byte(u32DivXPattern+4, u32FrmSize);
6226 #endif
6227 pDivxHdr->u32StAddr = u32DivXPattern - HAL_MVD_GetMemOffset(pstMemCfg->u32DrvBufAddr);
6228 pDivxHdr->u32TimeStamp = pDivxData->u32TimeStamp; //unit: ms
6229 pDivxHdr->u32ID_L = pDivxData->u32ID_L;
6230 pDivxHdr->u32ID_H = pDivxData->u32ID_H;
6231 //printf("u32DivXPattern(0x%x==>0x%x)=0x%x 0x%x\n", u32DivXPattern, pDivxHdr->u32StAddr,
6232 // HAL_MVD_MemRead4Byte(u32DivXPattern), HAL_MVD_MemRead4Byte(u32DivXPattern+4));
6233 if (E_MVD_CODEC_VC1_ADV == curCodecType)
6234 {
6235 pstSlqTblInfo->pDrvDivxTbl->u32WrPtr += 4;
6236 pDivxHdr->u32Length = 4;
6237 }
6238 else
6239 {
6240 pstSlqTblInfo->pDrvDivxTbl->u32WrPtr += 8;
6241 if(pstCtrlCfg->u8McuMode == TRUE)
6242 {
6243 pDivxHdr->u32Length = 64;
6244 if (pstSlqTblInfo->pDrvDivxTbl->u32WrPtr >= pstSlqTblInfo->pDrvDivxTbl->u32EndAdd)
6245 {
6246 pstSlqTblInfo->pDrvDivxTbl->u32WrPtr = pstSlqTblInfo->pDrvDivxTbl->u32StAdd;
6247 }
6248 }
6249 else
6250 {
6251 pDivxHdr->u32Length = 8;
6252 }
6253 }
6254
6255 #if SLQ_NEW_PUSH
6256 if(pstSlqTblInfo->pSlqStatus->bSlqPicStart && pstCtrlCfg->u8McuMode == FALSE)
6257 {
6258 if (E_MVD_CODEC_VC1_ADV == curCodecType)
6259 {
6260 pstSlqTblInfo->pDrvDivxTbl->u32WrPtr += 4;
6261 pDivxHdr->u32Length = 4;
6262 }
6263 else
6264 {
6265 pstSlqTblInfo->pDrvDivxTbl->u32WrPtr += 8;
6266 pDivxHdr->u32Length = 8;
6267 }
6268 }
6269 #endif
6270 }
6271
MVD_SLQTblInitFileEndPkt(MS_U8 u8Idx,MVD_CodecType eType)6272 static void MVD_SLQTblInitFileEndPkt(MS_U8 u8Idx, MVD_CodecType eType)
6273 {
6274 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
6275 MS_VIRT u32EndPattern = HAL_MVD_GetMemOffset(pstMemCfg->u32DrvBufAddr+SLQ_TBL_SIZE*3);
6276 MS_PHY temp = 0;
6277
6278 #if 0
6279 _MVD_Memset(u32EndPattern, 0xff, END_PATTERN_SIZE);
6280 #else
6281 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,u32EndPattern,temp);
6282 memset((void*)(MS_PA2KSEG1(temp)),0xff,END_PATTERN_SIZE);
6283 MsOS_FlushMemory();
6284 MsOS_ReadMemory();
6285 #endif
6286
6287 if ((E_MVD_CODEC_FLV == eType)||(E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER == eType))
6288 {
6289 HAL_MVD_MemWrite4Byte(u32EndPattern, FLV_PATTERN);
6290 HAL_MVD_MemWrite4Byte(u32EndPattern+4, 0xffffffff);
6291 HAL_MVD_MemWrite4Byte(u32EndPattern+8, END_PATTERN_1); //scw
6292 HAL_MVD_MemWrite4Byte(u32EndPattern+12,END_PATTERN_2); //scw
6293 HAL_MVD_MemWrite4Byte(u32EndPattern+16,END_PATTERN_3); //scw
6294 //printf("##########FileEnd for FLV/SVH!, u32EndPattern=%x\n",u32EndPattern);
6295 }
6296 else if (E_MVD_CODEC_DIVX311 == eType)
6297 {
6298 HAL_MVD_MemWrite4Byte(u32EndPattern, DIVX_PATTERN);
6299 HAL_MVD_MemWrite4Byte(u32EndPattern+4, 0xffffffff);
6300 HAL_MVD_MemWrite4Byte(u32EndPattern+8, END_PATTERN_1); //scw
6301 HAL_MVD_MemWrite4Byte(u32EndPattern+12,END_PATTERN_2); //scw
6302 HAL_MVD_MemWrite4Byte(u32EndPattern+16,END_PATTERN_3); //scw
6303 //printf("##########FileEnd for DIVX311!, u32EndPattern=%x\n",u32EndPattern);
6304 }
6305 else if ((E_MVD_CODEC_MPEG2 == eType)||(E_MVD_CODEC_MPEG4 == eType))
6306 {
6307 HAL_MVD_MemWrite4Byte(u32EndPattern, MPEG_PATTERN_0);
6308 HAL_MVD_MemWrite4Byte(u32EndPattern+4, END_PATTERN_1);
6309 HAL_MVD_MemWrite4Byte(u32EndPattern+8, END_PATTERN_2);
6310 HAL_MVD_MemWrite4Byte(u32EndPattern+12,END_PATTERN_3);
6311 //printf("##########FileEnd for MPEG2/4!, u32EndPattern=%x\n",u32EndPattern);
6312 }
6313 else
6314 {
6315 HAL_MVD_MemWrite4Byte(u32EndPattern, END_PATTERN_0);
6316 HAL_MVD_MemWrite4Byte(u32EndPattern+4, END_PATTERN_1);
6317 HAL_MVD_MemWrite4Byte(u32EndPattern+8, END_PATTERN_2); //scw
6318 HAL_MVD_MemWrite4Byte(u32EndPattern+12,END_PATTERN_3); //scw
6319 //printf("##########FileEnd for VC1!, u32EndPattern=%x\n",u32EndPattern);
6320 }
6321
6322 MVD_DEBUGINFO(printf("u32EndPattern(0x%lx)=0x%x 0x%x\n", (unsigned long)u32EndPattern,
6323 HAL_MVD_MemRead4Byte(u32EndPattern), HAL_MVD_MemRead4Byte(u32EndPattern+4)));
6324 }
6325
6326
MVD_SLQTblInitDummyPkt(MS_U8 u8Idx,MVD_CodecType eType)6327 static void MVD_SLQTblInitDummyPkt(MS_U8 u8Idx, MVD_CodecType eType)
6328 {
6329 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
6330 MS_VIRT u32DummyES = HAL_MVD_GetMemOffset(pstMemCfg->u32DrvBufAddr+SLQ_TBL_SIZE*2);
6331 MS_U32 u32DummyPattern[3];
6332 MS_U32 u32PatternSize;
6333 MS_U32 i;
6334 MS_PHY temp = 0;
6335
6336 //printf("eType = 0x%x\n", eType);
6337 //initial content for dummy packet
6338 #if 0
6339 _MVD_Memset(u32DummyES, 0xff, DUMMY_SIZE);
6340 #else
6341 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,u32DummyES,temp);
6342 memset((void*)(MS_PA2KSEG1(temp)),0xff,DUMMY_SIZE);
6343 MsOS_FlushMemory();
6344 MsOS_ReadMemory();
6345 #endif
6346
6347 switch (eType)
6348 {
6349 case E_MVD_CODEC_FLV:
6350 case E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER:
6351 u32DummyPattern[0] = FLV_PATTERN;
6352 u32PatternSize = 1;
6353 break;
6354
6355 case E_MVD_CODEC_DIVX311:
6356 u32DummyPattern[0] = DIVX_PATTERN;
6357 u32PatternSize = 1;
6358 break;
6359
6360 case E_MVD_CODEC_VC1_ADV: //vc1
6361 u32DummyPattern[0] = VC1_PATTERN_0;
6362 u32DummyPattern[1] = VC1_PATTERN_1;
6363 u32DummyPattern[2] = VC1_PATTERN_2;
6364 u32PatternSize = 3;
6365 break;
6366
6367 case E_MVD_CODEC_VC1_MAIN: //rcv
6368 u32DummyPattern[0] = RCV_PATTERN_0;
6369 u32DummyPattern[1] = RCV_PATTERN_1;
6370 u32DummyPattern[2] = RCV_PATTERN_2;
6371 u32PatternSize = 3;
6372 break;
6373
6374 default:
6375 u32DummyPattern[0] = DUMMY_PATTERN;
6376 u32PatternSize = 1;
6377 break;
6378 }
6379 for (i=0; i<u32PatternSize; i++)
6380 {
6381 HAL_MVD_MemWrite4Byte(u32DummyES+i*4, u32DummyPattern[i]);
6382 }
6383 #if 0
6384 printf("u32DummyES(0x%x)=0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", u32DummyES, HAL_MVD_MemRead4Byte(u32DummyES),
6385 HAL_MVD_MemRead4Byte(u32DummyES+4),HAL_MVD_MemRead4Byte(u32DummyES+8),HAL_MVD_MemRead4Byte(u32DummyES+12));
6386 #endif
6387
6388 }
6389
MVD_SLQTblInitDrvSlqTbl(MVD_SLQ_TBL_ST * pDrvSlqTbl,MS_VIRT u32Addr)6390 static void MVD_SLQTblInitDrvSlqTbl(MVD_SLQ_TBL_ST* pDrvSlqTbl, MS_VIRT u32Addr)
6391 {
6392 MS_PHY temp = 0;
6393 pDrvSlqTbl->u32StAdd = u32Addr;
6394 pDrvSlqTbl->u32EndAdd = u32Addr + SLQ_TBL_SIZE;
6395 pDrvSlqTbl->u32EntryCntMax = SLQ_ENTRY_MAX;
6396
6397 //reset SLQ table read/write pointers
6398 pDrvSlqTbl->u32RdPtr = pDrvSlqTbl->u32StAdd;
6399 pDrvSlqTbl->u32WrPtr = pDrvSlqTbl->u32StAdd;
6400 pDrvSlqTbl->pu32LastEntry = &pDrvSlqTbl->u32WrPtr;
6401
6402 #if (!MVD_TURBO_INIT)
6403 //reset SLQ table
6404 #if 0
6405 _MVD_Memset(pDrvSlqTbl->u32StAdd, 0, SLQ_TBL_SIZE);
6406 #else
6407 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,pDrvSlqTbl->u32StAdd,temp);
6408 memset((void*)(MS_PA2KSEG1(temp)),0,SLQ_TBL_SIZE);
6409 MsOS_FlushMemory();
6410 MsOS_ReadMemory();
6411 #endif
6412 #endif
6413 pDrvSlqTbl->u32Empty = SLQ_TBL_SIZE;
6414 //_SLQTbl_DumpInfo(pDrvSlqTbl);
6415 }
6416
MVD_SLQTblInitSlqStatus(MVD_SLQ_STATUS * pSlqStatus,MS_VIRT u32WrPtr)6417 static void MVD_SLQTblInitSlqStatus(MVD_SLQ_STATUS* pSlqStatus, MS_VIRT u32WrPtr)
6418 {
6419 #if SLQ_NEW_PUSH
6420 pSlqStatus->u32VaildWptrAddr = u32WrPtr ;
6421 pSlqStatus->bSlqPicWaitNextStart = FALSE;
6422 pSlqStatus->bSlqCtrlBit = FALSE;
6423 pSlqStatus->u32SlqPushLength = 0;
6424 pSlqStatus->bSlqPicStart = FALSE;
6425 pSlqStatus->bSlqPicCollect = FALSE;
6426 pSlqStatus->bSlqEnLastFrameShow =FALSE;
6427 pSlqStatus->bSlqFireRdy = FALSE;
6428 #endif
6429 }
6430
MVD_SLQTblInitDrvDivxTbl(MVD_SLQ_ES_ST * pDrvDivxTbl,MS_VIRT u32StAdd,MS_U32 u32Val)6431 static void MVD_SLQTblInitDrvDivxTbl(MVD_SLQ_ES_ST* pDrvDivxTbl, MS_VIRT u32StAdd, MS_U32 u32Val)
6432 {
6433 MS_PHY temp = 0;
6434 ///// init SLQ entries for DivX311
6435 pDrvDivxTbl->u32StAdd = u32StAdd;
6436 pDrvDivxTbl->u32EndAdd= pDrvDivxTbl->u32StAdd + SLQ_TBL_SIZE;
6437 pDrvDivxTbl->u32WrPtr = pDrvDivxTbl->u32StAdd;
6438 //pDrvDivxTbl->u32RdPtr = pDrvDivxTbl->u32StAdd;
6439 #if (!MVD_TURBO_INIT)
6440 //reset DivX311 pattern table
6441 #if 0
6442 _MVD_Memset(pDrvDivxTbl->u32StAdd, 0, u32Val);
6443 #else
6444 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,pDrvDivxTbl->u32StAdd,temp);
6445 memset((void*)(MS_PA2KSEG1(temp)),0,u32Val);
6446 MsOS_FlushMemory();
6447 MsOS_ReadMemory();
6448 #endif
6449 #endif
6450 }
6451
MVD_SLQTblInitDrvEsTbl(MVD_SLQ_ES_ST * pDrvEsTbl,MS_VIRT u32StAdd,MS_U32 u32Val)6452 static void MVD_SLQTblInitDrvEsTbl(MVD_SLQ_ES_ST* pDrvEsTbl, MS_VIRT u32StAdd, MS_U32 u32Val)
6453 {
6454 UNUSED(u32Val);
6455 MS_PHY temp = 0;
6456 ///// init ES table
6457 pDrvEsTbl->u32StAdd = u32StAdd;
6458 pDrvEsTbl->u32EndAdd= pDrvEsTbl->u32StAdd + ES_TBL_SIZE;
6459 pDrvEsTbl->u32WrPtr = pDrvEsTbl->u32StAdd;
6460 //reset ES table
6461 #if 0
6462 _MVD_Memset(pDrvEsTbl->u32StAdd, 0, ES_TBL_SIZE);
6463 #else
6464 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,pDrvEsTbl->u32StAdd,temp);
6465 memset((void*)(MS_PA2KSEG1(temp)),0,ES_TBL_SIZE);
6466 MsOS_FlushMemory();
6467 MsOS_ReadMemory();
6468 #endif
6469 }
6470
6471 //------------------------------------------------------------------------------------------------------------
6472 // Layout of drvProcBuffer
6473 // -----------------
6474 // drvProcBuff | SlqTbl entries | <- pstSlqTblInfo->pDrvSlqTbl->u32StAdd
6475 // | 8K bytes |
6476 // | (1024 entries) |
6477 // | |
6478 // |-----------------|
6479 // | DivX311 | <- pstSlqTblInfo->pDrvSlqTbl->u32EndAdd <- pstSlqTblInfo->pDrvDivxTbl->u32StAdd
6480 // | 8K bytes |
6481 // | (1024 entries) |
6482 // | |
6483 // |-----------------|
6484 // | Flush Patterns |... <- pstSlqTblInfo->pDrvDivxTbl->u32EndAdd <- _drvDummy.u32StAdd
6485 // | 8K bytes |
6486 // | (1024 entries) |
6487 // | |
6488 // |-----------------|
6489 // | FileEnd Pattern |... <- _drvDummy.u32EndAdd <- _drvFileEnd.u32StAdd
6490 // | 8K bytes |
6491 // | (1024 entries) |
6492 // | |
6493 // |-----------------|
6494 // | ES table |... <- _drvFileEnd.u32EndAdd <- pstSlqTblInfo->pDrvEsTbl->u32StAdd
6495 // | 8K bytes |
6496 // | (1024 entries) |
6497 // | |
6498 // |-----------------|
6499 // | |........ End of drvProcBuff
6500 //
6501 //------------------------------------------------------------------------------------------------------------
HAL_MVD_SLQTblInit(MS_U8 u8Idx)6502 MS_BOOL HAL_MVD_SLQTblInit(MS_U8 u8Idx)
6503 {
6504 MS_VIRT u32Addr, u32Len;
6505 MVD_CodecType curCodecType = HAL_MVD_GetCodecType(u8Idx);
6506 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
6507 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
6508
6509 if(curCodecType == E_MVD_CODEC_UNKNOWN)
6510 {
6511 MVD_DEBUGERROR(printf("%s: unknow codec type!\n", __FUNCTION__));
6512 return FALSE;
6513 }
6514 pstSlqTblInfo->u32DummyPktCnt = 0;//reset dummy packet counter
6515 pstSlqTblInfo->u32SlqByteCnt = 0; //reset SLQ table byte counter
6516 pstSlqTblInfo->bSlqTblHasValidData = FALSE;
6517
6518 HAL_MVD_MemGetMap(u8Idx, E_MVD_MMAP_DRV, &u32Addr, &u32Len);
6519
6520 //init SLQ table attributes & reset SLQ table read/write pointers
6521 MVD_SLQTblInitDrvSlqTbl(pstSlqTblInfo->pDrvSlqTbl, u32Addr);
6522 pstSlqTblInfo->u32FileEndPtr = pstSlqTblInfo->pDrvSlqTbl->u32StAdd;
6523
6524 MVD_SLQTblInitSlqStatus(pstSlqTblInfo->pSlqStatus, pstSlqTblInfo->pDrvSlqTbl->u32WrPtr);
6525
6526 //set SLQ table start/end to F/W
6527 HAL_MVD_SetSLQTblBufStartEnd(u8Idx, HAL_MVD_GetMemOffset(pstMemCfg->u32BSAddr), HAL_MVD_GetMemOffset(pstMemCfg->u32BSAddr+SLQ_TBL_SIZE));
6528
6529 ///// init SLQ entries for DivX311
6530 MVD_SLQTblInitDrvDivxTbl(pstSlqTblInfo->pDrvDivxTbl, pstSlqTblInfo->pDrvSlqTbl->u32EndAdd, SLQ_TBL_SIZE);
6531
6532 ///// init flush pattern
6533 MVD_SLQTblInitDummyPkt(u8Idx, curCodecType);
6534
6535 ///// init file-end pattern
6536 MVD_SLQTblInitFileEndPkt(u8Idx, curCodecType);
6537
6538 MVD_SLQTblInitDrvEsTbl(pstSlqTblInfo->pDrvEsTbl, (pstSlqTblInfo->pDrvDivxTbl->u32EndAdd + DUMMY_SIZE*2), pstMemCfg->u32DrvBufSize);
6539
6540 pstSlqTblInfo->u32PreEsRd = MVD_U32_MAX; //reset ES read pointer
6541 pstSlqTblInfo->u32PreEsWr = 0; //reset ES write pointer
6542
6543 return TRUE;
6544 }
6545
6546
6547 #if 0
6548 static void _SLQTbl_DumpInfo(MVD_SLQ_TBL_ST* pInfo)
6549 {
6550 printf("str=0x%x\n", pInfo->u32StAdd);
6551 printf("end=0x%x\n", pInfo->u32EndAdd);
6552 printf("cnt=0x%x\n", pInfo->u32EntryCntMax);
6553 printf("rd =0x%x\n", pInfo->u32RdPtr);
6554 printf("wr =0x%x\n", pInfo->u32WrPtr);
6555 return;
6556 }
6557 #endif
6558
6559
HAL_MVD_GetQueueVacancy(MS_U8 u8Idx,MS_BOOL bCached)6560 MS_U32 HAL_MVD_GetQueueVacancy(MS_U8 u8Idx, MS_BOOL bCached)
6561 {
6562 MS_U32 u32Empty;
6563 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
6564
6565 #if 0
6566 if (MDrv_MVD_GetVldErrCount()!=0)
6567 {
6568 printf("QQQ wPtr= 0x%x(0x%x) rPtr=0x%x(0x%x) vldErr=0x%x\n", writePtrLast[u8Idx], pstSlqTblInfo->pDrvSlqTbl->u32WrPtr,
6569 HAL_MVD_GetSLQReadPtr(u8Idx), pstSlqTblInfo->pDrvSlqTbl->u32RdPtr, MDrv_MVD_GetVldErrCount(u8Idx));
6570 printf("Previous EsRead=0x%x EsWrite=0x%x\n", pstSlqTblInfo->u32PreEsRd, pstSlqTblInfo->u32PreEsWr);
6571 _SLQTbl_DumpPtsTbl(u8Idx, 0x0, 0x620);
6572 while(1);
6573 }
6574 #endif
6575
6576 u32Empty = pstSlqTblInfo->pDrvSlqTbl->u32Empty;
6577 if ((TRUE == bCached) && (u32Empty > SLQTBL_CHECKVACANCY_WATERLEVEL))
6578 {
6579 //To have better performance, we only query F/W read pointer
6580 //when queue_vacancy is lower than water_level
6581 if (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr > pstSlqTblInfo->pDrvSlqTbl->u32RdPtr)
6582 {
6583 u32Empty = SLQ_TBL_SIZE - (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr - pstSlqTblInfo->pDrvSlqTbl->u32RdPtr);
6584 }
6585 else
6586 {
6587 u32Empty = pstSlqTblInfo->pDrvSlqTbl->u32RdPtr - pstSlqTblInfo->pDrvSlqTbl->u32WrPtr;
6588 }
6589
6590 if (u32Empty == 0)// && (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr == pstSlqTblInfo->pDrvSlqTbl->u32StAdd))
6591 {
6592 u32Empty = SLQ_TBL_SIZE;
6593 }
6594 u32Empty -= SLQ_TBL_SAFERANGE;
6595 return (u32Empty / SLQ_ENTRY_LEN);
6596 }
6597
6598 pstSlqTblInfo->pDrvSlqTbl->u32RdPtr = HAL_MVD_Map2DrvSlqTbl(u8Idx, HAL_MVD_GetSLQReadPtr(u8Idx));
6599 //printf("QV=0x%x rd=0x%x==>", u32Empty, pstSlqTblInfo->pDrvSlqTbl->u32RdPtr);
6600 if (pstSlqTblInfo->pDrvSlqTbl->u32RdPtr >= (pstSlqTblInfo->pDrvSlqTbl->u32StAdd+SLQ_ENTRY_LEN))
6601 {
6602 if (pstSlqTblInfo->pDrvSlqTbl->u32RdPtr >= pstSlqTblInfo->pDrvSlqTbl->u32EndAdd)
6603 {
6604 MVD_DEBUGERROR(printf("%s: readPtr 0x%lx out of range: too large!\n",
6605 __FUNCTION__, (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32RdPtr));
6606 }
6607 pstSlqTblInfo->pDrvSlqTbl->u32RdPtr -= SLQ_ENTRY_LEN;
6608 }
6609 else if (pstSlqTblInfo->pDrvSlqTbl->u32RdPtr == pstSlqTblInfo->pDrvSlqTbl->u32StAdd)
6610 {
6611 pstSlqTblInfo->pDrvSlqTbl->u32RdPtr = pstSlqTblInfo->pDrvSlqTbl->u32EndAdd - SLQ_ENTRY_LEN;
6612 }
6613 else
6614 {
6615 MVD_DEBUGERROR(printf("%s: readPtr 0x%lx out of range: too small!\n",
6616 __FUNCTION__, (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32RdPtr));
6617 pstSlqTblInfo->pDrvSlqTbl->u32RdPtr = pstSlqTblInfo->pDrvSlqTbl->u32StAdd;
6618 }
6619 //printf("0x%x\n", pstSlqTblInfo->pDrvSlqTbl->u32RdPtr);
6620
6621 if (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr > pstSlqTblInfo->pDrvSlqTbl->u32RdPtr)
6622 {
6623 u32Empty = SLQ_TBL_SIZE - (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr - pstSlqTblInfo->pDrvSlqTbl->u32RdPtr);
6624 }
6625 else
6626 {
6627 u32Empty = pstSlqTblInfo->pDrvSlqTbl->u32RdPtr - pstSlqTblInfo->pDrvSlqTbl->u32WrPtr;
6628 }
6629
6630 if (u32Empty == 0)// && (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr == pstSlqTblInfo->pDrvSlqTbl->u32StAdd))
6631 {
6632 u32Empty = SLQ_TBL_SIZE;
6633 }
6634
6635 pstSlqTblInfo->pDrvSlqTbl->u32Empty = u32Empty;
6636
6637 if (u32Empty < SLQ_TBL_SAFERANGE)
6638 {//to avoid write_pointer catch up to read_pointer
6639 u32Empty= 0;
6640 }
6641 else
6642 {
6643 u32Empty -= SLQ_TBL_SAFERANGE;
6644 }
6645
6646 //printf("%s r=0x%x w=0x%x u32Empty=0x%x\n", __FUNCTION__,
6647 // pstSlqTblInfo->pDrvSlqTbl->u32RdPtr, pstSlqTblInfo->pDrvSlqTbl->u32WrPtr, u32Empty);
6648 return (u32Empty / SLQ_ENTRY_LEN);
6649 }
6650
HAL_MVD_PushQueue(MS_U8 u8Idx,MVD_PacketInfo * pInfo)6651 E_MVD_Result HAL_MVD_PushQueue(MS_U8 u8Idx, MVD_PacketInfo* pInfo)
6652 {
6653 E_MVD_Result eRet=E_MVD_RET_INVALID_PARAM;
6654 MVD_CodecType curCodecType = HAL_MVD_GetCodecType(u8Idx);
6655 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
6656 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
6657 MS_U32 u32Id = MVD_GetStreamId(u8Idx);
6658 MS_U8 u8VPUIdx = HAL_VPU_EX_GetTaskId(u32Id);
6659 #ifdef VDEC3
6660 MS_VIRT u32VBBUAddr = HAL_MVD_GetVBBUTableAddr(u8VPUIdx);
6661 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
6662 #endif
6663 if (pInfo == NULL)
6664 {
6665 MVD_DEBUGERROR(printf("PushQueue NULL pInfo\n"));
6666 return E_MVD_RET_INVALID_PARAM;
6667 }
6668
6669 #ifndef VDEC3
6670 if(pMVDHalContext->bAutoInsertDummyPattern[u8Idx] == TRUE)
6671 #else
6672 if(pstCtrlCfg->u8McuMode == TRUE)
6673 #endif
6674 {
6675 MS_U8* temp = (MS_U8*)(MS_PA2KSEG1( (MS_PHY)(pInfo->u32StAddr)+pstMemCfg->u32BSAddr));
6676 MS_U32 i;
6677 MS_U32 u32DummyPattern[3];
6678 MS_U32 u32PatternSize;
6679
6680 switch (curCodecType)
6681 {
6682 case E_MVD_CODEC_FLV:
6683 case E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER:
6684 u32DummyPattern[0] = FLV_PATTERN;
6685 u32PatternSize = 1;
6686 break;
6687
6688 case E_MVD_CODEC_DIVX311:
6689 u32DummyPattern[0] = DIVX_PATTERN;
6690 u32PatternSize = 1;
6691 break;
6692
6693 case E_MVD_CODEC_VC1_ADV: //vc1
6694 u32DummyPattern[0] = VC1_PATTERN_0;
6695 u32DummyPattern[1] = VC1_PATTERN_3;
6696 u32PatternSize = 2;
6697 break;
6698 case E_MVD_CODEC_VC1_MAIN: //rcv
6699 u32DummyPattern[0] = RCV_PATTERN_3;
6700 u32DummyPattern[1] = RCV_PATTERN_1;
6701 u32DummyPattern[2] = RCV_PATTERN_3;
6702 u32PatternSize = 3;
6703 break;
6704
6705 default:
6706 u32DummyPattern[0] = DUMMY_PATTERN;
6707 u32DummyPattern[1] = DUMMY_PATTERN;
6708 u32PatternSize = 2;
6709 break;
6710 }
6711
6712
6713 for (i=0; i<u32PatternSize; i++)
6714 {
6715 temp[4*i+pInfo->u32Length] = ((u32DummyPattern[i])&0xff);
6716 temp[4*i+pInfo->u32Length+1] = ((u32DummyPattern[i]>>8)&0xff);
6717 temp[4*i+pInfo->u32Length+2] = ((u32DummyPattern[i]>>16)&0xff);
6718 temp[4*i+pInfo->u32Length+3] = ((u32DummyPattern[i]>>24)&0xff);
6719 }
6720
6721 for(i=u32PatternSize*4;i<256;i++)
6722 {
6723 temp[pInfo->u32Length+i] = 0xFF;
6724 }
6725
6726 pInfo->u32Length += 256;
6727 }
6728
6729
6730 #if _SLQTBL_DUMP_PUSHQ
6731 {
6732 //static MS_U32 u32pqTimes[MAX_DEC_NUM]= {0, 0};
6733
6734 printf("Push[%x] st=0x%x len=0x%x pts=0x%x\n", pMVDHalContext->u32pqTimes[u8Idx]++,
6735 pInfo->u32StAddr, pInfo->u32Length, pInfo->u32TimeStamp);
6736 }
6737 #endif
6738
6739 #if SLQ_NEW_PUSH
6740 if((pInfo->u32StAddr & SLQ_PIC_START_FLAG) == SLQ_PIC_START_FLAG)
6741 {
6742 pInfo->u32StAddr = pInfo->u32StAddr&~SLQ_PIC_START_FLAG;
6743 pstSlqTblInfo->pSlqStatus->bSlqPicStart =TRUE;
6744 pstSlqTblInfo->pSlqStatus->bSlqCtrlBit = TRUE;
6745 }
6746 else
6747 {
6748 pstSlqTblInfo->pSlqStatus->bSlqPicStart = FALSE;
6749 }
6750 #endif
6751 //check input parameters
6752 if (pInfo->u32StAddr >= pstMemCfg->u32BSSize)
6753 {
6754 //since u32StAddr is offset, it shouldn't be larger than size.
6755 MVD_DEBUGERROR(printf("PushQueue invalid u32StAddr=0x%lx, bsSize=0x%lx\n", (unsigned long)pInfo->u32StAddr, (unsigned long)pstMemCfg->u32BSSize));
6756 return E_MVD_RET_INVALID_PARAM;
6757 }
6758 else if ((pInfo->u32TimeStamp == MVD_NULLPKT_PTS) && (pInfo->u32Length==0))
6759 {
6760 // AVI NULL packet.
6761 pstSlqTblInfo->u32DummyPktCnt++;
6762 //printf("Pos:0x%x%08x; PTS:%08d; NullPKT:%d\n", pInfo->u32ID_H, pInfo->u32ID_L, pInfo->u32TimeStamp, pstSlqTblInfo->u32DummyPktCnt);
6763 return E_MVD_RET_OK;
6764 }
6765
6766 if (FALSE == (HAL_MVD_IsMStreamerMode(u8Idx) ||HAL_MVD_IsMcuMode(u8Idx)))
6767 { //Check repeat PTS for non-MStreamer/Mcu mode.
6768 //printf(".Pos:0x%x%08x; PTS:%08d; NullPKT:%d\n", pInfo->u32ID_H, pInfo->u32ID_L, pInfo->u32TimeStamp, pstSlqTblInfo->u32DummyPktCnt);
6769 if (pInfo->u32TimeStamp == pstSlqTblInfo->u32LastPts)
6770 {
6771 //printf("Repeat PTS!\n");
6772 if (pInfo->u32TimeStamp != MVD_NULLPKT_PTS)
6773 pInfo->u32TimeStamp = MVD_NULLPKT_PTS; //repeat PTS
6774 }
6775 else
6776 {
6777 pstSlqTblInfo->u32LastPts = pInfo->u32TimeStamp;
6778 }
6779 }
6780
6781 //check queue vacancy
6782 if (pstSlqTblInfo->pDrvSlqTbl->u32Empty >= SLQ_TBL_SAFERANGE)
6783 { //put packets
6784 #if SLQ_NEW_PUSH
6785 if (E_MVD_CODEC_DIVX311 == curCodecType
6786 ||E_MVD_CODEC_VC1_MAIN == curCodecType //rcv
6787 ||E_MVD_CODEC_VC1_ADV == curCodecType)
6788 {
6789 MVD_PacketInfo stHdr;
6790 if((pstSlqTblInfo->pSlqStatus->bSlqCtrlBit) || (E_MVD_CODEC_DIVX311 == curCodecType))
6791 {
6792 MVD_SLQTblGetHdrPkt(u8Idx, &stHdr, pInfo);
6793
6794 if(pstSlqTblInfo->pSlqStatus->bSlqPicStart||(!pstSlqTblInfo->pSlqStatus->bSlqCtrlBit))
6795 {
6796 if (HAL_MVD_IsMStreamerMode(u8Idx) || HAL_MVD_IsMcuMode(u8Idx))
6797 { //to mark this packet's pts as unused.
6798 stHdr.u32TimeStamp = MVD_NULLPKT_PTS;
6799 stHdr.u32ID_H = MVD_NULLPKT_PTS;
6800 }
6801 #ifdef VDEC3
6802 if(pstCtrlCfg->u8McuMode == TRUE)
6803 {
6804 if(HAL_VPU_EX_GetVBBUVacancy(u32VBBUAddr) > 1)
6805 {
6806 HAL_VPU_EX_PacketInfo stVpuPkt;
6807
6808 stVpuPkt.u32Offset = stHdr.u32StAddr;
6809 stVpuPkt.u32Length = stHdr.u32Length;
6810 stVpuPkt.u64TimeStamp = (MS_U64)stHdr.u32TimeStamp;
6811 //If in display queue mode
6812 stVpuPkt.u64TimeStamp |= ((MS_U64)stHdr.u32ID_H << 32);
6813 stVpuPkt.u32ID_H = stHdr.u32ID_H;
6814 stVpuPkt.u32ID_L = stHdr.u32ID_L;
6815
6816 pstSlqTblInfo->bSlqTblHasValidData = TRUE;
6817 eRet = (E_MVD_Result)HAL_VPU_EX_Push2VBBU(u32Id, &stVpuPkt, u32VBBUAddr);
6818 }
6819 else
6820 {
6821 return E_MVD_RET_FAIL;
6822 }
6823 }
6824 else
6825 #endif
6826 {
6827 HAL_MVD_SLQTblSendPacket(u8Idx, &stHdr);
6828 }
6829 }
6830 }
6831 }
6832 #else
6833 if (E_MVD_CODEC_DIVX311 == curCodecType)
6834 {
6835 MVD_PacketInfo stDivxHdr;
6836 MVD_SLQTblGetDivxHdrPkt(u8Idx, &stDivxHdr, pInfo);
6837 if (HAL_MVD_IsMStreamerMode(u8Idx) || HAL_MVD_IsMcuMode(u8Idx))
6838 { //to mark this packet's pts as unused.
6839 stDivxHdr.u32TimeStamp = MVD_NULLPKT_PTS;
6840 stDivxHdr.u32ID_H = MVD_NULLPKT_PTS;
6841 }
6842 HAL_MVD_SLQTblSendPacket(u8Idx, &stDivxHdr);
6843 }
6844 #endif
6845
6846 #ifdef VDEC3
6847 if(pstCtrlCfg->u8McuMode == TRUE)
6848 {
6849 if(HAL_VPU_EX_GetVBBUVacancy(u32VBBUAddr) > 0)
6850 {
6851 HAL_VPU_EX_PacketInfo stVpuPkt;
6852
6853 stVpuPkt.u32Offset = pInfo->u32StAddr;
6854 stVpuPkt.u32Length = pInfo->u32Length;
6855 stVpuPkt.u64TimeStamp = (MS_U64)pInfo->u32TimeStamp;
6856 //If in display queue mode
6857 stVpuPkt.u64TimeStamp |= ((MS_U64)pInfo->u32ID_H << 32);
6858 stVpuPkt.u32ID_H = pInfo->u32ID_H;
6859 stVpuPkt.u32ID_L = pInfo->u32ID_L;
6860
6861 pstSlqTblInfo->bSlqTblHasValidData = TRUE;
6862 eRet = (E_MVD_Result)HAL_VPU_EX_Push2VBBU(u32Id, &stVpuPkt, u32VBBUAddr);
6863 //VPRINTF("[%d]%s[%d],ret=%d,u32StAddr %x,u32Length %d,u32TimeStamp %d\n",u8Idx,__FUNCTION__,__LINE__,eRet,(unsigned int)pInfo->u32StAddr,(unsigned int)pInfo->u32Length,(unsigned int)pInfo->u32TimeStamp);
6864 return eRet;
6865 }
6866 else
6867 {
6868 return E_MVD_RET_FAIL;
6869 }
6870 }
6871 else
6872 #endif
6873 {
6874 HAL_MVD_SLQTblSendPacket(u8Idx, pInfo);
6875 eRet=E_MVD_RET_OK;
6876 pstSlqTblInfo->bSlqTblHasValidData = TRUE;
6877 }
6878 }
6879 else
6880 {
6881 MS_ASSERT(0); //shouldn't be here!
6882 MVD_DEBUGERROR(printf("PushQueue FULL!!! empty=0x%lx\n", (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32Empty));
6883 //Player will only push queue when queue vacancy != 0
6884 eRet=E_MVD_RET_QUEUE_FULL;
6885 }
6886
6887 if (E_MVD_RET_OK != eRet)
6888 {
6889 MVD_DEBUGERROR(printf("%s ret = %d\n", __FUNCTION__, eRet));
6890 }
6891 return eRet;
6892 }
6893
6894
MVD_FlushTSQueue(MS_U8 u8Idx)6895 static E_MVD_Result MVD_FlushTSQueue(MS_U8 u8Idx)
6896 {
6897 if (HAL_MVD_GetLastCmd(u8Idx)!=CMD_PAUSE)
6898 {
6899 HAL_MVD_PauseDisp(u8Idx);
6900 HAL_MVD_DecodePause(u8Idx);
6901 HAL_MVD_FlushDisplayBuf(u8Idx);
6902 }
6903
6904 if(HAL_MVD_SkipData(u8Idx) == FALSE)
6905 {
6906 return E_MVD_RET_FAIL;
6907 }
6908 else
6909 {
6910 return E_MVD_RET_OK;
6911 }
6912 }
6913
6914
MVD_PatternLenIsValid(MS_U8 u8Idx,MS_U32 u32Len)6915 static MS_BOOL MVD_PatternLenIsValid(MS_U8 u8Idx, MS_U32 u32Len)
6916 {
6917 MS_U32 u32ValidLen = 0;
6918 MVD_CodecType curCodecType = HAL_MVD_GetCodecType(u8Idx);
6919 #define MAX_VALIDLEN 0x200000 //2M
6920
6921 if (E_MVD_CODEC_VC1_MAIN != curCodecType)
6922 {
6923 return TRUE;
6924 }
6925 else
6926 {
6927 //only RCV has to check this
6928 u32ValidLen = HAL_MVD_GetPayloadLen(u8Idx);
6929 if (u32ValidLen > MAX_VALIDLEN)
6930 { //avoid the extreme large value due to error bitstream
6931 u32ValidLen = MAX_VALIDLEN;
6932 }
6933 MVD_DEBUGINFO(printf("(%x) ValidLen=0x%x CurLen=0x%x\n",
6934 (u32Len > u32ValidLen), u32ValidLen, u32Len));
6935 return (u32Len > u32ValidLen);
6936 }
6937 }
6938
MVD_FlushSlqTblQueue(MS_U8 u8Idx)6939 static E_MVD_Result MVD_FlushSlqTblQueue(MS_U8 u8Idx)
6940 {
6941 MS_U32 u32TimeCnt;
6942 MS_U32 u32PatternByteCnt = 0;
6943 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
6944 MS_U32 u32Id = MVD_GetStreamId(u8Idx);
6945 MS_U8 u8VPUIdx = HAL_VPU_EX_GetTaskId(u32Id);
6946 #ifdef VDEC3
6947 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
6948 MS_VIRT u32VBBUAddr = HAL_MVD_GetVBBUTableAddr(u8VPUIdx);
6949 #endif
6950 HAL_MVD_ResetHandShake(u8Idx,MVD_HANDSHAKE_PAUSE);
6951 HAL_MVD_PauseDisp(u8Idx);
6952 HAL_MVD_DecodePause(u8Idx);
6953 HAL_MVD_FlushDisplayBuf(u8Idx);
6954
6955 u32TimeCnt = HAL_MVD_GetTime();
6956 while (((HAL_MVD_GetTime() - u32TimeCnt) < CMD_TIMEOUT_MS) ||
6957 (TRUE != MVD_PatternLenIsValid(u8Idx, u32PatternByteCnt)))
6958 {
6959 if (HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_PAUSE))
6960 {
6961 MVD_DEBUGINFO(printf("\nPause finished!\n"));
6962 break;
6963 }
6964
6965 #ifdef VDEC3
6966 if(pstCtrlCfg->u8McuMode == TRUE)
6967 {
6968 if(HAL_VPU_EX_GetVBBUVacancy(u32VBBUAddr) > 0)
6969 {
6970 HAL_VPU_EX_PacketInfo stVpuPkt;
6971 MVD_PacketInfo stDummyPkt;
6972 MVD_SLQTblGetDummyPkt(&stDummyPkt);
6973
6974 stVpuPkt.u32Offset = stDummyPkt.u32StAddr;
6975 stVpuPkt.u32Length = stDummyPkt.u32Length;
6976 stVpuPkt.u64TimeStamp = (MS_U64)stDummyPkt.u32TimeStamp;
6977 //If in display queue mode
6978 stVpuPkt.u64TimeStamp |= ((MS_U64)stDummyPkt.u32ID_H << 32);
6979 stVpuPkt.u32ID_H = stDummyPkt.u32ID_H;
6980 stVpuPkt.u32ID_L = stDummyPkt.u32ID_L;
6981
6982 HAL_VPU_EX_Push2VBBU(u32Id, &stVpuPkt,u32VBBUAddr);
6983 }
6984 }
6985 else
6986 #endif
6987 {
6988 if (pstSlqTblInfo->pDrvSlqTbl->u32Empty < SLQ_TBL_SAFERANGE)
6989 {
6990 HAL_MVD_GetQueueVacancy(u8Idx, FALSE); //update pstSlqTblInfo->pDrvSlqTbl->u32Empty
6991 HAL_MVD_Delayms(1); //avoid busy query
6992 }
6993 //insert dummy pattern
6994 if (TRUE == HAL_MVD_SLQTblInsertPattern(u8Idx, E_MVD_PATTERN_FLUSH))
6995 {
6996 u32PatternByteCnt += DUMMY_SIZE*2; //2 dummy were inserted
6997 }
6998 }
6999
7000
7001 //Timeout for RCV
7002 if ((HAL_MVD_GetTime() - u32TimeCnt) > (CMD_TIMEOUT_MS*10))
7003 {
7004 MVD_DEBUGERROR(printf("RCV timeout!!! pl=%d, pbc=%d, emp=%ld\n",
7005 HAL_MVD_GetPayloadLen(u8Idx), u32PatternByteCnt,
7006 (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32Empty));
7007 break;
7008 }
7009 }
7010 MVD_DEBUGINFO(printf("====> %s (t1=%u t2=%u diff=%u)\n", __FUNCTION__,
7011 u32TimeCnt, HAL_MVD_GetTime(), (HAL_MVD_GetTime() - u32TimeCnt)));
7012 //if ((HAL_MVD_GetTime() - u32TimeCnt) >= CMD_TIMEOUT_MS)
7013 if (TRUE != HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_PAUSE))
7014 {
7015 MVD_DEBUGERROR(printf("\n***** MDrv_MVD_FlushQueue PAUSE TIMEOUT!!! *****\n\n"));
7016 MVD_DEBUGERROR(printf("ValidLen=0x%x CurPatternLen=0x%x\n",
7017 HAL_MVD_GetPayloadLen(u8Idx), u32PatternByteCnt));
7018
7019 return E_MVD_RET_FAIL;
7020 }
7021
7022 //flush ES buffer & reset SLQ tbl
7023 HAL_MVD_ResetHandShake(u8Idx, MVD_HANDSHAKE_SLQ_RST);
7024 if (HAL_MVD_SlqTblRst(u8Idx) == TRUE)
7025 {
7026 //return E_MVD_RET_OK;
7027 }
7028
7029 u32TimeCnt = HAL_MVD_GetTime();
7030 while (((HAL_MVD_GetTime() - u32TimeCnt) < CMD_TIMEOUT_MS))
7031 {
7032 if (HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_SLQ_RST))
7033 {
7034 MVD_DEBUGINFO(printf("\nSlqRst finished!\n"));
7035 break;
7036 }
7037 }
7038 MVD_DEBUGINFO(printf("====> %s (t1=%u t2=%u diff=%u)\n", __FUNCTION__,
7039 u32TimeCnt, HAL_MVD_GetTime(), (HAL_MVD_GetTime() - u32TimeCnt)));
7040 if (TRUE != HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_SLQ_RST))
7041 {
7042 MVD_DEBUGERROR(printf("\n***** MDrv_MVD_FlushQueue SlqRst TIMEOUT!!! *****\n\n"));
7043 return E_MVD_RET_FAIL;
7044 }
7045
7046 HAL_MVD_SLQTblInit(u8Idx); //reset related buffers
7047
7048 return E_MVD_RET_OK;
7049 }
7050
HAL_MVD_FlushQueue(MS_U8 u8Idx)7051 E_MVD_Result HAL_MVD_FlushQueue(MS_U8 u8Idx)
7052 {
7053 E_MVD_Result eRet = E_MVD_RET_OK;
7054 MVD_SrcMode curSrcMode = HAL_MVD_GetSrcMode(u8Idx);
7055
7056 if (HAL_MVD_GetDecodeStatus(u8Idx) == E_MVD_STAT_IDLE)
7057 {
7058 return eRet;
7059 }
7060
7061 //flush ES buffer (and cmd queue if used)
7062 if (E_MVD_SLQ_TBL_MODE == curSrcMode)
7063 {
7064 eRet = MVD_FlushSlqTblQueue(u8Idx);
7065 }
7066 else if (E_MVD_TS_FILE_MODE == curSrcMode)
7067 {
7068 eRet = MVD_FlushTSQueue(u8Idx);
7069 }
7070 if (E_MVD_RET_OK != eRet)
7071 {
7072 return eRet;
7073 }
7074
7075 MVD_RstFrmInfo(u8Idx, E_MVD_FRMINFO_DECODE);
7076 //flush display buffer
7077
7078 if (HAL_MVD_FlushDisplayBuf(u8Idx) != TRUE)
7079 {
7080 return E_MVD_RET_FAIL;
7081 }
7082
7083 if (TRUE == HAL_MVD_SkipToIFrame(u8Idx))
7084 {
7085 return E_MVD_RET_OK;
7086 }
7087 else
7088 {
7089 return E_MVD_RET_FAIL;
7090 }
7091 }
7092
HAL_MVD_IsAllBufferEmpty(MS_U8 u8Idx)7093 MS_BOOL HAL_MVD_IsAllBufferEmpty(MS_U8 u8Idx)
7094 {
7095 return HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_SKIP_DATA);
7096 }
7097
HAL_MVD_EnableInt(MS_U8 u8Idx,MS_U32 bEn)7098 MS_BOOL HAL_MVD_EnableInt(MS_U8 u8Idx, MS_U32 bEn)
7099 {
7100 MVD_CmdArg mvdcmd;
7101 MS_U32 u32IntFlag = 0;
7102
7103 u32IntFlag = (((bEn & E_MVD_EVENT_USER_DATA) == E_MVD_EVENT_USER_DATA) ? INT_USER_DATA : 0) |
7104 (((bEn & E_MVD_EVENT_USER_DATA_DISP) == E_MVD_EVENT_USER_DATA_DISP) ? INT_USER_DATA_DISP : 0) |
7105 (((bEn & E_MVD_EVENT_PIC_FOUND) == E_MVD_EVENT_PIC_FOUND) ? INT_PIC_FOUND : 0) |
7106 (((bEn & E_MVD_EVENT_FIRST_FRAME) == E_MVD_EVENT_FIRST_FRAME) ? INT_FIRST_FRAME : 0) |
7107 (((bEn & E_MVD_EVENT_DISP_RDY) == E_MVD_EVENT_DISP_RDY) ? INT_DISP_RDY : 0) |
7108 (((bEn & E_MVD_EVENT_SEQ_FOUND) == E_MVD_EVENT_SEQ_FOUND) ? INT_SEQ_FOUND : 0)|
7109 (((bEn & E_MVD_EVENT_DEC_ONE_FRAME) == E_MVD_EVENT_DEC_ONE_FRAME) ? INT_DEC_DONE : 0)|
7110 (((bEn & E_MVD_EVENT_DEC_ERR) == E_MVD_EVENT_DEC_ERR) ? INT_DEC_ERR : 0)|
7111 (((bEn & E_MVD_EVENT_DEC_DATA_ERR) == E_MVD_EVENT_DEC_DATA_ERR) ? INT_VES_INVALID : 0)|
7112 (((bEn & E_MVD_EVENT_XC_LOW_DEALY) == E_MVD_EVENT_XC_LOW_DEALY) ? INT_XC_LOW_DELAY : 0)|
7113 (((bEn & E_MVD_EVENT_DEC_I) == E_MVD_EVENT_DEC_I) ? INT_DEC_I : 0);
7114 if (((bEn & E_MVD_EVENT_DISP_VSYNC) == E_MVD_EVENT_DISP_VSYNC) ||
7115 ((bEn & E_MVD_EVENT_UNMUTE) == E_MVD_EVENT_UNMUTE))
7116 {
7117 u32IntFlag |= INT_DISP_VSYNC;
7118 }
7119
7120 MVD_DEBUGINFO(printf("u32IntFlag = 0x%x\n", u32IntFlag));
7121 SETUP_CMDARG(mvdcmd);
7122 mvdcmd.Arg0 = u32IntFlag & 0xff;
7123 mvdcmd.Arg1 = (u32IntFlag>>8) & 0xff;
7124 mvdcmd.Arg2 = (u32IntFlag>>16) & 0xff;
7125 SET_DECNUM(mvdcmd, u8Idx);
7126 SET_CMD_RET_FALSE(CMD_ENABLE_INT_STAT, &mvdcmd);
7127
7128 return TRUE;
7129 }
7130
HAL_MVD_EnablePTSDetector(MS_U8 u8Idx,MS_BOOL bEn)7131 E_MVD_Result HAL_MVD_EnablePTSDetector(MS_U8 u8Idx, MS_BOOL bEn)
7132 {
7133 MVD_CmdArg stCmdArg;
7134
7135 SETUP_CMDARG(stCmdArg);
7136 if(TRUE == bEn)
7137 {
7138 stCmdArg.Arg0 = 1;
7139 }
7140 SET_DECNUM(stCmdArg, u8Idx);
7141 if (HAL_MVD_MVDCommand(CMD_PTS_DETECTOR_EN, &stCmdArg) == FALSE)
7142 {
7143 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PTS_DETECTOR_EN ) );
7144 return E_MVD_RET_FAIL;
7145 }
7146 return E_MVD_RET_OK;
7147 }
7148
7149
HAL_MVD_EnableDispOneField(MS_U8 u8Idx,MS_BOOL bEn)7150 E_MVD_Result HAL_MVD_EnableDispOneField(MS_U8 u8Idx, MS_BOOL bEn)
7151 {
7152 MVD_CmdArg stCmdArg;
7153
7154 SETUP_CMDARG(stCmdArg);
7155 if(TRUE == bEn)
7156 {
7157 stCmdArg.Arg0 = 1;
7158 }
7159 SET_DECNUM(stCmdArg, u8Idx);
7160 if (HAL_MVD_MVDCommand(CMD_SHOW_ONE_FIELD, &stCmdArg) == FALSE)
7161 {
7162 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SHOW_ONE_FIELD ) );
7163 return E_MVD_RET_FAIL;
7164 }
7165 return E_MVD_RET_OK;
7166 }
7167
HAL_MVD_SetFdMaskDelayCount(MS_U8 u8Idx,MS_U16 u16Cnt)7168 E_MVD_Result HAL_MVD_SetFdMaskDelayCount(MS_U8 u8Idx, MS_U16 u16Cnt)
7169 {
7170 MVD_CmdArg stCmdArg;
7171
7172 SETUP_CMDARG(stCmdArg);
7173 //16bits and unit in vsync for mute the fd_mask
7174 stCmdArg.Arg0 = u16Cnt & 0xff;
7175 stCmdArg.Arg1 = (u16Cnt>>8) & 0xff;
7176 SET_DECNUM(stCmdArg, u8Idx);
7177 if (HAL_MVD_MVDCommand(CMD_FD_MASK_DELAY_CNT, &stCmdArg) == FALSE)
7178 {
7179 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FD_MASK_DELAY_CNT ) );
7180 return E_MVD_RET_FAIL;
7181 }
7182 return E_MVD_RET_OK;
7183 }
7184
HAL_MVD_SetOutputFRCMode(MS_U8 u8Idx,MS_U8 u8FrameRate,MS_U8 u8Interlace)7185 E_MVD_Result HAL_MVD_SetOutputFRCMode(MS_U8 u8Idx, MS_U8 u8FrameRate, MS_U8 u8Interlace)
7186 {
7187 MVD_CmdArg stCmdArg;
7188 if((u8Interlace != 0) && (u8Interlace != 1))
7189 {
7190 return E_MVD_RET_FAIL;
7191 }
7192 SETUP_CMDARG(stCmdArg);
7193 stCmdArg.Arg0 = u8FrameRate;
7194 stCmdArg.Arg1 = u8Interlace;
7195 SET_DECNUM(stCmdArg, u8Idx);
7196 if (HAL_MVD_MVDCommand(CMD_FRC_OUPUT, &stCmdArg) == FALSE)
7197 {
7198 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FRC_OUPUT ) );
7199 return E_MVD_RET_FAIL;
7200 }
7201 return E_MVD_RET_OK;
7202 }
7203
7204
HAL_MVD_SetFRCDropType(MS_U8 u8Idx,MS_U8 u8DropType)7205 E_MVD_Result HAL_MVD_SetFRCDropType(MS_U8 u8Idx, MS_U8 u8DropType)
7206 {
7207 MVD_CmdArg stCmdArg;
7208
7209 if((u8DropType != FRC_DROP_FRAME)
7210 && (u8DropType != FRC_DROP_FIELD))
7211 {
7212 return E_MVD_RET_FAIL;
7213 }
7214
7215 SETUP_CMDARG(stCmdArg);
7216 stCmdArg.Arg0 = u8DropType;
7217 SET_DECNUM(stCmdArg, u8Idx);
7218 if (HAL_MVD_MVDCommand(CMD_FRC_DROP_BEHAVIOR, &stCmdArg) == FALSE)
7219 {
7220 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FRC_DROP_BEHAVIOR ) );
7221 return E_MVD_RET_FAIL;
7222 }
7223 return E_MVD_RET_OK;
7224 }
7225
HAL_MVD_SetDisableSeqChange(MS_U8 u8Idx,MS_BOOL bEnable)7226 E_MVD_Result HAL_MVD_SetDisableSeqChange(MS_U8 u8Idx, MS_BOOL bEnable)
7227 {
7228 MVD_CmdArg stCmdArg;
7229
7230 SETUP_CMDARG(stCmdArg);
7231 stCmdArg.Arg0 = bEnable;
7232 SET_DECNUM(stCmdArg, u8Idx);
7233 if (HAL_MVD_MVDCommand(CMD_FORBID_RESOLUTION_CHANGE, &stCmdArg) == FALSE)
7234 {
7235 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_FORBID_RESOLUTION_CHANGE ) );
7236 return E_MVD_RET_FAIL;
7237 }
7238 MVD_DEBUGINFO(printf("MVD CMD_FORBID_RESOLUTION_CHANGE(0x%x) OK\n", bEnable));
7239
7240 return E_MVD_RET_OK;
7241 }
7242
HAL_MVD_DbgGetData(MS_VIRT u32Addr,MS_U32 * u32Data)7243 E_MVD_Result HAL_MVD_DbgGetData(MS_VIRT u32Addr, MS_U32* u32Data)
7244 {
7245 MVD_CmdArg mvdcmd;
7246 MS_U32 u32Val;
7247
7248 if (!u32Data)
7249 {
7250 return E_MVD_RET_INVALID_PARAM;
7251 }
7252
7253 SET_CMDARG(mvdcmd, u32Addr, 0); //FIXME
7254 if (HAL_MVD_MVDCommand( CMD_RD_IO, &mvdcmd ) == FALSE)
7255 {
7256 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_RD_IO ) );
7257 return E_MVD_RET_FAIL;
7258 }
7259
7260 u32Val = (((MS_U32)mvdcmd.Arg2)) | ((MS_U32)mvdcmd.Arg3 << 8) |
7261 (((MS_U32)mvdcmd.Arg4) << 16) | (((MS_U32)mvdcmd.Arg5) << 24);
7262 *u32Data = u32Val;
7263
7264 return E_MVD_RET_OK;
7265 }
7266
7267
HAL_MVD_DbgDumpBits(MS_U8 u8Idx,MS_PHY u32base,MS_U32 u32size)7268 void HAL_MVD_DbgDumpBits(MS_U8 u8Idx, MS_PHY u32base, MS_U32 u32size)
7269 {
7270 MVD_CmdArg mvdcmd;
7271
7272 u32base = HAL_MVD_GetMemOffset(u32base);
7273 printf("%s base=0x%lx size=0x%x\n", __FUNCTION__, (unsigned long)u32base, u32size);
7274 MS_ASSERT((u32base%8)==0);
7275 u32base >>= 3;
7276 SET_CMDARG(mvdcmd, u32base, u8Idx);
7277 if (HAL_MVD_MVDCommand( CMD_DUMP_BITSTREAM_BASE, &mvdcmd ) == FALSE)
7278 {
7279 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\n", CMD_DUMP_BITSTREAM_BASE ) );
7280 return;
7281 }
7282
7283 MS_ASSERT((u32size%8)==0);
7284 u32size >>= 3;
7285 SET_CMDARG(mvdcmd, u32size, u8Idx);
7286 if (HAL_MVD_MVDCommand( CMD_DUMP_BITSTREAM_LENGTH, &mvdcmd ) == FALSE)
7287 {
7288 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\n", CMD_DUMP_BITSTREAM_LENGTH ) );
7289 return;
7290 }
7291 return;
7292 }
7293
7294
HAL_MVD_GetActiveFormat(MS_U8 u8Idx)7295 MS_U8 HAL_MVD_GetActiveFormat(MS_U8 u8Idx)
7296 {
7297 MVD_CmdArg mvdcmd;
7298 MS_U8 u8Afd = 0;
7299
7300 SETUP_CMDARG(mvdcmd);
7301 SET_DECNUM(mvdcmd, u8Idx);
7302 if (HAL_MVD_MVDCommand( CMD_GET_AFD, &mvdcmd ) == FALSE)
7303 {
7304 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_GET_AFD ) );
7305 return 0xff;
7306 }
7307 u8Afd = mvdcmd.Arg0;
7308 return u8Afd;
7309 }
7310
HAL_MVD_EnableAVSync(MS_U8 u8Idx,MS_BOOL bEnable)7311 MS_BOOL HAL_MVD_EnableAVSync(MS_U8 u8Idx, MS_BOOL bEnable)
7312 {
7313 MVD_CmdArg mvdcmd;
7314 SETUP_CMDARG(mvdcmd);
7315 mvdcmd.Arg0 = bEnable;
7316 SET_DECNUM(mvdcmd, u8Idx);
7317 SET_CMD_RET_FALSE(CMD_SYNC_ON, &mvdcmd);
7318
7319 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
7320 pCtrlCfg->bAVSyncOn = bEnable;
7321
7322 return TRUE;
7323 }
7324
HAL_MVD_SetAVSyncDelay(MS_U8 u8Idx,MS_U32 u32Delay)7325 MS_BOOL HAL_MVD_SetAVSyncDelay(MS_U8 u8Idx, MS_U32 u32Delay)
7326 {
7327 MVD_CmdArg mvdcmd;
7328 SET_CMDARG(mvdcmd, _MS_TO_90K(u32Delay), u8Idx); //u32Delay ms ==> 90k counter
7329 SET_CMD_RET_FALSE(CMD_SYNC_OFFSET, &mvdcmd);
7330 return TRUE;
7331 }
7332
HAL_MVD_SetAVSyncThreshold(MS_U8 u8Idx,MS_U32 u32Th)7333 MS_BOOL HAL_MVD_SetAVSyncThreshold(MS_U8 u8Idx, MS_U32 u32Th)
7334 {
7335 MVD_CmdArg mvdcmd;
7336
7337 if (u32Th == 0x00)
7338 {
7339 return FALSE; //invalid parameter, do nothing
7340 }
7341 if (u32Th > 0xff)
7342 {
7343 u32Th = 0xff; //set to maximum
7344 }
7345
7346 SETUP_CMDARG(mvdcmd);
7347 mvdcmd.Arg3 = u32Th;
7348 SET_DECNUM(mvdcmd, u8Idx);
7349 SET_CMD_RET_FALSE(CMD_SYN_THRESHOLD, &mvdcmd);
7350 return TRUE;
7351 }
7352
HAL_MVD_SetAVSyncFreerunThreshold(MS_U8 u8Idx,MS_U32 u32Th)7353 MS_BOOL HAL_MVD_SetAVSyncFreerunThreshold(MS_U8 u8Idx, MS_U32 u32Th)
7354 {
7355 MVD_CmdArg mvdcmd;
7356 SET_CMDARG(mvdcmd, u32Th, u8Idx);
7357 SET_CMD_RET_FALSE(CMD_AVSYNC_FREERUN_THRESHOLD, &mvdcmd);
7358 return TRUE;
7359 }
7360
HAL_MVD_ChangeAVsync(MS_U8 u8Idx,MS_BOOL bEnable,MS_U16 u16PTS)7361 MS_BOOL HAL_MVD_ChangeAVsync(MS_U8 u8Idx, MS_BOOL bEnable, MS_U16 u16PTS)
7362 {
7363 MVD_CmdArg mvdcmd;
7364
7365 u16PTS = _MS_TO_90K(u16PTS); //u16PTS ms ==> 90k counter
7366 SETUP_CMDARG(mvdcmd);
7367 mvdcmd.Arg0 = (MS_U8)bEnable;
7368 mvdcmd.Arg1 = 0;
7369 mvdcmd.Arg2 = (MS_U8)(u16PTS&0xff);
7370 mvdcmd.Arg3 = (MS_U8)((u16PTS&0xff00)>>8);
7371 SET_DECNUM(mvdcmd, u8Idx);
7372 SET_CMD_RET_FALSE(CMD_MVD_FAST_INT, &mvdcmd);
7373 return TRUE;
7374 }
7375
HAL_MVD_GetIsSyncRep(MS_U8 u8Idx)7376 MS_BOOL HAL_MVD_GetIsSyncRep(MS_U8 u8Idx)
7377 {
7378 MS_U32 u32IntStat = 0;
7379 MS_BOOL bRet = FALSE;
7380
7381 u32IntStat = HAL_MVD_GetIntState(u8Idx);
7382 if (u32IntStat != 0)
7383 {
7384 bRet = ((u32IntStat&INT_SYN_REP)==INT_SYN_REP) ? TRUE : FALSE;
7385 }
7386 return bRet;
7387 }
7388
HAL_MVD_GetIsSyncSkip(MS_U8 u8Idx)7389 MS_BOOL HAL_MVD_GetIsSyncSkip(MS_U8 u8Idx)
7390 {
7391 MS_U32 u32IntStat = 0;
7392 MS_BOOL bRet = FALSE;
7393
7394 u32IntStat = HAL_MVD_GetIntState(u8Idx);
7395 if (u32IntStat != 0)
7396 {
7397 bRet = ((u32IntStat&INT_SYN_SKIP)==INT_SYN_SKIP) ? TRUE : FALSE;
7398 }
7399
7400 return bRet;
7401 }
7402
HAL_MVD_GetIsSyncReach(MS_U8 u8Idx)7403 MS_U8 HAL_MVD_GetIsSyncReach(MS_U8 u8Idx)
7404 {
7405 #define MVD_SYNC_DONE 1
7406 if(MVD_GetSyncStat(u8Idx, 1) == MVD_SYNC_DONE)
7407 return 1;
7408 else
7409 return 0xFF;
7410 }
7411
HAL_MVD_GetDispRdy(MS_U8 u8Idx)7412 MS_U8 HAL_MVD_GetDispRdy(MS_U8 u8Idx)
7413 {
7414 if (HAL_MVD_GetPicCounter(u8Idx) > 0)
7415 {
7416 return 1;
7417 }
7418 else
7419 {
7420 return 0;
7421 }
7422 }
7423
HAL_MVD_GetDecodeStatus(MS_U8 u8Idx)7424 MVD_DecStat HAL_MVD_GetDecodeStatus(MS_U8 u8Idx)
7425 {
7426 MVD_CmdArg mvdcmd;
7427 MVD_DecStat stat = E_MVD_STAT_UNKNOWN;
7428
7429 SETUP_CMDARG(mvdcmd);
7430 SET_DECNUM(mvdcmd, u8Idx);
7431 if (HAL_MVD_MVDCommand(CMD_DECODE_STATUS, &mvdcmd) == FALSE)
7432 {
7433 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DECODE_STATUS ) );
7434 return E_MVD_STAT_UNKNOWN;
7435 }
7436
7437 switch(mvdcmd.Arg1)
7438 {
7439 case DEC_STAT_IDLE:
7440 stat = E_MVD_STAT_IDLE;
7441 break;
7442 case DEC_STAT_FIND_SC:
7443 stat = E_MVD_STAT_FIND_STARTCODE;
7444 break;
7445 case DEC_STAT_FIND_SPE_SC:
7446 stat = E_MVD_STAT_FIND_SPECIALCODE;
7447 break;
7448 case DEC_STAT_FIND_FRAMEBUFFER:
7449 stat = E_MVD_STAT_FIND_FRAMEBUFFER;
7450 break;
7451 case DEC_STAT_WAIT_DECODE_DONE:
7452 stat = E_MVD_STAT_WAIT_DECODEDONE;
7453 break;
7454 case DEC_STAT_DECODE_DONE:
7455 stat = E_MVD_STAT_DECODE_DONE;
7456 break;
7457 case DEC_STAT_WAIT_VDFIFO:
7458 stat = E_MVD_STAT_WAIT_VDFIFO;
7459 break;
7460 case DEC_STAT_INIT_SUCCESS:
7461 stat = E_MVD_STAT_INIT_SUCCESS;
7462 break;
7463 default:
7464 break;
7465 }
7466
7467 return stat;
7468 }
7469
HAL_MVD_GetLastCmd(MS_U8 u8Idx)7470 MS_U8 HAL_MVD_GetLastCmd(MS_U8 u8Idx)
7471 {
7472 MVD_CmdArg mvdcmd;
7473 SETUP_CMDARG(mvdcmd);
7474 SET_DECNUM(mvdcmd, u8Idx);
7475 if (HAL_MVD_MVDCommand( CMD_DECODE_STATUS, &mvdcmd ) == FALSE)
7476 {
7477 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DECODE_STATUS ) );
7478 return 0xff;
7479 }
7480
7481 return (mvdcmd.Arg0);
7482 }
7483
HAL_MVD_GetParserByteCnt(MS_U8 u8Idx)7484 MS_U32 HAL_MVD_GetParserByteCnt(MS_U8 u8Idx)
7485 {
7486 MVD_CmdArg mvdcmd;
7487 MS_U32 u32Cnt = 0;
7488
7489 SETUP_CMDARG(mvdcmd);
7490
7491 //To be accurate, it's "VLD byte count", instead of "parser byte count".
7492 mvdcmd.Arg0 = 0x34;
7493 mvdcmd.Arg1 = 0x2;
7494 SET_DECNUM(mvdcmd, u8Idx);
7495 if (HAL_MVD_MVDCommand( CMD_RD_IO, &mvdcmd ) == FALSE)
7496 {
7497 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail!!\r\n", CMD_RD_IO ) );
7498 return 0;
7499 }
7500 u32Cnt = (((MS_U32)mvdcmd.Arg2)) | ((MS_U32)mvdcmd.Arg3 << 8) |
7501 (((MS_U32)mvdcmd.Arg4) << 16) | (((MS_U32)mvdcmd.Arg5) << 24);
7502
7503 //printf(" parser byte count = %lu byte \n", u32Cnt);
7504 return u32Cnt;
7505 }
7506
HAL_MVD_DropErrorFrame(MS_U8 u8Idx,MS_BOOL bDrop)7507 MS_BOOL HAL_MVD_DropErrorFrame(MS_U8 u8Idx, MS_BOOL bDrop)
7508 {
7509 MVD_CmdArg mvdcmd;
7510 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
7511
7512 SETUP_CMDARG(mvdcmd);
7513 mvdcmd.Arg1 = (MS_U8)bDrop;
7514 mvdcmd.Arg2 = (MS_U8)pstCtrlCfg->bDropDispfrm;
7515 mvdcmd.Arg3 = (MS_U8)pstCtrlCfg->eFrcMode;
7516 SET_DECNUM(mvdcmd, u8Idx);
7517 SET_CMD_RET_FALSE(CMD_DISPLAY_CTL, &mvdcmd);
7518 return TRUE;
7519 }
7520
HAL_MVD_SetDivXCfg(MS_U8 u8Idx,MS_U8 u8MvAdjust,MS_U8 u8IdctSel)7521 void HAL_MVD_SetDivXCfg(MS_U8 u8Idx, MS_U8 u8MvAdjust, MS_U8 u8IdctSel)
7522 {
7523 MVD_CmdArg stCmdArg;
7524
7525 SETUP_CMDARG(stCmdArg);
7526 stCmdArg.Arg0 = u8MvAdjust;
7527 SET_DECNUM(stCmdArg, u8Idx);
7528 if (HAL_MVD_MVDCommand(CMD_DIVX_PATCH, &stCmdArg) == FALSE)
7529 {
7530 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DIVX_PATCH ) );
7531 return;
7532 }
7533
7534 SETUP_CMDARG(stCmdArg);
7535 stCmdArg.Arg0 = u8IdctSel;
7536 SET_DECNUM(stCmdArg, u8Idx);
7537 if (HAL_MVD_MVDCommand(CMD_IDCT_SEL, &stCmdArg) == FALSE)
7538 {
7539 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_IDCT_SEL ) );
7540 return;
7541 }
7542
7543 return;
7544 }
7545
7546 #define _IsNotInStreamBuff(x) \
7547 (((x) < pstMemCfg->u32DrvBufSize) || \
7548 ((x) > pstMemCfg->u32BSSize) )
7549
7550 //------------------------------------------------------------------------------
7551 /// Get read pointer in ElementaryStream buffer for SLQ table mode
7552 /// @return -the read pointer
7553 //------------------------------------------------------------------------------
MVD_GetSlqTblESReadPtr(MS_U8 u8Idx)7554 MS_VIRT MVD_GetSlqTblESReadPtr(MS_U8 u8Idx)
7555 {
7556 MS_U32 u32Idx;
7557 MS_U32 u32SlqRp = 0, u32SlqRp1 = 0;
7558 MS_VIRT u32EsRp;
7559 MS_VIRT u32EsStart;
7560 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
7561 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
7562 MVD_CodecType curCodecType = HAL_MVD_GetCodecType(u8Idx);
7563
7564 u32SlqRp1 = HAL_MVD_GetSLQReadPtr(u8Idx);
7565
7566 if (u32SlqRp1 == 0)
7567 {
7568 return MVD_U32_MAX;
7569 }
7570 else
7571 {
7572 u32SlqRp = HAL_MVD_Map2DrvSlqTbl(u8Idx, u32SlqRp1);
7573 }
7574
7575 pstSlqTblInfo->pDrvSlqTbl->u32RdPtr = u32SlqRp; //update pstSlqTblInfo->pDrvSlqTbl->u32RdPtr
7576
7577 //report (readPtr-1) for HW may still use (readPtr)
7578 if (u32SlqRp > (pstSlqTblInfo->pDrvSlqTbl->u32StAdd))
7579 {
7580 u32Idx = ((u32SlqRp - pstSlqTblInfo->pDrvSlqTbl->u32StAdd)/SLQ_ENTRY_LEN) - 1;
7581 }
7582 else
7583 {
7584 u32Idx = SLQ_ENTRY_MAX - 1;
7585 }
7586 u32EsRp = pstSlqTblInfo->pDrvEsTbl->u32StAdd + u32Idx*8;
7587
7588 u32EsStart = HAL_MVD_MemRead4Byte(u32EsRp); //report StartAdd as read_pointer
7589 #if 0
7590 MS_U32 u32EsEnd;
7591 u32EsEnd = HAL_MVD_MemRead4Byte(u32EsRp+4);
7592 printf("GetESReadPtr ES[%x] Start=0x%x End=0x%x u32EsRp=%x u32SlqRp=%x\n",
7593 u32Idx, HAL_MVD_MemRead4Byte(u32EsRp), u32EsEnd, u32EsRp, u32SlqRp);
7594 #endif
7595
7596 if ((_IsNotInStreamBuff(u32EsStart)) && (u32EsStart != 0))
7597 { //ESRead is not in BS buffer, so this entry is a divx or dummy pattern.
7598 //Report the last ESRead, instead of this one.
7599 if(curCodecType == E_MVD_CODEC_DIVX311)
7600 {
7601 //update last slq index es end address
7602 if(u32Idx == 0)
7603 {
7604 u32Idx = SLQ_ENTRY_MAX-1;
7605 }
7606 else
7607 {
7608 u32Idx = u32Idx-1;
7609 }
7610 u32EsRp = pstSlqTblInfo->pDrvEsTbl->u32StAdd + u32Idx*8;
7611 u32EsStart = HAL_MVD_MemRead4Byte(u32EsRp); //report StartAdd as read_pointer
7612 if(_IsNotInStreamBuff(u32EsStart))
7613 {
7614 return (pstSlqTblInfo->u32PreEsRd);
7615 }
7616 }
7617 else
7618 {
7619 MVD_DEBUGINFO(printf("0x%lx Not in BS, report u32PreEsRd=0x%lx\n", (unsigned long)u32EsStart, (unsigned long)pstSlqTblInfo->u32PreEsRd));
7620 return (pstSlqTblInfo->u32PreEsRd);
7621 }
7622 }
7623 pstSlqTblInfo->u32PreEsRd = u32EsStart;
7624
7625 return u32EsStart;
7626 }
7627
7628 //------------------------------------------------------------------------------
7629 /// Get write pointer in ElementaryStream buffer for SLQ table mode
7630 /// @return -the read pointer
7631 //------------------------------------------------------------------------------
MVD_GetSlqTblESWritePtr(MS_U8 u8Idx)7632 MS_VIRT MVD_GetSlqTblESWritePtr(MS_U8 u8Idx)
7633 {
7634 MS_VIRT u32EsWp;
7635 MS_VIRT u32EsEnd;
7636 MS_U32 u32Idx;
7637 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
7638 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
7639
7640 if (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr > (pstSlqTblInfo->pDrvSlqTbl->u32StAdd))
7641 {
7642 u32Idx = ((pstSlqTblInfo->pDrvSlqTbl->u32WrPtr - pstSlqTblInfo->pDrvSlqTbl->u32StAdd)/SLQ_ENTRY_LEN) - 1;
7643 }
7644 else
7645 {
7646 u32Idx = SLQ_ENTRY_MAX - 1;
7647 }
7648 u32EsWp = pstSlqTblInfo->pDrvEsTbl->u32StAdd + u32Idx*8;
7649
7650 u32EsEnd = HAL_MVD_MemRead4Byte(u32EsWp+4);
7651 #if 0
7652 printf("GetESWritePtr[%x] ES Start=0x%x End=0x%x u32EsWp=%x\n",
7653 (u32EsWp - pstSlqTblInfo->pDrvEsTbl->u32StAdd)/8,
7654 HAL_MVD_MemRead4Byte(u32EsWp), u32EsEnd, u32EsWp);
7655 #endif
7656
7657 if ((_IsNotInStreamBuff(u32EsEnd)) && (u32EsEnd != 0))
7658 { //ESRead is not in BS buffer, so this entry is a divx pattern.
7659 //Report the last ESRead, instead of this one.
7660 MVD_DEBUGINFO(printf("0x%lx Not in BS, report u32PreEsWr=0x%lx\n", (unsigned long)u32EsEnd, (unsigned long)pstSlqTblInfo->u32PreEsWr));
7661 return (pstSlqTblInfo->u32PreEsWr);
7662 }
7663 pstSlqTblInfo->u32PreEsWr = u32EsEnd;
7664
7665 return u32EsEnd;
7666 }
7667
7668
HAL_MVD_GetSLQReadPtr(MS_U8 u8Idx)7669 MS_VIRT HAL_MVD_GetSLQReadPtr(MS_U8 u8Idx)
7670 {
7671 MS_VIRT u32RdPtr = 0;
7672
7673 if (!(pMVDHalContext->bSlqTblHKCtrl[u8Idx]))
7674 {
7675 #ifndef VDEC3
7676 MVD_CmdArg mvdcmd;
7677 SETUP_CMDARG(mvdcmd);
7678 SET_DECNUM(mvdcmd, u8Idx);
7679 if (HAL_MVD_MVDCommand( CMD_SLQ_GET_TBL_RPTR, &mvdcmd ) == FALSE)
7680 {
7681 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLQ_GET_TBL_RPTR ) );
7682 return 0;
7683 }
7684 u32RdPtr = mvdcmd.Arg0 | (mvdcmd.Arg1<<8) | (mvdcmd.Arg2<<16) | (mvdcmd.Arg3<<24);
7685 #else
7686 u32RdPtr = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SLQ_TBL_RPTR, sizeof(MS_U32));
7687 #endif
7688 }
7689 else
7690 {
7691 u32RdPtr = HAL_MVD_SlqTblProbeRdPtr(u8Idx);
7692 }
7693
7694 //printf("##### HAL_MVD_GetSLQReadPtr 0x%x\n", readPtr);
7695
7696 if(u32RdPtr == 0)//not start decode yet,MVD return 0
7697 {
7698 u32RdPtr = 0;
7699 }
7700 else
7701 {
7702 u32RdPtr = u32RdPtr << 3;
7703 }
7704
7705 return u32RdPtr;
7706 }
7707
7708
HAL_MVD_SetSLQWritePtr(MS_U8 u8Idx,MS_BOOL bCheckData)7709 MS_BOOL HAL_MVD_SetSLQWritePtr(MS_U8 u8Idx, MS_BOOL bCheckData)
7710 {
7711 MVD_CmdArg mvdcmd;
7712 MS_VIRT u32WrPtr;
7713 MVD_MEMCfg* pstMemCfg = HAL_MVD_GetMEMCfg(u8Idx);
7714 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
7715 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
7716
7717 if (FALSE == pstSlqTblInfo->bRdyToFireCmd)
7718 {
7719 //check FW is init success and thus ready to update write pointer
7720 MS_U32 u32TimeCnt;
7721
7722 u32TimeCnt = HAL_MVD_GetTime();
7723 while ((HAL_MVD_GetTime() - u32TimeCnt) < CMD_TIMEOUT_MS)
7724 {
7725 if (HAL_MVD_GetDecodeStatus(u8Idx) != E_MVD_STAT_IDLE)
7726 {
7727 pstSlqTblInfo->bRdyToFireCmd = TRUE;
7728 MVD_DEBUGVERBAL(printf("time=0x%x ms, ", (HAL_MVD_GetTime() - u32TimeCnt)));
7729 break;
7730 }
7731 }
7732 if (FALSE == pstSlqTblInfo->bRdyToFireCmd)
7733 {
7734 MVD_DEBUGERROR(printf("%s: err timeout(%d)! stat=0x%x\n", __FUNCTION__,
7735 HAL_MVD_GetTime() - u32TimeCnt, HAL_MVD_GetDecodeStatus(u8Idx)));
7736 return FALSE;
7737 }
7738 else
7739 {
7740 MVD_DEBUGVERBAL(printf("%s: ready to update WrPtr.\n", __FUNCTION__));
7741 }
7742 }
7743
7744
7745 MS_ASSERT(pstSlqTblInfo->pDrvSlqTbl->u32WrPtr < pstSlqTblInfo->pDrvSlqTbl->u32EndAdd);
7746 MS_ASSERT(pstSlqTblInfo->pDrvSlqTbl->u32WrPtr >= pstSlqTblInfo->pDrvSlqTbl->u32StAdd);
7747 #if SLQ_NEW_PUSH
7748 if((!pstSlqTblInfo->pSlqStatus->bSlqFireRdy)&&pstSlqTblInfo->pSlqStatus->bSlqCtrlBit)
7749 {
7750 MVD_DEBUGINFO(printf("**** pstSlqTblInfo->pSlqStatus->bSlqFireRdy is not Ready ** \n"));
7751 return FALSE;
7752 }
7753 pstSlqTblInfo->pSlqStatus->bSlqFireRdy = FALSE;
7754 #endif
7755 if ((bCheckData==TRUE) && (FALSE==pstSlqTblInfo->bSlqTblHasValidData))
7756 {
7757 MVD_DEBUGINFO(printf("**** SlqWrPtr(0x%lx) is not update!(%x, %x) ****\n",
7758 (unsigned long)pstSlqTblInfo->pDrvSlqTbl->u32WrPtr, bCheckData, pstSlqTblInfo->bSlqTblHasValidData));
7759 return FALSE;
7760 }
7761 pstSlqTblInfo->bSlqTblHasValidData = FALSE;
7762
7763 if (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr != pstSlqTblInfo->pDrvSlqTbl->u32EndAdd)
7764 {
7765 u32WrPtr = pstSlqTblInfo->pDrvSlqTbl->u32WrPtr;
7766 }
7767 else
7768 {
7769 u32WrPtr = pstSlqTblInfo->pDrvSlqTbl->u32StAdd;
7770 }
7771
7772 if (pstCtrlCfg->bSlqTblSync)
7773 {
7774 //Update SLQ table, DivX311 patterns, and dummy patterns to bitstream buffer
7775 MS_VIRT u32SrcOffset = pstSlqTblInfo->pDrvSlqTbl->u32StAdd;
7776 MS_VIRT u32SrcAdd = u32SrcOffset;
7777 MS_VIRT u32DstAdd = pstMemCfg->u32BSAddr;
7778 MS_VIRT u32DstOffset = HAL_MVD_GetMemOffset(pstMemCfg->u32BSAddr);
7779 MS_VIRT u32TblWr;
7780
7781 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,u32SrcOffset,u32SrcAdd);
7782
7783
7784 HAL_MVD_CPU_Sync();
7785 #ifndef MSOS_TYPE_LINUX_KERNEL//BDMA
7786 BDMA_Result bdmaRlt;
7787
7788 bdmaRlt = MDrv_BDMA_CopyHnd(u32SrcAdd, u32DstAdd, pstMemCfg->u32DrvBufSize, pstSlqTblInfo->bdmaCpyType, BDMA_OPCFG_DEF);
7789
7790 if (E_BDMA_OK != bdmaRlt)
7791 {
7792 MVD_DEBUGERROR(printf("%s MDrv_BDMA_MemCopy fail ret=%x!\n", __FUNCTION__, bdmaRlt));
7793 }
7794 #endif
7795 MVD_DEBUGINFO(printf("SlqWrPtr_BDMA src=0x%lx dst=0x%lx size=0x%lx cpyType=0x%x\n",
7796 (unsigned long)u32SrcAdd, (unsigned long)u32DstAdd, (unsigned long)pstMemCfg->u32DrvBufSize, pstSlqTblInfo->bdmaCpyType));
7797
7798 u32TblWr = u32DstOffset + (u32WrPtr - pstSlqTblInfo->pDrvSlqTbl->u32StAdd);
7799
7800 u32WrPtr = u32TblWr;
7801 }
7802 //printf("wPtr= 0x%x(0x%x) rPtr=0x%x(0x%x)\n", writePtr, pstSlqTblInfo->pDrvSlqTbl->u32WrPtr,
7803 // HAL_MVD_GetSLQReadPtr(u8Idx), pstSlqTblInfo->pDrvSlqTbl->u32RdPtr);
7804
7805
7806 //writePtrLast[u8Idx] = u32WrPtr;
7807 #if SLQ_NEW_PUSH
7808 if(!pstSlqTblInfo->pSlqStatus->bSlqEnLastFrameShow && pstSlqTblInfo->pSlqStatus->bSlqCtrlBit)
7809 {
7810 u32WrPtr = pstSlqTblInfo->pSlqStatus->u32VaildWptrAddr;
7811 }
7812 #endif
7813 MS_ASSERT((u32WrPtr%8)==0);
7814 u32WrPtr >>= 3;
7815
7816 if (!(pMVDHalContext->bSlqTblHKCtrl[u8Idx]))
7817 {
7818 SET_CMDARG(mvdcmd, u32WrPtr, u8Idx);
7819 HAL_MVD_CPU_Sync();
7820 SET_CMD_RET_FALSE(CMD_SLQ_UPDATE_TBL_WPTR, &mvdcmd);
7821 }
7822 else
7823 {
7824 HAL_MVD_SlqTblLoadWrPtr(u8Idx, u32WrPtr);
7825 if (HAL_MVD_SlqTblProbeWrPtr(u8Idx) != u32WrPtr)
7826 {
7827 MVD_DEBUGERROR(printf("Ooops! SlqWrPtr update fail!!! 0x%lx != 0x%lx\n", (unsigned long)HAL_MVD_SlqTblProbeWrPtr(u8Idx), (unsigned long)u32WrPtr));
7828 return FALSE;
7829 }
7830 }
7831
7832 return TRUE;
7833 }
7834
HAL_MVD_SetOverflowTH(MS_U8 u8Idx,MS_U32 u32Threshold)7835 void HAL_MVD_SetOverflowTH(MS_U8 u8Idx, MS_U32 u32Threshold)
7836 {
7837 MVD_CmdArg mvdcmd;
7838
7839 MS_ASSERT((u32Threshold%8)==0);
7840 u32Threshold >>= 3;
7841 SET_CMDARG(mvdcmd, u32Threshold, u8Idx);
7842 if (HAL_MVD_MVDCommand( CMD_DMA_OVFTH, &mvdcmd ) == FALSE)
7843 {
7844 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DMA_OVFTH ) );
7845 return;
7846 }
7847 return;
7848 }
7849
7850 //------------------------------------------------------------------------------
7851 /// Set bitstream buffer underflow threshold
7852 /// @return -none
7853 //------------------------------------------------------------------------------
HAL_MVD_SetUnderflowTH(MS_U8 u8Idx,MS_U32 u32Threshold)7854 void HAL_MVD_SetUnderflowTH(MS_U8 u8Idx, MS_U32 u32Threshold)
7855 {
7856 MVD_CmdArg mvdcmd;
7857
7858 MS_ASSERT((u32Threshold%8)==0);
7859 u32Threshold >>= 3;
7860 SET_CMDARG(mvdcmd, u32Threshold, u8Idx);
7861 if (HAL_MVD_MVDCommand( CMD_DMA_UNFTH, &mvdcmd ) == FALSE)
7862 {
7863 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DMA_UNFTH ) );
7864 return;
7865 }
7866 return;
7867 }
7868
HAL_MVD_GenPattern(MS_U8 u8Idx,MVD_PatternType ePattern,MS_PHY u32PAddr,MS_U32 * pu32Size)7869 MS_BOOL HAL_MVD_GenPattern(MS_U8 u8Idx, MVD_PatternType ePattern, MS_PHY u32PAddr, MS_U32* pu32Size)
7870 {
7871 MS_U8* pu8DummyData = NULL;
7872 MVD_CodecType curCodecType = HAL_MVD_GetCodecType(u8Idx);
7873
7874 if ((!pu32Size) || (*pu32Size < SKIP_PATTERN_SIZE))
7875 {
7876 return FALSE;
7877 }
7878
7879 pu8DummyData = (MS_U8*) HAL_MVD_PA2NonCacheSeg(u32PAddr);
7880
7881 if(pu8DummyData == NULL)
7882 {
7883 printf("%s %d NULL Address\n",__FILE__,__LINE__);
7884 return FALSE;
7885 }
7886
7887 switch (ePattern)
7888 {
7889 case E_MVD_PATTERN_FLUSH:
7890 #if 0
7891 *pu8DummyData = SKIP_PATTERN_0;
7892 pu8DummyData++;
7893 *pu8DummyData = SKIP_PATTERN_1;
7894 *pu32Size = SKIP_PATTERN_SIZE;
7895 #else
7896 pu8DummyData[0] = SKIP_PATTERN_0&0xff;
7897 pu8DummyData[1] = (SKIP_PATTERN_0>>8)&0xff;
7898 pu8DummyData[2] = (SKIP_PATTERN_0>>16)&0xff;
7899 pu8DummyData[3] = (SKIP_PATTERN_0>>24)&0xff;
7900
7901 pu8DummyData[4] = SKIP_PATTERN_1&0xff;
7902 pu8DummyData[5] = (SKIP_PATTERN_1>>8)&0xff;
7903 pu8DummyData[6] = (SKIP_PATTERN_1>>16)&0xff;
7904 pu8DummyData[7] = (SKIP_PATTERN_1>>24)&0xff;
7905
7906 *pu32Size = SKIP_PATTERN_SIZE;
7907 #endif
7908 break;
7909 case E_MVD_PATTERN_FILEEND:
7910 if ((E_MVD_CODEC_FLV == curCodecType)||(E_MVD_CODEC_MPEG4_SHORT_VIDEO_HEADER == curCodecType))
7911 {
7912 #if 0
7913 *pu8DummyData = FLV_PATTERN;
7914 pu8DummyData++;
7915 *pu8DummyData = 0xffffffff;
7916 pu8DummyData++;
7917 *pu8DummyData = END_PATTERN_1;
7918 pu8DummyData++;
7919 *pu8DummyData = END_PATTERN_2;
7920 pu8DummyData++;
7921 *pu8DummyData = END_PATTERN_3;
7922 #else
7923 pu8DummyData[0] = FLV_PATTERN&0xff;
7924 pu8DummyData[1] = (FLV_PATTERN>>8)&0xff;
7925 pu8DummyData[2] = (FLV_PATTERN>>16)&0xff;
7926 pu8DummyData[3] = (FLV_PATTERN>>24)&0xff;
7927
7928 pu8DummyData[4] = 0xffffffff&0xff;
7929 pu8DummyData[5] = (0xffffffff>>8)&0xff;
7930 pu8DummyData[6] = (0xffffffff>>16)&0xff;
7931 pu8DummyData[7] = (0xffffffff>>24)&0xff;
7932
7933 pu8DummyData[8] = END_PATTERN_1&0xff;
7934 pu8DummyData[9] = (END_PATTERN_1>>8)&0xff;
7935 pu8DummyData[10] = (END_PATTERN_1>>16)&0xff;
7936 pu8DummyData[11] = (END_PATTERN_1>>24)&0xff;
7937
7938 pu8DummyData[12] = END_PATTERN_2&0xff;
7939 pu8DummyData[13] = (END_PATTERN_2>>8)&0xff;
7940 pu8DummyData[14] = (END_PATTERN_2>>16)&0xff;
7941 pu8DummyData[15] = (END_PATTERN_2>>24)&0xff;
7942
7943 pu8DummyData[16] = END_PATTERN_3&0xff;
7944 pu8DummyData[17] = (END_PATTERN_3>>8)&0xff;
7945 pu8DummyData[18] = (END_PATTERN_3>>16)&0xff;
7946 pu8DummyData[19] = (END_PATTERN_3>>24)&0xff;
7947
7948 #endif
7949
7950 }
7951 else if (E_MVD_CODEC_DIVX311 == curCodecType)
7952 {
7953 #if 0
7954 *pu8DummyData = DIVX_PATTERN;
7955 pu8DummyData++;
7956 *pu8DummyData = 0xffffffff;
7957 pu8DummyData++;
7958 *pu8DummyData = END_PATTERN_1;
7959 pu8DummyData++;
7960 *pu8DummyData = END_PATTERN_2;
7961 pu8DummyData++;
7962 *pu8DummyData = END_PATTERN_3;
7963 #else
7964 pu8DummyData[0] = DIVX_PATTERN&0xff;
7965 pu8DummyData[1] = (DIVX_PATTERN>>8)&0xff;
7966 pu8DummyData[2] = (DIVX_PATTERN>>16)&0xff;
7967 pu8DummyData[3] = (DIVX_PATTERN>>24)&0xff;
7968
7969 pu8DummyData[4] = 0xffffffff&0xff;
7970 pu8DummyData[5] = (0xffffffff>>8)&0xff;
7971 pu8DummyData[6] = (0xffffffff>>16)&0xff;
7972 pu8DummyData[7] = (0xffffffff>>24)&0xff;
7973
7974 pu8DummyData[8] = END_PATTERN_1&0xff;
7975 pu8DummyData[9] = (END_PATTERN_1>>8)&0xff;
7976 pu8DummyData[10] = (END_PATTERN_1>>16)&0xff;
7977 pu8DummyData[11] = (END_PATTERN_1>>24)&0xff;
7978
7979 pu8DummyData[12] = END_PATTERN_2&0xff;
7980 pu8DummyData[13] = (END_PATTERN_2>>8)&0xff;
7981 pu8DummyData[14] = (END_PATTERN_2>>16)&0xff;
7982 pu8DummyData[15] = (END_PATTERN_2>>24)&0xff;
7983
7984 pu8DummyData[16] = END_PATTERN_3&0xff;
7985 pu8DummyData[17] = (END_PATTERN_3>>8)&0xff;
7986 pu8DummyData[18] = (END_PATTERN_3>>16)&0xff;
7987 pu8DummyData[19] = (END_PATTERN_3>>24)&0xff;
7988 #endif
7989 }
7990 else if ((E_MVD_CODEC_MPEG2 == curCodecType)||(E_MVD_CODEC_MPEG4 == curCodecType))
7991 {
7992 #if 0
7993 *pu8DummyData = MPEG_PATTERN_0;
7994 pu8DummyData++;
7995 *pu8DummyData = END_PATTERN_1;
7996 pu8DummyData++;
7997 *pu8DummyData = END_PATTERN_2;
7998 pu8DummyData++;
7999 *pu8DummyData = END_PATTERN_3;
8000 #else
8001 pu8DummyData[0] = MPEG_PATTERN_0&0xff;
8002 pu8DummyData[1] = (MPEG_PATTERN_0>>8)&0xff;
8003 pu8DummyData[2] = (MPEG_PATTERN_0>>16)&0xff;
8004 pu8DummyData[3] = (MPEG_PATTERN_0>>24)&0xff;
8005
8006 pu8DummyData[4] = END_PATTERN_1&0xff;
8007 pu8DummyData[5] = (END_PATTERN_1>>8)&0xff;
8008 pu8DummyData[6] = (END_PATTERN_1>>16)&0xff;
8009 pu8DummyData[7] = (END_PATTERN_1>>24)&0xff;
8010
8011 pu8DummyData[8] = END_PATTERN_2&0xff;
8012 pu8DummyData[9] = (END_PATTERN_2>>8)&0xff;
8013 pu8DummyData[10] = (END_PATTERN_2>>16)&0xff;
8014 pu8DummyData[11] = (END_PATTERN_2>>24)&0xff;
8015
8016 pu8DummyData[12] = END_PATTERN_3&0xff;
8017 pu8DummyData[13] = (END_PATTERN_3>>8)&0xff;
8018 pu8DummyData[14] = (END_PATTERN_3>>16)&0xff;
8019 pu8DummyData[15] = (END_PATTERN_3>>24)&0xff;
8020 #endif
8021 }
8022 else
8023 {
8024 #if 0
8025 *pu8DummyData = END_PATTERN_0;
8026 pu8DummyData++;
8027 *pu8DummyData = END_PATTERN_1;
8028 pu8DummyData++;
8029 *pu8DummyData = END_PATTERN_2;
8030 pu8DummyData++;
8031 *pu8DummyData = END_PATTERN_3;
8032 #else
8033 pu8DummyData[0] = END_PATTERN_0&0xff;
8034 pu8DummyData[1] = (END_PATTERN_0>>8)&0xff;
8035 pu8DummyData[2] = (END_PATTERN_0>>16)&0xff;
8036 pu8DummyData[3] = (END_PATTERN_0>>24)&0xff;
8037
8038 pu8DummyData[4] = END_PATTERN_1&0xff;
8039 pu8DummyData[5] = (END_PATTERN_1>>8)&0xff;
8040 pu8DummyData[6] = (END_PATTERN_1>>16)&0xff;
8041 pu8DummyData[7] = (END_PATTERN_1>>24)&0xff;
8042
8043 pu8DummyData[8] = END_PATTERN_2&0xff;
8044 pu8DummyData[9] = (END_PATTERN_2>>8)&0xff;
8045 pu8DummyData[10] = (END_PATTERN_2>>16)&0xff;
8046 pu8DummyData[11] = (END_PATTERN_2>>24)&0xff;
8047
8048 pu8DummyData[12] = END_PATTERN_3&0xff;
8049 pu8DummyData[13] = (END_PATTERN_3>>8)&0xff;
8050 pu8DummyData[14] = (END_PATTERN_3>>16)&0xff;
8051 pu8DummyData[15] = (END_PATTERN_3>>24)&0xff;
8052 #endif
8053 }
8054 *pu32Size = 16;
8055 break;
8056 default:
8057 break;
8058 }
8059
8060 return TRUE;
8061 }
8062
8063
8064
HAL_MVD_DbgDump(MS_U8 u8Idx)8065 void HAL_MVD_DbgDump(MS_U8 u8Idx)
8066 {
8067 MS_U32 u32VdCnt=0;
8068 //static MS_U32 u32PreVdCnt[MAX_DEC_NUM]= {0, 0};
8069 MS_U32 u32ErrCnt=0;
8070 //static MS_U32 u32PreErrCnt[MAX_DEC_NUM]= {0, 0};
8071 //static MS_BOOL b1stDump[MAX_DEC_NUM]= {TRUE, TRUE};
8072 MVD_FrmInfo stFrm = {_INIT_ADDR, _INIT_ADDR, _INIT_TIMESTAMP, _INIT_ID,
8073 _INIT_ID, _INIT_LEN, _INIT_LEN, _INIT_LEN, 0xff, E_MVD_PIC_UNKNOWN};
8074 MVD_SrcMode curSrcMode = HAL_MVD_GetSrcMode(u8Idx);
8075 #ifndef VDEC3
8076 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
8077 #endif
8078 if (pMVDHalContext->b1stDump[u8Idx])
8079 {
8080 MVD_FWCfg* pFwCfg = NULL;
8081 pFwCfg = HAL_MVD_GetFWCfg(u8Idx);
8082 printf("curDisablePESParsing = %d\n", pFwCfg->bDisablePESParsing);
8083 pMVDHalContext->b1stDump[u8Idx] = FALSE;
8084 }
8085
8086 u32VdCnt = HAL_MVD_GetParserByteCnt(u8Idx);
8087 u32ErrCnt= HAL_MVD_GetVldErrCount(u8Idx);
8088 printf("input: vfifo=%d(full=%d,empty=%d), vdCnt=%d(%d), vldErr=%d(%d); ",
8089 HAL_MVD_RegReadByte(0x1564)>>6, HAL_MVD_RegReadByte(0x1564)&0x20,
8090 HAL_MVD_RegReadByte(0x1564)&0x10, u32VdCnt, (u32VdCnt-pMVDHalContext->u32PreVdCnt[u8Idx]),
8091 u32ErrCnt, (u32ErrCnt-pMVDHalContext->u32PreErrCnt[u8Idx]));
8092 pMVDHalContext->u32PreVdCnt[u8Idx] = u32VdCnt;
8093 pMVDHalContext->u32PreErrCnt[u8Idx] = u32ErrCnt;
8094
8095 printf("state: fw=0x%x, lastCmd=0x%x, pc=0x%x\n",
8096 HAL_MVD_GetDecodeStatus(u8Idx), HAL_MVD_GetLastCmd(u8Idx), HAL_VPU_EX_GetProgCnt());
8097 printf("cnt: dec=%d, skip=%d, drop=%ld\n", HAL_MVD_GetPicCounter(u8Idx), HAL_MVD_GetSkipPicCounter(u8Idx), 0x0UL);
8098 HAL_MVD_GetFrmInfo(u8Idx, E_MVD_FRMINFO_DECODE, &stFrm);
8099 printf("frm Dec Y=%lx UV=%lx Pitch=%x; ", (unsigned long)stFrm.u32LumaAddr, (unsigned long)stFrm.u32ChromaAddr, stFrm.u16Pitch);
8100 HAL_MVD_GetFrmInfo(u8Idx, E_MVD_FRMINFO_DISPLAY, &stFrm);
8101 printf("Disp Y=%lx UV=%lx Pitch=%x\n", (unsigned long)stFrm.u32LumaAddr, (unsigned long)stFrm.u32ChromaAddr, stFrm.u16Pitch);
8102 if (curSrcMode == E_MVD_SLQ_TBL_MODE)
8103 {
8104 #ifndef VDEC3
8105 printf("fe=%x, rd=%x(%x), wr=%x, empty=%x; ", pstSlqTblInfo->u32FileEndPtr, pstSlqTblInfo->pDrvSlqTbl->u32RdPtr,
8106 HAL_MVD_Map2DrvSlqTbl(u8Idx, HAL_MVD_GetSLQReadPtr(u8Idx)), pstSlqTblInfo->pDrvSlqTbl->u32WrPtr, pstSlqTblInfo->pDrvSlqTbl->u32Empty);
8107
8108 printf("es rd=0x%lx, wr=0x%lx\n", (unsigned long)MVD_GetSlqTblESReadPtr(u8Idx), (unsigned long)MVD_GetSlqTblESWritePtr(u8Idx));
8109 #endif
8110 }
8111 else if (curSrcMode == E_MVD_TS_FILE_MODE)
8112 {
8113 printf("es rd=0x%lx, wr=0x%lx\n", (unsigned long)HAL_MVD_GetTsFileESReadPtr(u8Idx), (unsigned long)HAL_MVD_GetTsFileESWritePtr(u8Idx));
8114 }
8115 }
8116
8117 #ifdef MS_DEBUG
8118 #define _STRINGIFY_HAL_SID(x) \
8119 (x==E_HAL_MVD_MAIN_STREAM0)?"E_HAL_MVD_MAIN_STREAM0": \
8120 ((x==E_HAL_MVD_SUB_STREAM0)?"E_HAL_MVD_SUB_STREAM0":"E_HAL_MVD_STREAM_NONE")
MVD_DumpMVDStream(void)8121 void MVD_DumpMVDStream(void)
8122 {
8123 //if (_u8HalDbgLevel == 0) return;
8124 MS_U8 i = 0;
8125 for (i=0; i< MAX_DEC_NUM; i++)
8126 {
8127 MVD_DEBUGINFO(printf("[%d] eStreamId=0x%x(%s) bUsed=0x%x\n", i, pMVDHalContext->_stMVDStream[i].eStreamId,
8128 _STRINGIFY_HAL_SID(pMVDHalContext->_stMVDStream[i].eStreamId), pMVDHalContext->_stMVDStream[i].bUsed));
8129 }
8130 }
8131 #endif
HAL_MVD_Init_Share_Mem(void)8132 MS_BOOL HAL_MVD_Init_Share_Mem(void)
8133 {
8134 #if (defined(MSOS_TYPE_LINUX) || defined(MSOS_TYPE_ECOS) || defined(MSOS_TYPE_LINUX_KERNEL))
8135 #if !defined(SUPPORT_X_MODEL_FEATURE)
8136 MS_U32 u32ShmId;
8137 MS_VIRT u32Addr;
8138 MS_U32 u32BufSize;
8139
8140
8141 if (FALSE == MsOS_SHM_GetId( (MS_U8*)"Linux MVD HAL",
8142 sizeof(MVD_Hal_CTX),
8143 &u32ShmId,
8144 &u32Addr,
8145 &u32BufSize,
8146 MSOS_SHM_QUERY))
8147 {
8148 if (FALSE == MsOS_SHM_GetId((MS_U8*)"Linux MVD HAL",
8149 sizeof(MVD_Hal_CTX),
8150 &u32ShmId,
8151 &u32Addr,
8152 &u32BufSize,
8153 MSOS_SHM_CREATE))
8154 {
8155 printf("[%s]SHM allocation failed!!! use global structure instead!!!\n",__FUNCTION__);
8156 if(pMVDHalContext == NULL)
8157 {
8158 pMVDHalContext = &gMVDHalContext;
8159 memset(pMVDHalContext,0,sizeof(MVD_Hal_CTX));
8160 HAL_MVD_Context_Init();
8161 printf("[%s]Global structure init Success!!!\n",__FUNCTION__);
8162 }
8163 else
8164 {
8165 printf("[%s]Global structure exists!!!\n",__FUNCTION__);
8166 }
8167 //return FALSE;
8168 }
8169 else
8170 {
8171 memset((MS_U8*)u32Addr,0,sizeof(MVD_Hal_CTX));
8172 pMVDHalContext = (MVD_Hal_CTX*)u32Addr; // for one process
8173 HAL_MVD_Context_Init();
8174 }
8175 }
8176 else
8177 {
8178 pMVDHalContext = (MVD_Hal_CTX*)u32Addr; // for another process
8179 }
8180 #else
8181 if(pMVDHalContext == NULL)
8182 {
8183 pMVDHalContext = &gMVDHalContext;
8184 memset(pMVDHalContext,0,sizeof(MVD_Hal_CTX));
8185 HAL_MVD_Context_Init();
8186 }
8187 #endif
8188 OSAL_MVD_MutexInit();
8189 #else
8190 if(pMVDHalContext == NULL)
8191 {
8192 pMVDHalContext = &gMVDHalContext;
8193 memset(pMVDHalContext,0,sizeof(MVD_Hal_CTX));
8194 HAL_MVD_Context_Init();
8195 }
8196 #endif
8197
8198
8199 return TRUE;
8200
8201 }
8202
8203 //------------------------------------------------------------------------------
HAL_MVD_GetFreeStream(HAL_MVD_StreamType eStreamType)8204 HAL_MVD_StreamId HAL_MVD_GetFreeStream(HAL_MVD_StreamType eStreamType)
8205 {
8206 MS_U32 i = 0;
8207
8208 #ifdef MS_DEBUG
8209 MVD_DumpMVDStream();
8210 #endif
8211 if (eStreamType == E_HAL_MVD_MAIN_STREAM)
8212 {
8213 for (i = 0;
8214 i <
8215 ((E_HAL_MVD_MAIN_STREAM_MAX - E_HAL_MVD_MAIN_STREAM_BASE) +
8216 (E_HAL_MVD_SUB_STREAM_MAX - E_HAL_MVD_SUB_STREAM_BASE)); i++)
8217 {
8218 if ((E_HAL_MVD_MAIN_STREAM_BASE & pMVDHalContext->_stMVDStream[i].eStreamId) && (FALSE == pMVDHalContext->_stMVDStream[i].bUsed))
8219 {
8220 return pMVDHalContext->_stMVDStream[i].eStreamId;
8221 }
8222 }
8223 }
8224 else if (eStreamType == E_HAL_MVD_SUB_STREAM)
8225 {
8226 for (i = 0;
8227 i <
8228 ((E_HAL_MVD_MAIN_STREAM_MAX - E_HAL_MVD_MAIN_STREAM_BASE) +
8229 (E_HAL_MVD_SUB_STREAM_MAX - E_HAL_MVD_SUB_STREAM_BASE)); i++)
8230 {
8231 if ((E_HAL_MVD_SUB_STREAM_BASE & pMVDHalContext->_stMVDStream[i].eStreamId) && (FALSE == pMVDHalContext->_stMVDStream[i].bUsed))
8232 {
8233 return pMVDHalContext->_stMVDStream[i].eStreamId;
8234 }
8235 }
8236 }
8237 #ifdef VDEC3
8238 else if ((eStreamType >= E_HAL_MVD_N_STREAM) && (eStreamType < E_HAL_MVD_N_STREAM + MAX_DEC_NUM))
8239 {
8240 i = eStreamType - E_HAL_MVD_N_STREAM;
8241 if (!pMVDHalContext->_stMVDStream[i].bUsed)
8242 {
8243 return pMVDHalContext->_stMVDStream[i].eStreamId;
8244 }
8245 }
8246 #endif
8247
8248 return E_HAL_MVD_STREAM_NONE;
8249 }
8250
HAL_MVD_SidToIdx(HAL_MVD_StreamId eSID)8251 MS_U8 HAL_MVD_SidToIdx(HAL_MVD_StreamId eSID)
8252 {
8253 #ifdef VDEC3
8254 return eSID - E_HAL_MVD_N_STREAM_BASE;
8255 #else
8256 MS_U8 u8Idx = 0;
8257 switch (eSID)
8258 {
8259 case E_HAL_MVD_MAIN_STREAM0:
8260 u8Idx = 0;
8261 break;
8262 case E_HAL_MVD_SUB_STREAM0:
8263 u8Idx = 1;
8264 break;
8265 #if 0
8266 case E_HAL_MVD_SUB_STREAM1:
8267 u8Idx = 2;
8268 break;
8269 #endif
8270 default:
8271 u8Idx = 0;
8272 break;
8273 }
8274 return u8Idx;
8275 #endif
8276 }
8277
HAL_MVD_ReleaseFdMask(MS_U8 u8Idx,MS_BOOL bRls)8278 MS_BOOL HAL_MVD_ReleaseFdMask(MS_U8 u8Idx, MS_BOOL bRls)
8279 {
8280 MVD_CmdArg mvdcmd;
8281
8282 SETUP_CMDARG(mvdcmd);
8283 mvdcmd.Arg0 = bRls; //1 to release the fd mask
8284 MVD_DEBUGINFO(printf("%s: release=0x%x\n", __FUNCTION__, bRls));
8285 SET_DECNUM(mvdcmd, u8Idx);
8286 SET_CMD_RET_FALSE(CMD_UPDATE_FRAME, &mvdcmd);
8287
8288 return TRUE;
8289 }
8290
HAL_MVD_ParserRstDone(MS_U8 u8Idx,MS_BOOL bEnable)8291 MS_BOOL HAL_MVD_ParserRstDone(MS_U8 u8Idx, MS_BOOL bEnable)
8292 {
8293 #define PARSER_RST_TIMEOUT 0x40000
8294 MS_U32 u32TimeOut = 0;
8295 MVD_CmdArg mvdcmd;
8296
8297 HAL_MVD_ResetHandShake(u8Idx, MVD_HANDSHAKE_PARSER_RST);
8298 SETUP_CMDARG(mvdcmd);
8299 mvdcmd.Arg1 = bEnable;
8300 SET_DECNUM(mvdcmd, u8Idx);
8301 SET_CMD_RET_FALSE(CMD_PTS_TBL_RESET, &mvdcmd);
8302
8303 while ((TRUE != HAL_MVD_IsCmdFinished(u8Idx, MVD_HANDSHAKE_PARSER_RST)) && (u32TimeOut < PARSER_RST_TIMEOUT))
8304 {
8305 u32TimeOut++;
8306 }
8307 if (u32TimeOut >= PARSER_RST_TIMEOUT)
8308 {
8309 MVD_DEBUGERROR( printf( "Ctrl: 0x%x fail timeout!!\r\n", CMD_PTS_TBL_RESET ) );
8310 return FALSE;
8311 }
8312 return TRUE;
8313 }
8314
HAL_MVD_FlushPTSBuf(MS_U8 u8Idx,MS_BOOL bEnable)8315 MS_BOOL HAL_MVD_FlushPTSBuf(MS_U8 u8Idx, MS_BOOL bEnable)
8316 {
8317 #ifdef VDEC3
8318 MVD_CtrlCfg* pstCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
8319
8320 if(pstCtrlCfg->u8McuMode == FALSE)
8321 #endif
8322 {
8323 MVD_CmdArg mvdcmd;
8324 SETUP_CMDARG(mvdcmd);
8325 mvdcmd.Arg0 = bEnable;
8326 if (HAL_MVD_MVDCommand( CMD_SEND_UNI_PTS, &mvdcmd ) == FALSE)
8327 {
8328 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SEND_UNI_PTS ) );
8329 return FALSE;
8330 }
8331 }
8332 return TRUE;
8333 }
8334
8335
HAL_MVD_GetSLQNum(MS_U8 u8Idx)8336 MS_U32 HAL_MVD_GetSLQNum(MS_U8 u8Idx)
8337 {
8338 MVD_SLQTBLInfo* pstSlqTblInfo = HAL_MVD_GetSlqTblInfo(u8Idx);
8339 MS_VIRT u32RdPtr = HAL_MVD_GetSLQReadPtr(u8Idx);
8340 MS_VIRT u32Diff = 0;
8341
8342 if (pstSlqTblInfo->pDrvSlqTbl->u32WrPtr >= u32RdPtr)
8343 {
8344 u32Diff = pstSlqTblInfo->pDrvSlqTbl->u32WrPtr - u32RdPtr;
8345 }
8346 else
8347 {
8348 u32Diff = SLQ_TBL_SIZE - (u32RdPtr - pstSlqTblInfo->pDrvSlqTbl->u32WrPtr);
8349 }
8350
8351 // printf("slq wptr = 0x%x, rptr = 0x%x\n", pstSlqTblInfo->pDrvSlqTbl->u32WrPtr, u32RdPtr);
8352
8353 return (u32Diff/SLQ_ENTRY_LEN);
8354 }
8355
8356
HAL_MVD_GetDispQNum(MS_U8 u8Idx)8357 MS_U32 HAL_MVD_GetDispQNum(MS_U8 u8Idx)
8358 {
8359 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DISPQ_NUM, sizeof(MS_U8));
8360 }
HAL_MVD_SetAutoMute(MS_U8 u8Idx,MS_BOOL bEn)8361 MS_BOOL HAL_MVD_SetAutoMute(MS_U8 u8Idx, MS_BOOL bEn)
8362 {
8363 MVD_CmdArg mvdcmd;
8364
8365 SETUP_CMDARG(mvdcmd);
8366 mvdcmd.Arg0 = bEn; //1 to enable
8367 MVD_DEBUGINFO(printf("%s: bEn=%x\n", __FUNCTION__, bEn));
8368 SET_DECNUM(mvdcmd, u8Idx);
8369 SET_CMD_RET_FALSE(CMD_ENABLE_AUTO_MUTE, &mvdcmd);
8370
8371 return TRUE;
8372 }
8373
HAL_MVD_SetVSizeAlign(MS_U8 u8Idx,MS_BOOL bEn)8374 MS_BOOL HAL_MVD_SetVSizeAlign(MS_U8 u8Idx, MS_BOOL bEn)
8375 {
8376 MVD_CmdArg mvdcmd;
8377
8378 SETUP_CMDARG(mvdcmd);
8379 mvdcmd.Arg0 = bEn; //1 to enable VSize alignment to 4x
8380 MVD_DEBUGINFO(printf("%s: bEn=%x\n", __FUNCTION__, bEn));
8381 SET_DECNUM(mvdcmd, u8Idx);
8382 SET_CMD_RET_FALSE(CMD_FORCE_ALIGN_VSIZE, &mvdcmd);
8383
8384 return TRUE;
8385 }
8386
HAL_MVD_GetFrmRateIsSupported(MS_U16 u16HSize,MS_U16 u16VSize,MS_U32 u32FrmRate)8387 MS_BOOL HAL_MVD_GetFrmRateIsSupported(MS_U16 u16HSize, MS_U16 u16VSize, MS_U32 u32FrmRate)
8388 {
8389 MVD_DEBUGINFO(printf("%s w:%d, h:%d, fr:%d, MAX:%lld\n", __FUNCTION__, u16HSize, u16VSize, u32FrmRate, MVD_HW_MAX_PIXEL));
8390 return (((MS_U64)u16HSize*(MS_U64)u16VSize*(MS_U64)u32FrmRate) <= MVD_HW_MAX_PIXEL);
8391 }
8392
8393 //------------------------------------------------------------------------------
8394 /// Wait MVD generate CRC done or timeout
8395 /// @return -MVD generate CRC done or timeout
8396 //------------------------------------------------------------------------------
_HAL_MVD_CrcTimeOut(MS_U8 u8Idx)8397 MS_BOOL _HAL_MVD_CrcTimeOut(MS_U8 u8Idx)
8398 {
8399 MS_U32 i;
8400 MS_U32 u32StartTime = MsOS_GetSystemTime();
8401
8402 for ( i = 0; i < MVD_PollingTimes; i++ )
8403 {
8404 ///- wait until MVD generate CRC done or timeout
8405 if ( ( HAL_MVD_RegReadByte(MVD_CRC_CTL) & MVD_CRC_CTL_DONE ) == MVD_CRC_CTL_DONE )
8406 {
8407 return FALSE;
8408 }
8409
8410 if ((TRUE == pMVDHalContext->bStopped[u8Idx]) || ((MsOS_GetSystemTime()-u32StartTime)>1300))
8411 {
8412 MVD_DEBUGINFO(printf("%s: bStopped(%x) or timeout(%d)\n", __FUNCTION__, pMVDHalContext->bStopped[u8Idx], MsOS_GetSystemTime()-u32StartTime));
8413 return TRUE;
8414 }
8415
8416 }
8417 MVD_DEBUGERROR( printf("_HAL_MVD_CrcTimeOut=%x\n", i) );
8418 return TRUE;
8419 }
8420
HAL_MVD_GetCrcValue(MS_U8 u8Idx,MVD_CrcIn * pCrcIn,MVD_CrcOut * pCrcOut)8421 E_MVD_Result HAL_MVD_GetCrcValue(MS_U8 u8Idx, MVD_CrcIn *pCrcIn, MVD_CrcOut *pCrcOut)
8422 {
8423 E_MVD_Result eRet = E_MVD_RET_OK;
8424 MS_U32 u32tmp = 0;
8425
8426 OSAL_MVD_LockHwMutex();
8427
8428 MVD_DEBUGINFO(printf("%s width=0x%x, height=0x%x, pitch=0x%x, luma=0x%lx, chroma=0x%lx\n",
8429 __FUNCTION__, pCrcIn->u32HSize, pCrcIn->u32VSize, pCrcIn->u32Strip, (unsigned long)pCrcIn->u32YStartAddr, (unsigned long)pCrcIn->u32UVStartAddr));
8430
8431 //Set generate CRC value
8432 u32tmp = ((pCrcIn->u32HSize + MVD_WIDTH_ALIGN_MASK) >> MVD_WIDTH_ALIGN_BITS) << MVD_WIDTH_ALIGN_BITS;
8433 HAL_MVD_RegWriteByte(MVD_CRC_HSIZE, u32tmp & 0xf0);
8434 HAL_MVD_RegWriteByte(MVD_CRC_HSIZE+1, (u32tmp >> 8) & 0x3f);
8435
8436 u32tmp = ((pCrcIn->u32VSize + MVD_WIDTH_ALIGN_MASK) >> MVD_WIDTH_ALIGN_BITS) << MVD_WIDTH_ALIGN_BITS;
8437 HAL_MVD_RegWriteByte(MVD_CRC_VSIZE, u32tmp & 0xff);
8438 HAL_MVD_RegWriteByte(MVD_CRC_VSIZE+1, (u32tmp >> 8) & 0xff);
8439
8440 u32tmp = (pCrcIn->u32Strip) >> 3;
8441 HAL_MVD_RegWriteByte(MVD_CRC_STRIP, u32tmp & 0xff);
8442 HAL_MVD_RegWriteByte((MVD_CRC_STRIP+1), (u32tmp >> 8) & 0xff);
8443
8444 u32tmp = (pCrcIn->u32YStartAddr) >> 3;
8445 HAL_MVD_RegWrite4Byte(MVD_CRC_Y_START, u32tmp & MVD_CRC_Y_START_LEN);
8446
8447 u32tmp = (pCrcIn->u32UVStartAddr) >> 3;
8448 HAL_MVD_RegWrite4Byte(MVD_CRC_UV_START, u32tmp & MVD_CRC_UV_START_LEN);
8449
8450 //Fire
8451 HAL_MVD_RegWriteBit(MVD_CRC_CTL, 1, MVD_CRC_CTL_FIRE);
8452
8453 //Check CRC done
8454 if ( _HAL_MVD_CrcTimeOut(u8Idx) == TRUE )
8455 {
8456 eRet = E_MVD_RET_TIME_OUT;
8457 goto _CRC_DONE;
8458 }
8459
8460 //Get CRC value
8461 pCrcOut->u32YCrc = HAL_MVD_RegReadByte(MVD_CRC_Y_L) |
8462 (HAL_MVD_RegReadByte(MVD_CRC_Y_L+1) << 8) |
8463 (HAL_MVD_RegReadByte(MVD_CRC_Y_H) <<16) |
8464 (HAL_MVD_RegReadByte(MVD_CRC_Y_H+1) <<24);
8465
8466 pCrcOut->u32UVCrc = HAL_MVD_RegReadByte(MVD_CRC_UV_L) |
8467 (HAL_MVD_RegReadByte(MVD_CRC_UV_L+1) << 8) |
8468 (HAL_MVD_RegReadByte(MVD_CRC_UV_H) <<16) |
8469 (HAL_MVD_RegReadByte(MVD_CRC_UV_H+1) <<24);
8470
8471 MVD_DEBUGINFO(printf("%s Y=0x%x, UV=0x%x\n", __FUNCTION__, pCrcOut->u32YCrc, pCrcOut->u32UVCrc));
8472
8473 _CRC_DONE:
8474 OSAL_MVD_UnlockHwMutex();
8475 return eRet;
8476 }
8477
8478
HAL_MVD_SuspendDynamicScale(MS_U8 u8Idx,MS_BOOL bEn)8479 MS_BOOL HAL_MVD_SuspendDynamicScale(MS_U8 u8Idx, MS_BOOL bEn)
8480 {
8481 MVD_CmdArg mvdcmd;
8482
8483 SETUP_CMDARG(mvdcmd);
8484 mvdcmd.Arg0 = bEn;
8485 MVD_DEBUGINFO(printf("%s: bEn=%x\n", __FUNCTION__, bEn));
8486 SET_DECNUM(mvdcmd, u8Idx);
8487 SET_CMD_RET_FALSE(CMD_SUSPEND_DS, &mvdcmd);
8488
8489 return TRUE;
8490 }
8491
HAL_MVD_GetSuspendDynamicScale(MS_U8 u8Idx)8492 MS_U8 HAL_MVD_GetSuspendDynamicScale(MS_U8 u8Idx)
8493 {
8494 return (MS_U8)MVD_GetFWBuffData(u8Idx, FW_BUFF_VOLINFO, OFFSET_SUSPEND_DS, sizeof(MS_U8));
8495 }
8496
HAL_MVD_GetStereoType(MS_U8 u8Idx)8497 MS_U8 HAL_MVD_GetStereoType(MS_U8 u8Idx)
8498 {
8499 return (MS_U8)MVD_GetFWBuffData(u8Idx, FW_BUFF_VOLINFO, OFFSET_STEREO_TYPE, sizeof(MS_U8));
8500 }
8501
HAL_MVD_GetDivxVer(MS_U8 u8Idx)8502 MS_U32 HAL_MVD_GetDivxVer(MS_U8 u8Idx)
8503 {
8504 return MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DIVX_VER_5X, sizeof(MS_U32));
8505 }
8506
HAL_MVD_SetIdctMode(MS_U8 u8Idx,MS_U8 u8Mode)8507 MS_BOOL HAL_MVD_SetIdctMode(MS_U8 u8Idx, MS_U8 u8Mode)
8508 {
8509 MVD_CmdArg mvdcmd;
8510
8511 SETUP_CMDARG(mvdcmd);
8512 mvdcmd.Arg0 = u8Mode;
8513 SET_DECNUM(mvdcmd, u8Idx);
8514
8515 MVD_DEBUGINFO(printf("%s CMD_IDCT_SEL arg0=%x)\n", __FUNCTION__, u8Mode));
8516 SET_CMD_RET_FALSE(CMD_IDCT_SEL, &mvdcmd);
8517
8518 return TRUE;
8519 }
8520
HAL_MVD_EX_SetClockSpeed(HAL_MVD_EX_ClockSpeed eClockSpeed)8521 E_MVD_Result HAL_MVD_EX_SetClockSpeed(HAL_MVD_EX_ClockSpeed eClockSpeed)
8522 {
8523 UNUSED(eClockSpeed);
8524 printf("This chip does not support mvd clock presetting~\n");
8525 return E_MVD_RET_FAIL;
8526 }
8527
HAL_MVD_GetIsAVSyncOn(MS_U8 u8Idx)8528 MS_BOOL HAL_MVD_GetIsAVSyncOn(MS_U8 u8Idx)
8529 {
8530 MS_BOOL bAVSyncOn = FALSE;
8531 MVD_CtrlCfg* pCtrlCfg = HAL_MVD_GetCtrlCfg(u8Idx);
8532 if (pCtrlCfg)
8533 {
8534 bAVSyncOn = pCtrlCfg->bAVSyncOn;
8535 }
8536
8537 return bAVSyncOn;
8538 }
8539
HAL_MVD_SetExternalDSBuff(MS_U8 u8Idx,MS_VIRT u32VPUAddr,MS_VIRT u32DrvAddr)8540 MS_BOOL HAL_MVD_SetExternalDSBuff(MS_U8 u8Idx, MS_VIRT u32VPUAddr, MS_VIRT u32DrvAddr)
8541 {
8542 MS_BOOL bRet = TRUE;
8543 MVD_FWBuff* pBuff = &(pMVDHalContext->stFWBuff[u8Idx]);
8544
8545 pBuff->u32DynScalingAdd = u32DrvAddr;
8546 bRet = HAL_MVD_SetDynamicScaleAddr(u8Idx, u32VPUAddr);
8547 return bRet;
8548 }
8549
HAL_MVD_ShowFirstFrameDirect(MS_U8 u8Idx,MS_U8 bEnable)8550 MS_BOOL HAL_MVD_ShowFirstFrameDirect(MS_U8 u8Idx, MS_U8 bEnable)
8551 {
8552 MVD_CmdArg mvdcmd;
8553
8554 SETUP_CMDARG(mvdcmd);
8555 mvdcmd.Arg0 = bEnable;
8556 SET_DECNUM(mvdcmd, u8Idx);
8557
8558 MVD_DEBUGINFO(printf("%s CMD_PUSH_FIRST_FRAME_DISP arg0=%x)\n", __FUNCTION__, bEnable));
8559 SET_CMD_RET_FALSE(CMD_PUSH_FIRST_FRAME_DISP, &mvdcmd);
8560
8561 return TRUE;
8562 }
8563
HAL_MVD_SetXCLowDelayPara(MS_U8 u8Idx,MS_U32 u32Para)8564 E_MVD_Result HAL_MVD_SetXCLowDelayPara(MS_U8 u8Idx,MS_U32 u32Para)
8565 {
8566 MVD_CmdArg mvdcmd;
8567
8568 SETUP_CMDARG(mvdcmd);
8569 mvdcmd.Arg0 = L_WORD(u32Para); // for set the XC diff_field_number
8570 mvdcmd.Arg1 = H_WORD(u32Para); // for set XC UCNR diff field no
8571 SET_DECNUM(mvdcmd, u8Idx);
8572
8573 SET_CMD_RET_FALSE(CMD_XC_LOW_DELAY_PARA, &mvdcmd);
8574
8575 return TRUE;
8576 }
8577
HAL_MVD_GetESBufferStatus(MS_U8 u8Idx)8578 MS_U8 HAL_MVD_GetESBufferStatus(MS_U8 u8Idx)
8579 {
8580 return (MS_U8)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_CURRENT_ES_BUFFER_STATUS, sizeof(MS_U8)));
8581 }
8582
HAL_MVD_Field_Polarity_Display_One_field(MS_U8 u8Idx,MS_BOOL bEn,MS_U8 top_bottom)8583 MS_BOOL HAL_MVD_Field_Polarity_Display_One_field(MS_U8 u8Idx, MS_BOOL bEn,MS_U8 top_bottom)
8584 {
8585 MVD_CmdArg mvdcmd;
8586
8587 SETUP_CMDARG(mvdcmd);
8588 mvdcmd.Arg2 = bEn;
8589 mvdcmd.Arg3 = top_bottom;
8590 MVD_DEBUGINFO(printf("%s: bEn=%x,top_bottom=%x\n", __FUNCTION__, bEn,top_bottom));
8591 SET_DECNUM(mvdcmd, u8Idx);
8592 SET_CMD_RET_FALSE(CMD_FP_FILTER, &mvdcmd);
8593
8594 return TRUE;
8595 }
8596
8597
HAL_MVD_SetShareMemoryBase(MS_U8 u8Idx,MS_VIRT u32base,MS_U8 u8sel)8598 MS_BOOL HAL_MVD_SetShareMemoryBase(MS_U8 u8Idx, MS_VIRT u32base, MS_U8 u8sel)
8599 {
8600 u8SHMMiuSel = u8sel;
8601 u32SharememoryBase[u8Idx] = u32base - MVD_FW_CODE_LEN;
8602 return TRUE;
8603 }
8604
HAL_MVD_GetShareMemoryOffset(MS_U8 u8Idx,MS_VIRT * u32base)8605 MS_BOOL HAL_MVD_GetShareMemoryOffset(MS_U8 u8Idx, MS_VIRT *u32base)
8606 {
8607 *u32base=u32SharememoryBase[u8Idx];
8608 return TRUE;
8609 }
8610
HAL_MVD_Support2ndMVOPInterface(void)8611 MS_BOOL HAL_MVD_Support2ndMVOPInterface(void)
8612 {
8613 return TRUE;
8614 }
8615
HAL_MVD_SetExternal_CC_Buffer(MS_U8 u8Idx,MS_VIRT u32base,MS_U8 u8size,MS_U8 cc_type)8616 MS_BOOL HAL_MVD_SetExternal_CC_Buffer(MS_U8 u8Idx, MS_VIRT u32base, MS_U8 u8size, MS_U8 cc_type)
8617 {
8618 MVD_CmdArg mvdcmd;
8619 MS_U32 u32cc_size=0;
8620 MS_VIRT u32StartOffset;
8621 MS_U8 u8MiuSel;
8622
8623 SETUP_CMDARG(mvdcmd);
8624 if (u8size !=0)
8625 {
8626 mvdcmd.Arg0 = TRUE; //enable
8627 }
8628 else
8629 {
8630 mvdcmd.Arg0 = FALSE; //disable
8631 }
8632 mvdcmd.Arg1 = cc_type; //608->1,708->0
8633
8634 SET_DECNUM(mvdcmd, u8Idx);
8635 SET_CMD_RET_FALSE(CMD_CC_ENABLE_EXTERNAL_BUFFER, &mvdcmd);
8636
8637 if (u8size ==0)
8638 {
8639 SET_CMD_RET_FALSE(CMD_CLOSE_CC, &mvdcmd);
8640 return E_MVD_RET_OK;
8641 }
8642
8643 u32base *= (1<<10); //unit is bytes
8644 u32cc_size = u8size * (1<<10); //unit is bytes
8645
8646
8647 MS_U32 *pu32ReadPtr = (MS_U32 *)(HAL_MVD_PA2NonCacheSeg(u32base));
8648 MS_U32 *pu32WritePtr = (MS_U32 *)(HAL_MVD_PA2NonCacheSeg(u32base+sizeof(MS_U32)));
8649 MS_U32 *pu32LatchOverflow = (MS_U32 *)(HAL_MVD_PA2NonCacheSeg(u32base+sizeof(MS_U32)*2));
8650 MS_U32 *pu32CpuBaseAddr = (MS_U32 *)(HAL_MVD_PA2NonCacheSeg(u32base+sizeof(MS_U32)*3));
8651
8652 //rptr,wptr,overflow,latch 16 bytes
8653 if(cc_type==1)
8654 {
8655 u32base += (4*sizeof(MS_U32));
8656 u32cc_size -= (4*sizeof(MS_U32));
8657 }
8658
8659 if(cc_type==0) // 708: start from 128 bytes
8660 {
8661 u32base += 128;
8662 u32cc_size -= 128;
8663 }
8664
8665 *pu32ReadPtr = *pu32WritePtr = u32base;
8666 *pu32LatchOverflow = 0;
8667 *pu32CpuBaseAddr = HAL_MVD_GetMEMCfg(u8Idx)->u32FWBinAddr;
8668
8669 _phy_to_miu_offset(u8MiuSel, u32StartOffset, u32base);
8670 _MVD_SetUserDataBufStart(u8Idx,u32StartOffset,cc_type);
8671 _MVD_SetUserDataBufSize(u8Idx,u32cc_size,cc_type);
8672 //MVD_DEBUGINFO(printf("%s: u32base=%x,u32size=%x,cc_type=%x\n", __FUNCTION__,u32base,u32cc_size,cc_type));
8673
8674 return E_MVD_RET_OK;
8675 }
8676
HAL_MVD_GetPVRSeamlessInfo(MS_U8 u8Idx,void * param)8677 MS_BOOL HAL_MVD_GetPVRSeamlessInfo(MS_U8 u8Idx,void* param)
8678 {
8679
8680 MVD_PVR_Seamless_Info* temp = (MVD_PVR_Seamless_Info*)param;
8681
8682 temp->u64PTS = ((MS_U64)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PVRSEAMLESSTARGETPTS, sizeof(MS_U32))) |
8683 (((MS_U64)MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PVRSEAMLESSTARGETPTSHIGH, sizeof(MS_U8)))<<32);
8684
8685 temp->u32POC = 0xFF; // not support in mvd
8686 temp->u8FrameType = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PVRSEAMLESSTARGETFRAMETYPE, sizeof(MS_U8));
8687
8688 return TRUE;
8689 }
8690
8691
HAL_MVD_HWBuffer_ReMappingMode(MS_U8 u8Idx,MS_BOOL bEnable)8692 E_MVD_Result HAL_MVD_HWBuffer_ReMappingMode(MS_U8 u8Idx,MS_BOOL bEnable)
8693 {
8694 pMVDHalContext->gMVDPreCtrl[u8Idx].bHWBufferReMapping = bEnable;
8695 return E_MVD_RET_OK;
8696 }
8697
HAL_MVD_SetPrebufferSize(MS_U8 u8Idx,MS_U32 size)8698 MS_BOOL HAL_MVD_SetPrebufferSize(MS_U8 u8Idx, MS_U32 size)
8699 {
8700 MVD_CmdArg mvdcmd;
8701
8702 SETUP_CMDARG(mvdcmd);
8703 mvdcmd.Arg0 = size&0xff;
8704 mvdcmd.Arg1 = (size>>8)&0xff;
8705 mvdcmd.Arg2 = (size>>16)&0xff;
8706 mvdcmd.Arg3 = (size>>24)&0xff;
8707 SET_DECNUM(mvdcmd, u8Idx);
8708 if (HAL_MVD_MVDCommand( CMD_PREBUFFER_SIZE, &mvdcmd ) == FALSE)
8709 {
8710 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PREBUFFER_SIZE ) );
8711 return FALSE;
8712 }
8713 return TRUE;
8714 }
8715
HAL_MVD_GetVsyncAddrOffset(void)8716 MS_VIRT HAL_MVD_GetVsyncAddrOffset(void)
8717 {
8718 MS_VIRT VPUSHMAddr = HAL_VPU_EX_GetSHMAddr();
8719 MS_VIRT VsyncBridgeOffset = 0;
8720
8721 if(VPUSHMAddr != 0) // TEE project
8722 {
8723 VsyncBridgeOffset = VSYNC_BRIDGE_OFFSET;
8724 }
8725 else // normal project
8726 {
8727 VsyncBridgeOffset = COMMON_AREA_START + VSYNC_BRIDGE_OFFSET;
8728 }
8729
8730 return VsyncBridgeOffset;
8731 }
8732
HAL_MVD_GetVsyncExtAddrOffset(void)8733 MS_VIRT HAL_MVD_GetVsyncExtAddrOffset(void)
8734 {
8735 MS_VIRT VsyncBridgeExtOffset = 0;
8736
8737 MS_VIRT VPUSHMAddr = HAL_VPU_EX_GetSHMAddr();
8738 if(VPUSHMAddr != 0) // TEE project
8739 {
8740 VsyncBridgeExtOffset = VSYNC_BRIDGE_EXT_OFFSET;
8741 }
8742 else // normal project
8743 {
8744 VsyncBridgeExtOffset = COMMON_AREA_START + VSYNC_BRIDGE_EXT_OFFSET;
8745 }
8746 return VsyncBridgeExtOffset;
8747 }
8748
HAL_MVD_SetTimeIncPredictParam(MS_U8 u8Idx,MS_U32 u32time)8749 E_MVD_Result HAL_MVD_SetTimeIncPredictParam(MS_U8 u8Idx, MS_U32 u32time)
8750 {
8751 MVD_CmdArg mvdcmd;
8752 SETUP_CMDARG(mvdcmd);
8753
8754 mvdcmd.Arg0 = L_WORD(u32time); // Arg0(enable), 1 for enable, default is 0...
8755 mvdcmd.Arg1 = H_WORD(u32time); // Arg1(vop_time_incr_predict_count), 1 for predict once, 2 for twice...0xff for always guess the vop_time_incr even with the vol_header, default is 0...
8756 mvdcmd.Arg2 = L_DWORD(u32time);// Arg2(vop_time_incr_follow_vol_header), // 0 for follow vol_header...1 for bypass vol_header, default is 0...
8757 mvdcmd.Arg3 = H_DWORD(u32time);// Arg3, reserve...
8758 MVD_DEBUGINFO(printf("CMD_TIME_INCR_PREDICT=%x\n",u32time));
8759 if (HAL_MVD_MVDCommand(CMD_TIME_INCR_PREDICT, &mvdcmd) == FALSE)
8760 {
8761 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_TIME_INCR_PREDICT ) );
8762 return E_MVD_RET_FAIL;
8763 }
8764 return E_MVD_RET_OK;
8765
8766 }
8767
HAL_MVD_SetDecodeTimeoutParam(MS_U8 u8Idx,MS_BOOL enable,MS_U32 u32timeout)8768 MS_BOOL HAL_MVD_SetDecodeTimeoutParam(MS_U8 u8Idx, MS_BOOL enable,MS_U32 u32timeout)
8769 {
8770 MVD_CmdArg mvdcmd;
8771
8772 SETUP_CMDARG(mvdcmd);
8773
8774 if(enable == TRUE)
8775 {
8776 mvdcmd.Arg0 = 2; //0:disable, 2: enable decode timeout
8777 mvdcmd.Arg1 = u32timeout&0xff;
8778 mvdcmd.Arg2 = (u32timeout>>8)&0xff;
8779 mvdcmd.Arg3 = (u32timeout>>16)&0xff;
8780 }
8781 else
8782 {
8783 mvdcmd.Arg0 = 0; //0:disable, 2: enable decode timeout
8784 }
8785
8786 SET_DECNUM(mvdcmd, u8Idx);
8787
8788 if (HAL_MVD_MVDCommand( CMD_ENABLE_VLD_TIMEOUT, &mvdcmd ) == FALSE)
8789 {
8790 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_ENABLE_VLD_TIMEOUT ) );
8791 return FALSE;
8792 }
8793
8794 return TRUE;
8795 }
8796
HAL_MVD_Set_Smooth_Rewind(MS_U8 u8Idx,MS_U8 btype)8797 E_MVD_Result HAL_MVD_Set_Smooth_Rewind(MS_U8 u8Idx, MS_U8 btype)
8798 {
8799 MVD_CmdArg mvdcmd;
8800 SETUP_CMDARG(mvdcmd);
8801 mvdcmd.Arg0 = btype;
8802 MVD_DEBUGINFO(printf("%s: btype=%x\n", __FUNCTION__, btype));
8803 SET_DECNUM(mvdcmd, u8Idx);
8804 if (HAL_MVD_MVDCommand(CMD_SMOOTH_REWIND, &mvdcmd) == FALSE)
8805 {
8806 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SMOOTH_REWIND ) );
8807 return E_MVD_RET_FAIL;
8808 }
8809 return E_MVD_RET_OK;
8810 }
8811
HAL_MVD_IsAlive(MS_U8 u8Idx)8812 E_MVD_Result HAL_MVD_IsAlive(MS_U8 u8Idx)
8813 {
8814 MVD_ALIVEInfo* pAliveInfo = &(pMVDHalContext->aliveInfo[u8Idx]);
8815 MVD_SrcMode curSrcMode = HAL_MVD_GetSrcMode(u8Idx);
8816
8817 if (E_MVD_SLQ_TBL_MODE == curSrcMode || E_MVD_TS_FILE_MODE == curSrcMode)
8818 {
8819 if(pMVDHalContext->u32LastAliveTime[u8Idx] == 0 || ((MsOS_GetSystemTime()-pMVDHalContext->u32LastAliveTime[u8Idx]) < 500))
8820 {
8821
8822 if(pMVDHalContext->u32LastAliveTime[u8Idx] == 0 )
8823 {
8824 pMVDHalContext->u32LastAliveTime[u8Idx] = MsOS_GetSystemTime();
8825 }
8826 return E_MVD_RET_OK;
8827 }
8828 }
8829
8830 #if 0
8831 printf("[%d]%d,%d,%d,%d,%d,%d,%d,%d\n",__FUNCTION__,
8832 (MS_U32)MsOS_GetSystemTime(),
8833 (MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DECODEDONE_COUNT, sizeof(MS_U32))),
8834 (MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHBUF_COUNT, sizeof(MS_U32))),
8835 (MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHCODE_COUNT, sizeof(MS_U32))),
8836 (MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PREBUF_COUNT, sizeof(MS_U32))),
8837 (MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_VFIFOBUF_COUNT, sizeof(MS_U32))),
8838 (MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHHEADER_COUNT, sizeof(MS_U32))),
8839 (MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_FLASHPATTERN_COUNT, sizeof(MS_U32))));
8840 #endif
8841
8842 //check count to vertify alive
8843 if((pAliveInfo->u32decode_count!=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DECODEDONE_COUNT, sizeof(MS_U32))))||
8844 (pAliveInfo->u32searchbuf_count!=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHBUF_COUNT, sizeof(MS_U32))))||
8845 (pAliveInfo->u32searchcode_count!=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHCODE_COUNT, sizeof(MS_U32))))||
8846 (pAliveInfo->u32prebuf_count!=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PREBUF_COUNT, sizeof(MS_U32))))||
8847 (pAliveInfo->u32vfifobuf_count!=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_VFIFOBUF_COUNT, sizeof(MS_U32))))||
8848 (pAliveInfo->u32searchheader_count!=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHHEADER_COUNT, sizeof(MS_U32))))||
8849 (pAliveInfo->u32flashpattern_count!=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_FLASHPATTERN_COUNT, sizeof(MS_U32)))))
8850 {
8851 pAliveInfo->u32decode_count=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_DECODEDONE_COUNT, sizeof(MS_U32)));
8852 pAliveInfo->u32searchbuf_count=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHBUF_COUNT, sizeof(MS_U32)));
8853 pAliveInfo->u32searchcode_count=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHCODE_COUNT, sizeof(MS_U32)));
8854 pAliveInfo->u32prebuf_count=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PREBUF_COUNT, sizeof(MS_U32)));
8855 pAliveInfo->u32vfifobuf_count=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_VFIFOBUF_COUNT, sizeof(MS_U32)));
8856 pAliveInfo->u32searchheader_count=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_SEARCHHEADER_COUNT, sizeof(MS_U32)));
8857 pAliveInfo->u32flashpattern_count=(MS_U32)(MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_FLASHPATTERN_COUNT, sizeof(MS_U32)));
8858 pMVDHalContext->u32LastAliveTime[u8Idx] = MsOS_GetSystemTime();
8859 return E_MVD_RET_OK;
8860 }
8861 else
8862 {
8863 pMVDHalContext->u32LastAliveTime[u8Idx] = MsOS_GetSystemTime();
8864 return E_MVD_RET_FAIL;
8865 }
8866
8867 }
8868
HAL_MVD_Set_Err_Tolerance(MS_U8 u8Idx,MS_U16 u16Para)8869 E_MVD_Result HAL_MVD_Set_Err_Tolerance(MS_U8 u8Idx, MS_U16 u16Para)
8870 {
8871 MVD_CmdArg mvdcmd;
8872 SETUP_CMDARG(mvdcmd);
8873 mvdcmd.Arg0 = u16Para & 0xFF; //enable or disable
8874 mvdcmd.Arg1 = u16Para >> 8; // err rate 0~100%
8875 if(mvdcmd.Arg1 >= 100)
8876 mvdcmd.Arg1 = 100;
8877
8878 SET_DECNUM(mvdcmd, u8Idx);
8879 if (HAL_MVD_MVDCommand(CMD_DECODE_ERROR_TOLERANCE, &mvdcmd) == FALSE)
8880 {
8881 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_DECODE_ERROR_TOLERANCE ) );
8882 return E_MVD_RET_FAIL;
8883 }
8884 return E_MVD_RET_OK;
8885
8886 }
8887
HAL_MVD_EnableAutoInsertDummyPattern(MS_U8 u8Idx,MS_BOOL bEnable)8888 void HAL_MVD_EnableAutoInsertDummyPattern(MS_U8 u8Idx, MS_BOOL bEnable)
8889 {
8890 pMVDHalContext->bAutoInsertDummyPattern[u8Idx] = bEnable;
8891 }
8892
HAL_MVD_Drop_One_PTS(MS_U8 u8Idx)8893 void HAL_MVD_Drop_One_PTS(MS_U8 u8Idx)
8894 {
8895 pMVDHalContext->bDropOnePTS[u8Idx] = TRUE;
8896 }
8897
HAL_MVD_PVR_Seamless_mode(MS_U8 u8Idx,MS_U8 u8Arg)8898 E_MVD_Result HAL_MVD_PVR_Seamless_mode(MS_U8 u8Idx, MS_U8 u8Arg)
8899 {
8900 #define STOP_TIMEOUT 500 //ms
8901 MVD_CmdArg mvdcmd;
8902 E_MVD_Result ret = E_MVD_RET_OK;
8903 MS_U32 u32StartTime;
8904 MS_U32 u32SeamlessStatus = 0;
8905 MS_U32 u32BufStart = 0;
8906 MS_U32* temp = 0;
8907
8908 if(u8Arg != 2)
8909 {
8910 // clear handshake dram
8911 u32BufStart = GET_FRMINFO_BUFFADD(u8Idx);
8912 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,u32BufStart,u32BufStart);
8913 temp = (MS_U32*)MsOS_PA2KSEG1(u32BufStart+OFFSET_PVR_SEAMLESS_STATUS);
8914 *temp = 0;
8915 MsOS_FlushMemory();
8916 }
8917
8918 SETUP_CMDARG(mvdcmd);
8919 mvdcmd.Arg0 = u8Arg;
8920 MVD_DEBUGINFO(printf("%s: arg=%d\n", __FUNCTION__, (unsigned int)u8Arg));
8921 SET_DECNUM(mvdcmd, u8Idx);
8922
8923 if (HAL_MVD_MVDCommand(CMD_PVR_SEAMLESS_MODE, &mvdcmd) == FALSE)
8924 {
8925 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_PVR_SEAMLESS_MODE ) );
8926 return E_MVD_RET_FAIL;
8927 }
8928
8929
8930 u32StartTime = HAL_MVD_GetTime();
8931
8932 if(u8Arg == 1)
8933 {
8934 pMVDHalContext->stFwCfg[u8Idx].eSrcMode = E_MVD_TS_FILE_MODE;
8935 while(1)
8936 {
8937 u32SeamlessStatus = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PVR_SEAMLESS_STATUS, sizeof(MS_U32));
8938 if(u32SeamlessStatus&1) // bit0 , pause done
8939 {
8940 break;
8941 }
8942
8943 if((HAL_MVD_GetTime()-u32StartTime)>STOP_TIMEOUT)
8944 {
8945 MVD_DEBUGERROR(printf("PVR seamless pause timeout\n" ) );
8946 ret = E_MVD_RET_FAIL;
8947 break;
8948 }
8949 }
8950 }
8951 else if(u8Arg == 2)
8952 {
8953 while(1)
8954 {
8955 u32SeamlessStatus = MVD_GetFWBuffData(u8Idx, FW_BUFF_FRMINFO, OFFSET_PVR_SEAMLESS_STATUS, sizeof(MS_U32));
8956 if(u32SeamlessStatus&4) // bit2, hw reset done
8957 {
8958 break;
8959 }
8960
8961 if((HAL_MVD_GetTime()-u32StartTime)>STOP_TIMEOUT)
8962 {
8963 MVD_DEBUGERROR(printf("PVR seamless hw reset timeout\n" ) );
8964 ret = E_MVD_RET_FAIL;
8965 break;
8966 }
8967 }
8968 }
8969
8970 return ret;
8971 }
8972
HAL_MVD_SetDVXCShmAddr(MS_U8 u8Idx,MS_PHY u32FWBaseAddr,MS_PHY u32DVXCShmAddr)8973 E_MVD_Result HAL_MVD_SetDVXCShmAddr(MS_U8 u8Idx, MS_PHY u32FWBaseAddr, MS_PHY u32DVXCShmAddr)
8974 {
8975 E_MVD_Result ret = E_MVD_RET_OK;
8976
8977 MS_U8 u8XCShmMiuSel;
8978 MS_U32 u32XCShmStartOffset;
8979 MS_U8 u8FWBaseMiuSel;
8980 MS_U32 u32FWBaseOffset;
8981 MVD_CmdArg mvdcmd;
8982 MS_U32 u32temp = 0;
8983
8984 _phy_to_miu_offset(u8FWBaseMiuSel, u32FWBaseOffset, u32FWBaseAddr);
8985 _phy_to_miu_offset(u8XCShmMiuSel, u32XCShmStartOffset, u32DVXCShmAddr);
8986
8987 if (u8FWBaseMiuSel != u8XCShmMiuSel)
8988 {
8989 MVD_DEBUGERROR(printf("[ERROR] XC share memory and VDEC Code base MIU selections are different\n"));
8990 return E_MVD_RET_FAIL;
8991 }
8992
8993 u32temp = u32XCShmStartOffset - u32FWBaseOffset;
8994
8995 SETUP_CMDARG(mvdcmd);
8996
8997 mvdcmd.Arg0 = L_WORD(u32temp);
8998 mvdcmd.Arg1 = H_WORD(u32temp);
8999 mvdcmd.Arg2 = L_DWORD(u32temp);
9000 mvdcmd.Arg3 = H_DWORD(u32temp);
9001
9002 MVD_DEBUGINFO(printf("%s: arg=%x\n", __FUNCTION__, (unsigned int)u32temp));
9003
9004 SET_DECNUM(mvdcmd, u8Idx);
9005
9006 if (HAL_MVD_MVDCommand(CMD_SET_DV_XC_SHM_ADDR, &mvdcmd) == FALSE)
9007 {
9008 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SET_DV_XC_SHM_ADDR ) );
9009 return E_MVD_RET_FAIL;
9010 }
9011
9012 return ret;
9013 }
9014
9015
HAL_MVD_SetDisplayFinishMode(MS_U8 u8Idx,MS_U8 u8Mode)9016 E_MVD_Result HAL_MVD_SetDisplayFinishMode(MS_U8 u8Idx, MS_U8 u8Mode)
9017 {
9018 MVD_CmdArg mvdcmd;
9019
9020 SETUP_CMDARG(mvdcmd);
9021 mvdcmd.Arg0 = u8Mode;
9022
9023 SET_DECNUM(mvdcmd, u8Idx);
9024
9025 MVD_DEBUGINFO(printf("%s CMD_ENABLE_LAST_FRAME_QUALIFIER arg0=%x\n", __FUNCTION__, u8Mode));
9026 if (HAL_MVD_MVDCommand(CMD_ENABLE_LAST_FRAME_QUALIFIER, &mvdcmd)== FALSE)
9027 {
9028 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_ENABLE_LAST_FRAME_QUALIFIER) );
9029 return E_MVD_RET_FAIL;
9030 }
9031
9032 return E_MVD_RET_OK;
9033 }
9034
HAL_MVD_Set_SlowSyncParam(MS_U8 u8Idx,MS_U8 u8RepeatPeriod,MS_U8 u8DropPeriod)9035 E_MVD_Result HAL_MVD_Set_SlowSyncParam(MS_U8 u8Idx, MS_U8 u8RepeatPeriod,MS_U8 u8DropPeriod)
9036 {
9037 MVD_CmdArg mvdcmd;
9038 SETUP_CMDARG(mvdcmd);
9039
9040 mvdcmd.Arg0 = u8RepeatPeriod;
9041
9042 SET_DECNUM(mvdcmd, u8Idx);
9043 if (HAL_MVD_MVDCommand(CMD_SLOW_SYNC_REPEAT, &mvdcmd) == FALSE)
9044 {
9045 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLOW_SYNC_REPEAT ) );
9046 return E_MVD_RET_FAIL;
9047 }
9048
9049
9050 mvdcmd.Arg0 = u8DropPeriod;
9051
9052 SET_DECNUM(mvdcmd, u8Idx);
9053 if (HAL_MVD_MVDCommand(CMD_SLOW_SYNC_SKIP, &mvdcmd) == FALSE)
9054 {
9055 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_SLOW_SYNC_SKIP ) );
9056 return E_MVD_RET_FAIL;
9057 }
9058
9059
9060 return E_MVD_RET_OK;
9061
9062 }
9063
HAL_MVD_VariableFrameRate(MS_U8 u8Idx)9064 MS_BOOL HAL_MVD_VariableFrameRate(MS_U8 u8Idx)
9065 {
9066 MVD_CmdArg mvdcmd;
9067 SETUP_CMDARG(mvdcmd);
9068 mvdcmd.Arg0 = 1;
9069 SET_DECNUM(mvdcmd, u8Idx);
9070 if (HAL_MVD_MVDCommand(CMD_VARIABLE_FRAMERATE, &mvdcmd)== FALSE)
9071 {
9072 MVD_DEBUGERROR( printf( "Command: 0x%x fail!!\r\n", CMD_VARIABLE_FRAMERATE) );
9073 return FALSE;
9074 }
9075 return TRUE;
9076 }
9077
9078 //------------------------------------------------------------------------------
9079 /// Set FRC Only Show TopField
9080 /// @return -TRUE for success; FALSE for failure.
9081 //------------------------------------------------------------------------------
HAL_MVD_FRC_OnlyShowTopField(MS_U8 u8Idx,MS_BOOL bEnable)9082 MS_BOOL HAL_MVD_FRC_OnlyShowTopField(MS_U8 u8Idx, MS_BOOL bEnable)
9083 {
9084 MVD_CmdArg mvdcmd;
9085
9086 SETUP_CMDARG(mvdcmd);
9087 mvdcmd.Arg0 = bEnable; //1 -> show Only Show TopField. 0 -> normal case.
9088 SET_DECNUM(mvdcmd, u8Idx);
9089 SET_CMD_RET_FALSE(CMD_FRC_ONLY_SHOW_TOP_FIELD, &mvdcmd);
9090 return TRUE;
9091 }
9092
HAL_MVD_DisableESFullStop(MS_U8 u8Idx,MS_BOOL bDisable)9093 MS_BOOL HAL_MVD_DisableESFullStop(MS_U8 u8Idx, MS_BOOL bDisable)
9094 {
9095 MVD_CmdArg mvdcmd;
9096 SETUP_CMDARG(mvdcmd);
9097 mvdcmd.Arg0 = bDisable;
9098 SET_DECNUM(mvdcmd, u8Idx);
9099 if (HAL_MVD_MVDCommand( CMD_ES_FULL_STOP, &mvdcmd ) == FALSE)
9100 {
9101 printf( "Command: 0x%x fail!!\r\n", CMD_ES_FULL_STOP);
9102 return FALSE;
9103 }
9104 return TRUE;
9105 }
9106
HAL_MVD_PUSI_Control(MS_U8 u8Idx,MS_BOOL bEnable)9107 MS_BOOL HAL_MVD_PUSI_Control(MS_U8 u8Idx, MS_BOOL bEnable)
9108 {
9109 MVD_CmdArg mvdcmd;
9110 SETUP_CMDARG(mvdcmd);
9111 mvdcmd.Arg0 = bEnable;
9112 SET_DECNUM(mvdcmd, u8Idx);
9113 if (HAL_MVD_MVDCommand( CMD_PUSI_CONTROL, &mvdcmd ) == FALSE)
9114 {
9115 MVD_PRINT( "Command: 0x%x fail!!\r\n", CMD_PUSI_CONTROL);
9116 return FALSE;
9117 }
9118 return TRUE;
9119 }
9120
9121
HAL_MVD_GetVBBUTableAddr(MS_U8 u8Idx)9122 MS_VIRT HAL_MVD_GetVBBUTableAddr(MS_U8 u8Idx)
9123 {
9124 return pMVDHalContext->stFWBuff[(u8Idx)].u32VBBUTableAdd;
9125 }
9126
HAL_MVD_SetDmxFrameRate(MS_U8 u8HalIdx,MS_U32 u32Value)9127 void HAL_MVD_SetDmxFrameRate(MS_U8 u8HalIdx,MS_U32 u32Value)
9128 {
9129 pMVDHalContext->u32DmxFrameRate[u8HalIdx] = u32Value;
9130 }
9131
HAL_MVD_SetDmxFrameRateBase(MS_U8 u8HalIdx,MS_U32 u32Value)9132 void HAL_MVD_SetDmxFrameRateBase(MS_U8 u8HalIdx,MS_U32 u32Value)
9133 {
9134 pMVDHalContext->u32DmxFrameRateBase[u8HalIdx] = u32Value;
9135 }
9136
HAL_MVD_TrickPlay2xAVSync(MS_U8 u8Idx,MS_BOOL bEnable)9137 void HAL_MVD_TrickPlay2xAVSync(MS_U8 u8Idx,MS_BOOL bEnable)
9138 {
9139 pMVDHalContext->bTrickPlay2xAVSync[u8Idx] = bEnable;
9140 }
9141
HAL_MVD_SetCMAInformation(void * cmaInitParam)9142 void HAL_MVD_SetCMAInformation(void* cmaInitParam)
9143 {
9144 pMVDHalContext->bCMAUsed = TRUE;
9145 memcpy((void*)(&pMVDHalContext->cmaInitParam),cmaInitParam,sizeof(struct CMA_Pool_Init_Param));
9146 }
9147
HAL_MVD_GetCMAInformation(MS_U8 u8HalIdx,MS_U64 * u64Addr,MS_SIZE * u64Size,MS_BOOL * bAllocDone)9148 void HAL_MVD_GetCMAInformation(MS_U8 u8HalIdx,MS_U64* u64Addr,MS_SIZE* u64Size,MS_BOOL* bAllocDone)
9149 {
9150 FW_VOL_INFO gvolInfo;
9151 MS_U32 u32VolAddr;
9152
9153 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,GET_VOL_BUFFADD(u8HalIdx),u32VolAddr);
9154
9155 gvolInfo = (*(volatile FW_VOL_INFO*)(MsOS_PA2KSEG1(u32VolAddr)));
9156
9157 *u64Addr = (MS_U64)gvolInfo.CMA_FB_Address;
9158 *u64Size = (MS_SIZE)gvolInfo.CMA_FB_Size;
9159 *bAllocDone = gvolInfo.CMA_AllocDone;
9160
9161 MsOS_ReadMemory();
9162 MsOS_FlushMemory();
9163 }
9164
HAL_MVD_SetCMAAllocateDone(MS_U8 u8HalIdx)9165 void HAL_MVD_SetCMAAllocateDone(MS_U8 u8HalIdx)
9166 {
9167 MS_U8* temp;
9168 MS_VIRT u32VolAddr;
9169
9170 _miu_offset_to_phy(pMVDHalContext->stMiuCfg.u8FWMiuSel,GET_VOL_BUFFADD(u8HalIdx),u32VolAddr);
9171
9172 temp = (MS_U8*)(MsOS_PA2KSEG1(u32VolAddr+OFFSET_CMA_ALLOCDONE));
9173
9174 *temp = 1;
9175
9176 MsOS_ReadMemory();
9177 MsOS_FlushMemory();
9178 }
9179
HAL_MVD_SetFrameBufferMiu(MS_U8 u8HalIdx,MS_U8 u8MiuIdx)9180 void HAL_MVD_SetFrameBufferMiu(MS_U8 u8HalIdx,MS_U8 u8MiuIdx)
9181 {
9182 //to do....
9183 }
9184
9185
9186 #ifdef VDEC3
HAL_MVD_IsDisplayCommand(MS_U8 u8Cmd)9187 MS_BOOL HAL_MVD_IsDisplayCommand(MS_U8 u8Cmd)
9188 {
9189
9190 #if 1 // to do.
9191 UNUSED(u8Cmd);
9192 return TRUE;
9193 #else
9194 MS_BOOL ret;
9195 switch(u8Cmd)
9196 {
9197 case CMD_PLAY:
9198 case CMD_STOP:
9199 case CMD_DISPLAY_PAUSE:
9200 case CMD_PAUSE:
9201 case CMD_FLUSH_DISP_QUEUE:
9202 case CMD_VC1_HW_SLQ_RESET:
9203 case CMD_FAST_SLOW:
9204 case CMD_FLIP_RELEASE_FRAME:
9205 case CMD_FD_MASK_DELAY_CNT:
9206 case CMD_PVR_SEAMLESS_MODE:
9207 case CMD_SW_RESET:
9208 case CMD_CODEC_INFO:
9209 case CMD_CODE_OFFSET:
9210 case CMD_VOL_INFO_BUF:
9211 case CMD_FRAME_INFO_BUF:
9212 case CMD_HEADER_INFO_BUF:
9213 case CMD_USER_BUF_START:
9214 case CMD_USER_BUF_SIZE:
9215 case CMD_PTS_TBL_START:
9216 case CMD_DEC_FRAME_INFO_BUF:
9217 case CMD_SLQ_TBL_BUF_END:
9218 case CMD_SLQ_TBL_BUF_START:
9219 case CMD_STREAM_BUF_START:
9220 case CMD_STREAM_BUF_END:
9221 case CMD_FB_BASE:
9222 case CMD_IAP_BUF_START:
9223 case CMD_DP_BUF_START:
9224 case CMD_MV_BUF_START:
9225 case CMD_FB_NUM:
9226 case CMD_DISPLAY_CTL:
9227 case CMD_REPEAT_MODE:
9228 case CMD_DS_VIRTUAL_BOX:
9229 case CMD_ENABLE_FILE_SYNC:
9230 case CMD_RVU_EN:
9231 case CMD_START_DEC_STRICT:
9232 case CMD_SYNC_ON:
9233 case CMD_SET_MST_MODE:
9234 case CMD_SET_MCU_MODE:
9235 ret = TRUE;
9236 break;
9237 default:
9238 ret = FALSE;
9239 break;
9240 }
9241
9242 return ret;
9243 #endif
9244 }
9245
HAL_MVD_IsNormalCommand(MS_U8 u8Cmd)9246 MS_BOOL HAL_MVD_IsNormalCommand(MS_U8 u8Cmd)
9247 {
9248 MS_BOOL ret;
9249
9250 switch(u8Cmd)
9251 {
9252
9253 case CMD_DISP_SPEED_CTRL:
9254 case CMD_STEP_DISP_DECODE_ONE:
9255 case CMD_ENABLE_LAST_FRAME_SHOW:
9256 case CMD_STEP_TO_PTS:
9257 case CMD_SKIP_DATA:
9258 case CMD_DIU_WIDTH_ALIGN:
9259 case CMD_SCALER_INFO_BASE:
9260 case CMD_DYNAMIC_SCALE_BASE:
9261 case CMD_ENABLE_DYNAMIC_SCALE:
9262 case CMD_FORCE_BLUE_SCREEN:
9263 case CMD_FREEZE_DISP:
9264 case CMD_FIXED_FRAME_BUFFER:
9265 case CMD_SEND_UNI_PTS:
9266 case CMD_ENABLE_FREEZE_PIC:
9267 case CMD_PTS_BASE:
9268 case CMD_SINGLE_STEP:
9269 case CMD_PARSE_M4V_PACKMD:
9270 case CMD_SLQ_END:
9271 case CMD_SLQ_START:
9272 case CMD_ENABLE_INT_STAT:
9273 case CMD_SHOW_ONE_FIELD:
9274 case CMD_FRC_OUPUT:
9275 case CMD_FRC_DROP_BEHAVIOR:
9276 case CMD_FORBID_RESOLUTION_CHANGE:
9277 case CMD_DUMP_BITSTREAM_BASE:
9278 case CMD_DUMP_BITSTREAM_LENGTH:
9279 case CMD_SYNC_OFFSET:
9280 case CMD_SYN_THRESHOLD:
9281 case CMD_AVSYNC_FREERUN_THRESHOLD:
9282 case CMD_MVD_FAST_INT:
9283 case CMD_DIVX_PATCH:
9284 case CMD_IDCT_SEL:
9285 case CMD_SLQ_UPDATE_TBL_WPTR:
9286 case CMD_DMA_OVFTH:
9287 case CMD_DMA_UNFTH:
9288 case CMD_UPDATE_FRAME:
9289 case CMD_PTS_TBL_RESET:
9290 case CMD_ENABLE_AUTO_MUTE:
9291 case CMD_FORCE_ALIGN_VSIZE:
9292 case CMD_SUSPEND_DS:
9293 case CMD_PUSH_FIRST_FRAME_DISP:
9294 case CMD_XC_LOW_DELAY_PARA:
9295 case CMD_FP_FILTER:
9296 case CMD_CC_ENABLE_EXTERNAL_BUFFER:
9297 case CMD_CLOSE_CC:
9298 case CMD_PREBUFFER_SIZE:
9299 case CMD_TIME_INCR_PREDICT:
9300 case CMD_ENABLE_VLD_TIMEOUT:
9301 case CMD_SMOOTH_REWIND:
9302 case CMD_DECODE_ERROR_TOLERANCE:
9303 case CMD_MVD_IDLE:
9304 case CMD_PARSER_READ_POSITION:
9305 case CMD_SLQ_GET_TBL_RPTR:
9306 case CMD_DECODE_STATUS:
9307 case CMD_GET_AFD:
9308 case CMD_GET_SYNC_STAT:
9309 case CMD_RD_USER_WP:
9310 case CMD_ENABLE_LAST_FRAME_QUALIFIER:
9311 //case CMD_RD_IO: // no need in V3
9312 //case CMD_WR_IO: // no need in V3
9313 ret = TRUE;
9314 break;
9315 default:
9316 ret = FALSE;
9317 break;
9318 }
9319
9320 return ret;
9321 }
9322
HAL_MVD_IsNeedResponseCommand(MS_U8 u8Cmd)9323 MS_BOOL HAL_MVD_IsNeedResponseCommand(MS_U8 u8Cmd)
9324 {
9325 MS_BOOL ret;
9326
9327 switch(u8Cmd)
9328 {
9329 case CMD_GET_AFD:
9330 case CMD_GET_SYNC_STAT:
9331 case CMD_RD_USER_WP:
9332 case CMD_DECODE_STATUS:
9333 case CMD_PARSER_READ_POSITION:
9334 case CMD_MVD_IDLE:
9335 ret = TRUE;
9336 break;
9337 default:
9338 ret = FALSE;
9339 break;
9340 }
9341
9342 return ret;
9343 }
9344 #endif
9345 #endif
9346