Example #1
0
/**
 * Initialize COM port connection
 */
BOOL fgHDDFsMount (UINT32 u4InstID)
{
    if (fd != 0)
    {
        fgHDDFsUnMount(u4InstID);
    }
#ifdef USB_ACM_DMA1
    printk("[USBIO] =====> Open /dev/usbacm <=====\n");
#else
    printk("[USBIO] =====> Open /dev/ttyGS0 <=====\n");
#endif

    vdecinitKernelEnv();
#ifdef USB_ACM_DMA1
    fd = filp_open("/dev/usbacm", O_RDWR|O_NOCTTY|O_NDELAY, 0);
    if (fd == 0) 
    {   printk("[USBIO] Open /dev/usbacm failed\n");
        return 0;
    }
#else
    fd = filp_open("/dev/ttyGS0", O_RDWR, 0);
    if (fd == 0) 
    {   printk("[USBIO] Open /dev/ttyGS0 failed\n");
        return 0;
    }
    
    fd->f_op->unlocked_ioctl(fd, TCGETS, (unsigned long)&settings);
    // TODO: Error handling

    settings.c_cflag &= ~CBAUD;
    settings.c_cflag |= B921600;
    settings.c_cflag &= ~PARENB;
    settings.c_cflag &= ~CSTOPB;
    settings.c_cflag &= ~CSIZE;
    settings.c_cflag |= CS8 | CLOCAL | CREAD;
    
    settings.c_iflag &= ~(INLCR | ICRNL | IXON | IXOFF | IXANY);
    settings.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);  // raw input
    settings.c_oflag &= ~OPOST;  // raw output

    settings.c_cc[VMIN] = 0;
    settings.c_cc[VTIME] = 100;
    
    fd->f_op->unlocked_ioctl(fd, TCSETS, (unsigned long)&settings); 
#endif    
    // TODO: Error handling


    return TRUE;
}
void vVDecVerifyThread(void* vpdata)
{
  VDEC_PARAM_T* pparam = vpdata;
  UINT32 u4InstID;
    UINT32 u4WmvMode;
  BOOL fgOpen,fgExistVerifyLoop;
  BOOL fgMVCType;
  BOOL fgInit;
  char strMessage[512];
  CHAR strVP6SizeFile[ 512];
  u4InstID =  pparam->u4InstanceId;
  _fgMVCType = pparam->fgMVCType;
//  u4WmvMode  =  pparam->u4Mode;   
  u4WmvMode  =  1;//(UINT32) ppv_param[1]; /* 1: VP6 adobe mode; 0: Open source or multi-stream. */  
 
  #if VDEC_CACHE_PROC
  UINT32 u4FifoDataSize = 0;
  UINT32 u4MappedVFifoSa = 0;
  //struct device rDev; 
  #endif
  g_fgAllocate[0] = FALSE;
  g_fgAllocate[1] = FALSE;
  g_u4AllocSize = 0;
  printk("u4InstID = %d,u4WmvMode = %d mvc = %d\n",u4InstID,u4WmvMode,_fgMVCType);
  fgExistVerifyLoop = FALSE;
  
    if (u4WmvMode > 0)
    {
        _u4WmvMode[u4InstID] = 1;
        _u4AdobeMode[u4InstID] = 1;
    }
    else
    {
        _u4WmvMode[u4InstID] = 0;
        _u4AdobeMode[u4InstID] = 0;
    }

    if(_fgMVCType)
    {
      _fgMVCBaseGo = FALSE;
      if(u4InstID == 1)
      {
        _fgMVCResReady[0] = FALSE;
        _fgMVCResReady[1] = FALSE;
      }
      while((u4InstID == 0) && (!_fgMVCBaseGo))
      {
        msleep(5);
      }
    }
    
    
    vVDecGconEnable();
#if (CONFIG_DRV_FPGA_BOARD)
#else
  vVDecClockSelect();
#endif

  vMemoryAllocate(u4InstID);

#if VDEC_DRAM_BUSY_TEST
   vDrmaBusySet (u4InstID);
#endif

#ifdef SATA_HDD_READ_SUPPORT
   #ifndef  SATA_HDD_FS_SUPPORT
  fgInitHDDFileAccess(u4InstID);
   #else
      //FS mount
    fgHDDFsMount(0);
   #endif
#endif

#if OUTPUT_USB_FILE
if(-1 == gfpH264log){
  gfpH264log = vdecopenFile((char*)H264LOGFILENAME,O_CREAT|O_WRONLY,0); 
  if (gfpH264log == -1)
  {
      printk("Fs open file fail %d\n", gfpH264log);
  }
  else{
      gH264logbufferOffset = 0;
      printk("Create H264Log file --> %d \n", gfpH264log);
  }
}

#endif


#ifdef IDE_READ_SUPPORT
  _DmxIdeReset();
#endif
#ifdef BARREL2_THREAD_SUPPORT
  if(!_fgSemaCreated[u4InstID])
  {
    VERIFY (x_sema_create(&_ahVDecEndSema[u4InstID], X_SEMA_TYPE_BINARY, X_SEMA_STATE_UNLOCK) == OSR_OK);
    _fgSemaCreated[u4InstID] = TRUE;
  }
#endif
  _u4StartCompPicNum[u4InstID] = 0;
  _u4EndCompPicNum[u4InstID] = 0xffffffff;
  _u4DumpRegPicNum[u4InstID] = 0xffffffff;
  _u4MaxReDecBistreamCnt[u4InstID] = 0;
#ifdef REDEC 
  //_u4ReDecNum[u4InstID] = 0;
  //_u4ReDecPicNum[u4InstID] = 0;
  _u4ReDecCnt[u4InstID] = 0;
#endif
  _u4RedecBistreamCnt[u4InstID] = 0xffffffff;
  _u4FileCnt[u4InstID] = 0;
  _u4FileListIdx[u4InstID] = 0;
  _u4FilePos[u4InstID] = 0;
  #ifdef WMV_CRC_COMPOSITE_CHECK_ENABLE
  _u4CRCCnt[u4InstID] = 0;
  #endif
#ifdef VERIFICATION_DOWN_SCALE
  _fgVDSCLEnableRandomTest[u4InstID] = TRUE;
   _fgVDSCLEnableLumaKeyTest[u4InstID] = FALSE;
#endif
#ifdef BARREL2_SUPPORT
  _u4BSID[u4InstID] = 1;
#else
  _u4BSID[u4InstID] = 0;
#endif


#if VDEC_DDR3_SUPPORT    
    _u2AddressSwapMode[u4InstID] = ADDRSWAP_DDR3;
#else
    _u2AddressSwapMode[u4InstID] = ADDRSWAP_OFF;
#endif

  fgInit = TRUE;
  _u4PowerTestInit[u4InstID] = 0;

  _tFileListInfo[u4InstID].i4FileId = 0xFFFFFFFF;
  while(fgVdecReadFileName(u4InstID, &_tFileListInfo[u4InstID], &_tFileListRecInfo[u4InstID], &_u4StartCompPicNum[u4InstID], &_u4EndCompPicNum[u4InstID], &_u4DumpRegPicNum[u4InstID]))
  {
     _u4SkipFrameCnt[u4InstID] = 0;
     _u4PicCnt[u4InstID] = 0;
     _u4FileCnt[u4InstID] = 0;
     if(fgExistVerifyLoop)
     {
       break;
     }

    if (fgInit == TRUE)
    {
        _u4StartCompPicNum[u4InstID] = 0;
        fgInit = FALSE;
    }

    #if VDEC_TEST_ADDSWAP
        _u2AddressSwapMode[u4InstID] = (UINT16) (((UINT32) rand())%8);
        while(_u2AddressSwapMode[u4InstID] == 3 || _u2AddressSwapMode[u4InstID] == 7)
        {
            _u2AddressSwapMode[u4InstID] = (UINT16) (((UINT32) rand())%8);
        }

        printk("[VDEC] Address Swap Mode = %d\n", _u2AddressSwapMode[u4InstID]);
    #endif

        #if VDEC_FIELD_COMPACT
        _u2AddressSwapMode[u4InstID] = 8;
        printk("[VDEC] Address Swap Mode = %d, Field Compact Enable\n", _u2AddressSwapMode[u4InstID]);
        #endif

     if (!fgVDecAllocWorkBuffer(u4InstID))
     {
         printk("[VDEC]Memory alloc failed\n");
         break;
     }

     #if ((CONFIG_CHIP_VER_CURR >= CONFIG_CHIP_VER_MT8560) && (!CONFIG_DRV_FPGA_BOARD))
 	vVDecSetVldMcClk(u4InstID,_u4CodecVer[u4InstID]);
     #endif

     #ifdef VDEC_VIDEOCODEC_RM
     fgOpen = fgVDecVerify_PrepareInfo_RM(u4InstID);

     if(fgOpen == FALSE)
     {
       continue;
     }
     #endif //VDEC_VIDEOCODEC_RM
   
#ifdef LETTERBOX_SUPPORT
     if(_u4CodecVer[u4InstID] == VDEC_H264)
     {
     VDEC_INFO_VERIFY_FILE_INFO_T tInFileInfo;
     
     tInFileInfo.fgGetFileInfo = TRUE;
     tInFileInfo.pucTargetAddr = (UCHAR*) _pucSettingFileSa[u4InstID];
     tInFileInfo.u4TargetSz = (UINT32) FILE_LIST_SZ;    
     tInFileInfo.u4FileLength = 0;    
     tInFileInfo.u4FileOffset = 0;
      sprintf(strMessage, "%s: ", _bFileStr1[u4InstID][12]);
      vVDecOutputDebugString(strMessage);
      printk("=====> Setting File Name = %s < ===== \n", strMessage);
      fgOpen = fgOpenFile(u4InstID, _bFileStr1[u4InstID][12],"r+b", &tInFileInfo);
      if(fgOpen == FALSE)
      {
       vVDecOutputDebugString("Open setting file fail\n");
       strcpy(_tFileListRecInfo[u4InstID].bFileName,_FileList_Rec[u4InstID]);
       sprintf(strMessage, "%s", "Open setting file fail\n");
       fgWrMsg2PC(strMessage,strlen(strMessage),8,&_tFileListRecInfo[u4InstID]);
       vVDecFreeWorkBuffer(u4InstID);
       continue;
      }
      _pcLBDSettingFile[u4InstID] = (char *)_pucSettingFileSa[u4InstID];

     tInFileInfo.fgGetFileInfo = TRUE;
     tInFileInfo.pucTargetAddr = (UCHAR*) _pucGoldenFileSa[u4InstID];
     tInFileInfo.u4TargetSz = (UINT32) FILE_LIST_SZ;    
     tInFileInfo.u4FileLength = 0;    
     tInFileInfo.u4FileOffset = 0;
      sprintf(strMessage, "%s: ", _bFileStr1[u4InstID][13]);
      vVDecOutputDebugString(strMessage);
      printk("=====> Golden File Name = %s < ===== \n", strMessage);
      fgOpen = fgOpenFile(u4InstID, _bFileStr1[u4InstID][13],"r+b", &tInFileInfo);
      if(fgOpen == FALSE)
      {
       vVDecOutputDebugString("Open golden file fail\n");
       strcpy(_tFileListRecInfo[u4InstID].bFileName,_FileList_Rec[u4InstID]);
       sprintf(strMessage, "%s", "Open golden file fail\n");
       fgWrMsg2PC(strMessage,strlen(strMessage),8,&_tFileListRecInfo[u4InstID]);
       vVDecFreeWorkBuffer(u4InstID);
       continue;
      }
      _pcLBDGoldenFile[u4InstID] = (char *)_pucGoldenFileSa[u4InstID];
      }
#endif
     
   
   #ifdef  RING_VFIFO_SUPPORT
      _u4LoadBitstreamCnt[u4InstID] = 0;
    #endif
     _tInFileInfo[u4InstID].fgGetFileInfo = TRUE;
     #ifdef RM_RINGVIFO_FLOW
     _tInFileInfo[u4InstID].pucTargetAddr = (UCHAR*) _pucRMRingWorkBuf[u4InstID];
     _tInFileInfo[u4InstID].u4TargetSz = (UINT32) RM_RINGFLOW_TEMPFIFO_SZ;    
     #else //RM_RINGVIFO_FLOW
     _tInFileInfo[u4InstID].pucTargetAddr = _pucVFifo[u4InstID];
     _tInFileInfo[u4InstID].u4TargetSz = V_FIFO_SZ;    
     #endif //RM_RINGVIFO_FLOW
     _tInFileInfo[u4InstID].u4FileLength = 0;    
     _tInFileInfo[u4InstID].u4FileOffset = 0;


      sprintf(strMessage, "%s: ", _bFileStr1[u4InstID][1]);
      vVDecOutputDebugString(strMessage);
      
      printk("=====> Test File Name = %s < ===== \n", strMessage);
      
      fgOpen = fgOpenFile(u4InstID, _bFileStr1[u4InstID][1],"r+b", &_tInFileInfo[u4InstID]);//Load bitstream
      //6589NEW (4) error concealment test only
      #ifdef MPEG4_6589_ERROR_CONCEAL
      _u4TotalBitstreamLen[u4InstID] = _tInFileInfo[u4InstID].u4FileLength;
      #endif
      if(_tInFileInfo[u4InstID].u4FileLength > V_FIFO_SZ)
       {
         printk("=====>The Vfifo size is not enough!. \n");
         printk("=====>The file's size is 0x%.8x bytes\n", _tInFileInfo[u4InstID].u4FileLength);
         //continue;
       }
     
   #ifdef  RING_VFIFO_SUPPORT
      _u4LoadBitstreamCnt[u4InstID]++;
    #endif

     if(fgOpen == FALSE)
     {
       vVDecOutputDebugString("Open bit-stream fail\n");
       strcpy(_tFileListRecInfo[u4InstID].bFileName,_FileList_Rec[u4InstID]);
       sprintf(strMessage, "%s", "Open bit-stream fail\n");
       fgWrMsg2PC(strMessage,strlen(strMessage),8,&_tFileListRecInfo[u4InstID]);
       //vVDecFreeWorkBuffer(u4InstID);
       continue;
     }
     else
     	{
     	  if((u4InstID == 1) && _ucMVCType[1]) 
     	  {    
     	    _fgMVCReady[0] = TRUE;    
     	    _fgMVCReady[1] = FALSE;	  
     	  }

     	}

        //Copy for Temp Buf to VFIFO
        #ifdef RM_RINGVIFO_FLOW
        {
          UINT32 u4VFifoWPtr = (UINT32) _pucVFifo[u4InstID];
          UINT32 u4VFIFOSa = (UINT32) _pucVFifo[u4InstID];
          UINT32 u4VFIFOSz = (UINT32) V_FIFO_SZ;
          UINT32 u4TempVFIFOSa = (UINT32) _pucRMRingWorkBuf[u4InstID];
          UINT32 u4CopySize = _tInFileInfo[u4InstID].u4FileLength;
          UINT32 u4RemSz = 0;

          #ifdef RM_ATSPEED_TEST_ENABLE
          _tVerMpvDecPrm[u4InstID].SpecDecPrm.rVDecRMDecPrm.u4RMFIFORPtr = (UINT32) _pucRMAULikeBuf[u4InstID];
          #else //RM_ATSPEED_TEST_ENABLE
          _tVerMpvDecPrm[u4InstID].SpecDecPrm.rVDecRMDecPrm.u4RMFIFORPtr = (UINT32) _pucVFifo[u4InstID];
          #endif //RM_ATSPEED_TEST_ENABLE

          if ((u4VFifoWPtr+_tInFileInfo[u4InstID].u4FileLength) < (UINT32) (u4VFIFOSa+u4VFIFOSz))
          {
            memcpy((void*)(u4VFifoWPtr), (void*)u4TempVFIFOSa, u4CopySize);
            _tVerMpvDecPrm[u4InstID].SpecDecPrm.rVDecRMDecPrm.u4RMVFIFOWPtr = u4VFIFOSa + u4CopySize;
          }
          else
          {
            u4CopySize = u4VFIFOSa+u4VFIFOSz - u4VFifoWPtr;
            u4RemSz = _tInFileInfo[u4InstID].u4FileLength - u4CopySize;
            memcpy((void*)(u4VFifoWPtr), (void*)u4TempVFIFOSa, u4CopySize);

            memcpy((void*)(u4VFIFOSa), (void*)(u4TempVFIFOSa+u4CopySize), u4RemSz);

            _tVerMpvDecPrm[u4InstID].SpecDecPrm.rVDecRMDecPrm.u4RMVFIFOWPtr = u4VFIFOSa + u4RemSz;
          }
        }
        #endif //RM_RINGVIFO_FLOW

      
     if((_u4CodecVer[u4InstID] == VDEC_H264) ||(_u4CodecVer[u4InstID] == VDEC_MPEG4))
     {
       vAddStartCode2Dram(_pucVFifo[u4InstID]+_tInFileInfo[u4InstID].u4FileLength);
     }
     
      #if VDEC_CACHE_PROC // update physical memory
      {      
      if(_u4CodecVer[u4InstID] == VDEC_H264)
      {
        u4FifoDataSize = _tInFileInfo[u4InstID].u4FileLength + 4;
      }
      else
      {
        u4FifoDataSize = _tInFileInfo[u4InstID].u4FileLength;
      }    

      printk("vVDecVerifyThread, update cache to physical mem, addr:0x%x, size:0x%x\n", 
        _pucVFifo[u4InstID], u4FifoDataSize);

      // tmp:
      //u4FifoDataSize = V_FIFO_SZ;

      u4MappedVFifoSa = dma_map_single(NULL, (UINT32)(_pucVFifo[u4InstID]), u4FifoDataSize, DMA_TO_DEVICE);  
      }
      #endif

     strcpy(_tFileListRecInfo[u4InstID].bFileName,_FileList_Rec[u4InstID]);
     sprintf(strMessage,"The bitstream file length / real returns is %d/%d (0x%.8x/0x%.8x)\n",
      _tInFileInfo[u4InstID].u4FileLength, _tInFileInfo[u4InstID].u4RealGetBytes,_tInFileInfo[u4InstID].u4FileLength, _tInFileInfo[u4InstID].u4RealGetBytes);
     fgWrMsg2PC(strMessage,strlen(strMessage),8,&_tFileListRecInfo[u4InstID]);

     u4BitStreamLengthH264 = _tInFileInfo[u4InstID].u4RealGetBytes;
        
     if (_u4CodecVer[u4InstID] == VDEC_VP6)
     {
         _rSizeFileInfo.fgGetFileInfo = TRUE;  
         _rSizeFileInfo.pucTargetAddr = _pucSizeFileBuf[u4InstID];
         _rSizeFileInfo.u4TargetSz = 1024*400;;  
         _rSizeFileInfo.u4FileLength = 0;
         sprintf(strVP6SizeFile, "%s.size", _bFileStr1[u4InstID][1]);
         fgOpenFile(u4InstID, strVP6SizeFile,"r+b", &_rSizeFileInfo);

         if(fgOpen == FALSE)
         {
             sprintf(strMessage, "%s", "Open VP6 size fail\n");
             fgWrMsg2PC(strMessage,strlen(strMessage),8,&_tFileListRecInfo[u4InstID]);
             continue;
        }

        if (0 == _u1AlphaBitstream[u4InstID])
        {
            //_fgVP6CRCExist[u4InstID] = fgVP6CRCPatternExist(u4InstID);
            _fgVP6CRCExist[u4InstID] = 0;
        }
        else
        {
            _fgVP6CRCExist[u4InstID] = 0;
            _u4AdobeMode[u4InstID] = 0;
        }
        _fgVP6SmallFlolder[u4InstID] = fgVP6SmallFolder(u4InstID);

        printk("<vdec> _fgVP6CRCExist[%u]=%d, _fgVP6SmallFlolder[%u]=%d\n", u4InstID, _fgVP6CRCExist[u4InstID], u4InstID, _fgVP6SmallFlolder[u4InstID]);
     }        

     // main decoding loop
#if VDEC_VP8_WEBP_SUPPORT_ME2_INTEGRATION
     break;
#else
     vMpvPlay(u4InstID);
#endif
     
    #if VDEC_CACHE_PROC
    printk("vVDecVerifyThread, unmap physical mem, addr:0x%x, size:0x%x\n", 
     _pucVFifo[u4InstID], u4FifoDataSize);

    dma_unmap_single(NULL, u4MappedVFifoSa, u4FifoDataSize, DMA_TO_DEVICE); 
    #endif

    _u4StartCompPicNum[u4InstID] = 0;

     //vVDecFreeWorkBuffer(u4InstID);
  }

#if VDEC_VP8_WEBP_SUPPORT_ME2_INTEGRATION
#else
  #ifdef PCFILE_WRITE  
  if(_tInFileInfo[u4InstID].pFile)
  {
    fclose(_tInFileInfo[u4InstID].pFile);
  }
  #endif
  vVerifyVDecIsrStop(u4InstID);

  vMemoryFree(u4InstID);

if(-1 != gfpH264log){
 if(gH264logbufferOffset > 0 ){ 
    vdecwriteFile(gfpH264log, gpfH264LogFileBuffer, gH264logbufferOffset);
 }
 vdeccloseFile(gfpH264log);
 printk("close H264 log file\n");
}


#ifdef SATA_HDD_READ_SUPPORT
   #ifdef  SATA_HDD_FS_SUPPORT
      if (_tFileListInfo[u4InstID].i4FileId != 0xFFFFFFFF)
      {
         // fgHDDFsCloseFile(u4InstID); // temp avoid system crash
         _tFileListInfo[u4InstID].i4FileId = 0xFFFFFFFF;
      }
      //FS mount
    fgHDDFsUnMount(0);
   #endif
#endif

#endif
}
Example #3
0
File: vdec.c Project: SelfImp/m75
static int uvvp_vdec_ioctl(struct file *file,
							unsigned int cmd, unsigned long arg)
{
int ret=0;
    int i, j;
    //int recv_buf[256];
    //int send_buf[256];
    //int num = 0;
    
    // For UVVP_VDEC_TEST_VERSION_1
    int reg_in = 0;
    int reg_out = 0;

    // For UVVP_VDEC_TEST_VERSION_2
    int mem_sz = 1;
    UCHAR *p = NULL;
    unsigned int u4Align = 1024;
    unsigned int u4Size = 16384;
    unsigned char *buf_data;
    unsigned char *buf_data2;
    UINT32 u4RetValue;

    // For UVVP_VDEC_TEST_VERSION_3
    struct termios settings; 
    struct file *fd = 0;
    mm_segment_t oldfs;
    unsigned long crc = 0;
    unsigned long own_crc = 0;
    int frame_start = 0;
    int frame_end= 0;
    int file_num = 0;
    int file_len = 0;
    int read_len = 0;
    int tmp_buf[256];

    // For speed measurement
    struct timeval tv1;
    struct timeval tv2;

//struct file * pfilename;
  VDEC_PARAM_T *param;
#if (VDEC_MVC_SUPPORT)
  VDEC_PARAM_T *param1;
#endif
printk("\r\n******** uvvp_vdec_ioctl cmd[%d]********\r\n",cmd);
param = kmalloc(sizeof(VDEC_PARAM_T), GFP_KERNEL);
#if (VDEC_MVC_SUPPORT)
  param1 = kmalloc(sizeof(VDEC_PARAM_T), GFP_KERNEL); 
#endif

	switch (cmd) {
		//  General TEST CASE
		case UVVP_VDEC_TEST_VERSION:
			param->u4InstanceId = 0;
			param->u4Mode = 0;
                        #if (VDEC_MVC_SUPPORT)
                        param->fgMVCType = TRUE;
                        #else
                        param->fgMVCType = FALSE;
                        #endif
			printk("\r\n******** uvvp_vdec_ioctl UVVP_VDEC_TEST_VERSION ********\r\n");	
#if VDEC_VP8_WEBP_SUPPORT_ME2_INTEGRATION
            vVDecVerifyThread(param);
            vVerInitVDec(0);
            vVParserProc(0);
            vVDecProc(0);
#if VP8_MB_ROW_MODE_SUPPORT_ME2_INTEGRATION
            while(1)
            {
                u4RetValue = vVerVP8DecEndProc_MB_ROW_START(0);
                if (u4RetValue == vVerResult_MB_ROW_DONE)
                {
                    printk("\n\n======== MB ROW DONE!! ========\n\n");
                }
                else if(u4RetValue == vVerResult_FRAME_DONE)
                {
                    printk("\n\n======== FRAME DONE!! ========\n\n");
                    break;
                }
                else
                {
                    printk("\n\n[ERROR]======== decode timeout!! ========\n\n");
                    break;
                }
            }
            vChkVDec_Webp_Row_Mode(0);
#else            
            vChkVDec(0);
#endif
#ifdef PCFILE_WRITE  
            if(_tInFileInfo[param->u4InstanceId].pFile)
            {
              fclose(_tInFileInfo[param->u4InstanceId].pFile);
            }
#endif
            vVerifyVDecIsrStop(param->u4InstanceId);
            vMemoryFree(param->u4InstanceId);
#ifdef SATA_HDD_READ_SUPPORT
#ifdef SATA_HDD_FS_SUPPORT
            if (_tFileListInfo[param->u4InstanceId].i4FileId != 0xFFFFFFFF)
            {
                // fgHDDFsCloseFile(u4InstID); // temp avoid system crash
                _tFileListInfo[param->u4InstanceId].i4FileId = 0xFFFFFFFF;
            }
            //FS mount
            fgHDDFsUnMount(0);
#endif
#endif
#else
			MPV_thread = kthread_run(vVDecVerifyThread, param, "rt8192cu_rtw_xmit_thread");
			if (IS_ERR(MPV_thread)) { 
				printk("[%s]: failed to create MPV thread\n", __FUNCTION__);
				return 0;	
				}
                        else
                        {
                            printk("Creat mpv0 thread ok!\n");
                        }  
//			break;					
//		case UVVP_VDEC_TEST_VERSION_1:
                        #if (VDEC_MVC_SUPPORT)
			param1->u4InstanceId = 1;
			param1->u4Mode = 0;
                        param1->fgMVCType = TRUE;
                        msleep(2);
			MPV_thread = kthread_run(vVDecVerifyThread, param1, "rt8192cu_rtw_xmit_thread");
			if (IS_ERR(MPV_thread)) { 
				printk("[%s]: failed to create MPV thread\n", __FUNCTION__);
				return 0;	
				}
                        else
                        {
                            printk("Creat mpv1 thread ok!\n");
                        }
                        #endif
#endif                        
			break;
        case UVVP_VDEC_TEST_VERSION_1:
            printk("UVVP_VDEC_TEST_VERSION_1\n");

            reg_in = 0x1;
            reg_out = 0;
            MFV_HW_WRITE(VDEC_GCON_BASE, reg_in);
            reg_out = MFV_HW_READ(VDEC_GCON_BASE);
            printk("GCON write 0x%x, read 0x%x, %s\n", reg_in, reg_out, reg_in == reg_out ? "Pass":"******");
            
            reg_in = 0xFFFFFFFF;
            reg_out = 0;
            MFV_HW_WRITE((VDEC_BASE + MC_BASE_OFFSET + OFFSET_R1Y_ADD), reg_in);
            reg_out = MFV_HW_READ((VDEC_BASE + MC_BASE_OFFSET + OFFSET_R1Y_ADD));
            printk("OFFSET_R1Y_ADD write 0x%x, read 0x%x, mask 0x%x, %s\n", reg_in, reg_out, Y_MASK, (reg_in & Y_MASK) == reg_out ? "Pass":"******");
            
            reg_in = 0xFFFFFFFF;
            reg_out = 0;
            MFV_HW_WRITE((VDEC_BASE + MC_BASE_OFFSET + OFFSET_R1C_ADD), reg_in);
            reg_out = MFV_HW_READ((VDEC_BASE + MC_BASE_OFFSET + OFFSET_R1C_ADD));
            printk("OFFSET_R1C_ADD write 0x%x, read 0x%x, mask 0x%x, %s\n", reg_in, reg_out, C_MASK, (reg_in & C_MASK) == reg_out ? "Pass":"******");
            
            reg_in = 0xFFFFFFFF;
            reg_out = 0;
            MFV_HW_WRITE((VDEC_BASE + MC_BASE_OFFSET + OFFSET_R2Y_ADD), reg_in);
            reg_out = MFV_HW_READ((VDEC_BASE + MC_BASE_OFFSET + OFFSET_R2Y_ADD));
            printk("OFFSET_R2Y_ADD write 0x%x, read 0x%x, mask 0x%x, %s\n", reg_in, reg_out, Y_MASK, (reg_in & Y_MASK) == reg_out ? "Pass":"******");

            reg_in = 0xFFFFFFFF;
            reg_out = 0;
            MFV_HW_WRITE((VDEC_BASE + MC_BASE_OFFSET + OFFSET_R2C_ADD), reg_in);
            reg_out = MFV_HW_READ((VDEC_BASE + MC_BASE_OFFSET + OFFSET_R2C_ADD));
            printk("OFFSET_R2C_ADD write 0x%x, read 0x%x, mask 0x%x, %s\n", reg_in, reg_out, C_MASK, (reg_in & C_MASK) == reg_out ? "Pass":"******");

            break;
		case UVVP_VDEC_TEST_VERSION_2:
		    printk("UVVP_VDEC_TEST_VERSION_2\n");

            printk("=== vmalloc memory speed test ===\n");
            
            do_gettimeofday(&tv1);
            buf_data = (unsigned char *)vmalloc(TESTDATA_BUFFER_SZ);
            buf_data2 = (unsigned char *)vmalloc(TESTDATA_BUFFER_SZ); 
            do_gettimeofday(&tv2);
            calc_time_diff(&tv1, &tv2);
            printk("Allocated %d + %dMB in %d sec %d usec\n", TESTDATA_BUFFER_SZ/1024/1024, TESTDATA_BUFFER_SZ/1024/1024, tv2.tv_sec, tv2.tv_usec);

            do_gettimeofday(&tv1);
            memset(buf_data, 0, TESTDATA_BUFFER_SZ);
            memset(buf_data2, 1, TESTDATA_BUFFER_SZ);
            do_gettimeofday(&tv2);
            calc_time_diff(&tv1, &tv2);
            printk("memset %d + %dMB in %d sec %d usec\n", TESTDATA_BUFFER_SZ/1024/1024, TESTDATA_BUFFER_SZ/1024/1024, tv2.tv_sec, tv2.tv_usec);

            do_gettimeofday(&tv1);
            memcpy(buf_data, buf_data2, TESTDATA_BUFFER_SZ);
            do_gettimeofday(&tv2);
            calc_time_diff(&tv1, &tv2);
            printk("memcpy %dMB in %d sec %d usec\n", TESTDATA_BUFFER_SZ/1024/1024, tv2.tv_sec, tv2.tv_usec);

            vfree(buf_data);
            vfree(buf_data2);

            printk("=== ioremap_nocache memory speed test ===\n");
            do_gettimeofday(&tv1);
            buf_data = g_pu1AllocSA;
            buf_data2 = g_pu1AllocSA + TESTDATA_BUFFER_SZ;
            buf_data = ioremap_nocache(buf_data, TESTDATA_BUFFER_SZ);
            buf_data2 = ioremap_nocache(buf_data2, TESTDATA_BUFFER_SZ);
            do_gettimeofday(&tv2);
            calc_time_diff(&tv1, &tv2);
            printk("ioremap %d + %dMB in %d sec %d usec\n", TESTDATA_BUFFER_SZ/1024/1024, TESTDATA_BUFFER_SZ/1024/1024, tv2.tv_sec, tv2.tv_usec);

            do_gettimeofday(&tv1);
            memset(buf_data, 0, TESTDATA_BUFFER_SZ);
            memset(buf_data2, 1, TESTDATA_BUFFER_SZ);
            do_gettimeofday(&tv2);
            calc_time_diff(&tv1, &tv2);
            printk("memset %d + %dMB in %d sec %d usec\n", TESTDATA_BUFFER_SZ/1024/1024, TESTDATA_BUFFER_SZ/1024/1024, tv2.tv_sec, tv2.tv_usec);

            do_gettimeofday(&tv1);
            memcpy(buf_data, buf_data2, TESTDATA_BUFFER_SZ);
            do_gettimeofday(&tv2);
            calc_time_diff(&tv1, &tv2);
            printk("memcpy %dMB in %d sec %d usec\n", TESTDATA_BUFFER_SZ/1024/1024, tv2.tv_sec, tv2.tv_usec);
            
            iounmap(buf_data);
            iounmap(buf_data2);            

            printk("=== ioremap write test ===\n");
            p = g_pu1AllocSA;
            p = ((UINT32)p + u4Align-1) & (~(u4Align - 1));
            printk("p physical addr 0x%x\n", p);
            p = ioremap_nocache(p, u4Size);
            printk("p virtual addr 0x%x\n", p);
            *p = 'S';
            *(p+u4Size-1) = 'E';
            printk("p %c %c\n", *p, *(p+u4Size-1));
            
            iounmap(p);
            
/*

            while (1)
            {
                buf_data = (unsigned char *)vmalloc(mem_sz*1024*1024);
                if (buf_data != NULL)
                {
                    vfree(buf_data);
                    mem_sz = mem_sz + 1;
                    printk("Memory size %dMB allocated!\n", mem_sz);
                }
                else
                {
                    printk("Memory size %dMB failed to allocate\n", mem_sz);
                    break;
                }
            }
*/
            break;
        case UVVP_VDEC_TEST_VERSION_3:
            printk("UVVP_VDEC_TEST_VERSION_3\n");

            buf_data = (unsigned char *)vmalloc(TESTDATA_BUFFER_SZ);
            if (0 == buf_data)
            {
                printk("Allocate %d bytes failed\n", TESTDATA_BUFFER_SZ);
                return 0;
            }

            oldfs = get_fs();
            set_fs(KERNEL_DS); 
#ifdef USB_ACM_DMA1
            printk("UVVP_VDEC_TEST_VERSION_3 Open /dev/usbacm\n");
            fd = filp_open("/dev/usbacm", O_RDWR|O_NOCTTY|O_NDELAY, 0);
            if (fd == 0) 
            {   printk("Open /dev/usbacm failed\n");
                return 0;
            }
#else
            printk("UVVP_VDEC_TEST_VERSION_3 Open /dev/ttyGS0\n");
            fd = filp_open("/dev/ttyGS0", O_RDWR, 0);
            if (fd == 0) 
            {   printk("Open /dev/ttyGS0 failed\n");
                return 0;
            }
            
            fd->f_op->unlocked_ioctl(fd, TCGETS, (unsigned long)&settings);
        
            settings.c_cflag &= ~CBAUD;
            settings.c_cflag |= B921600;

            settings.c_cflag &= ~PARENB;
            settings.c_cflag &= ~CSTOPB;
            settings.c_cflag &= ~CSIZE;
            settings.c_cflag |= CS8 | CLOCAL | CREAD;
            
            settings.c_iflag &= ~(INLCR | ICRNL | IXON | IXOFF | IXANY);
            settings.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);  /*raw input*/
            settings.c_oflag &= ~OPOST;  /*raw output*/

            settings.c_cc[VMIN] = 0;
            settings.c_cc[VTIME] = 100;
            
            fd->f_op->unlocked_ioctl(fd, TCSETS, (unsigned long)&settings); 
#endif
            // Read CRC
            printk("Read CRC file\n");
            file_num = remote_open(fd, "Z:\\1280x720_30_2000.ivf.crc", 27, "rb", 2);
            if (file_num < 0)
            {
                printk("Open CRC failed\n");
                return 0;
            }
            file_len = remote_seek(fd, file_num, 0, SEEK_END);
            if (file_len < 0 || file_len > TESTDATA_BUFFER_SZ)
            {
                printk("CRC file too big %d\n", file_len);
                return 0;
            }
            remote_seek(fd, file_num, 0, SEEK_SET);
            read_len = remote_read(fd, file_num, &crc, sizeof(int));
            if (read_len < file_len)
            {
                printk("Fail to read CRC file\n");
                return 0;
            }
            remote_close(fd, file_num);

            // Read real file
            printk("Read Data file\n");
            file_num = remote_open(fd, "Z:\\1280x720_30_2000.ivf", 23, "rb", 2);
            if (file_num < 0)
            {
                printk("Open data file failed\n");
                return 0;
            }
            
            file_len = remote_seek(fd, file_num, 0, SEEK_END);
            if (file_len < 0 || file_len > TESTDATA_BUFFER_SZ)
            {
                printk("Data file too big %d\n", file_len);
                return 0;
            }            
            remote_seek(fd, file_num, 0, SEEK_SET);
            memset(&tv1, 0, sizeof(struct timeval));
            memset(&tv2, 0, sizeof(struct timeval));
            printk("Start reading data\n");
            do_gettimeofday(&tv1);
            read_len = remote_read(fd, file_num, buf_data, file_len);
            do_gettimeofday(&tv2);
            printk("End reading data\n");  
            printk("tv1 %d.%d, tv2 %d.%d \n", tv1.tv_sec, tv1.tv_usec, tv2.tv_sec, tv2.tv_usec);
            tv2.tv_sec -= tv1.tv_sec;
            if (tv2.tv_usec < tv1.tv_usec)
            {
                if (tv2.tv_sec < 1)
                    printk("TIME ERROR\n");
                tv2.tv_usec = tv2.tv_usec + 1000000 - tv1.tv_usec;
                tv2.tv_sec -= 1;
            }
            else
            {
                tv2.tv_usec -= tv1.tv_usec;
            }
            printk("Data len %d, elapsed time %d ms, avg speed %d bytes/ms\n", read_len, (tv2.tv_sec * 1000000 + tv2.tv_usec)/1000, read_len/((tv2.tv_sec * 1000000 + tv2.tv_usec)/1000));
            
            if (read_len < file_len)
            {
                printk("Fail read data file exp. %d, read %d\n", file_len, read_len);
                return 0;
            }
            remote_close(fd, file_num);

            // CRC check
            own_crc = av_adler32_update(1, buf_data, 1, read_len);
            printk("own_crc 0x%08x, crc 0x%08x, %s\n", own_crc, crc, (own_crc == crc) ? "Pass":"******");

            // Write file
            file_num = remote_open(fd, "D:\\Test.txt", 11, "wb", 2);
            if (file_num < 0)
            {
                printk("Open data file failed\n");
                return 0;
            }

            for (i = 0; i < 256; i++)
            {
                tmp_buf[i] = i;
            }
            
            for (i = 0; i < 1024; i++)
            {
                memcpy(buf_data+(1024*i), (unsigned char *)&tmp_buf[0], 1024);
            }

            remote_write(fd, file_num, buf_data, 1024*1024);
            
            remote_close(fd, file_num);            

            filp_close(fd, NULL);
            
            vfree(buf_data);        

	/*
	    _pucVFifo[0] = ioremap(0x8000000, 0x100000);
           memset(_pucVFifo[0] ,5,0x100000);
           printk("_pucVFifo = 0x%x\n", _pucVFifo[0]);
           printk("_pucVFifo m4u_v2p = 0x%x\n", m4u_v2p_new((unsigned int)_pucVFifo[0]));
           iounmap(_pucVFifo[0]);
	    _pucVFifo[0] = ioremap(0x8000000, 0x100000);
           memset(_pucVFifo[0] ,5,0x100000);
           printk("_pucVFifo = 0x%x\n", _pucVFifo[0]);
           printk("_pucVFifo m4u_v2p = 0x%x\n", m4u_v2p_new((unsigned int)_pucVFifo[0]));
           iounmap(_pucVFifo[0]);
	    _pucVFifo[0] = ioremap(0x8000000, 0x100000);
           memset(_pucVFifo[0] ,5,0x100000);
           printk("_pucVFifo = 0x%x\n", _pucVFifo[0]);
           printk("_pucVFifo m4u_v2p = 0x%x\n", m4u_v2p_new((unsigned int)_pucVFifo[0]));
           iounmap(_pucVFifo[0]);
*/
			break;
		case UVVP_VDEC_TEST_VERSION_4:

                  initKernelEnv(); 

                  fd = openFile("/etc/frame_num",O_RDONLY,0); 
                  if (IS_ERR(fd) )
                      printk("[Error] Miss file: input arg file!!!!!!!!!!!!!\n");
                  else
                      readFile(fd ,tmp_buf, 256 );
                  closeFile(fd); 
                  set_fs( oldfs );

                  sscanf ( tmp_buf, "%i %i %i %i %i %s %i %i" , &frame_start, &frame_end, &width, &height, &debug_mode, bitstream_name, &error_rate, &UFO_MODE);

		    hevc_test( frame_start,  frame_end);
		    break;
            
		default:
		    break;

	}
	//printk("\r\n******** uvvp_vdec_ioctl done********\r\n");
	return 0;	
}