Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

805 lines
19 KiB

  1. /******************************************************************************\
  2. * *
  3. * ZIVAWDM.C - ZiVA hardware control API. *
  4. * *
  5. * Copyright (c) C-Cube Microsystems 1996 *
  6. * All Rights Reserved. *
  7. * *
  8. * Use of C-Cube Microsystems code is governed by terms and conditions *
  9. * stated in the accompanying licensing statement. *
  10. * *
  11. \******************************************************************************/
  12. #include "Headers.h"
  13. #pragma hdrstop
  14. #include "boardio.h"
  15. #include "cl6100.h"
  16. #include "tc6807af.h"
  17. #include "fpga.h"
  18. #include "audiodac.h"
  19. #if defined(DECODER_DVDPC)
  20. #include "lukecfg.h"
  21. #include "mvis.h"
  22. #include "dataxfer.h"
  23. #elif defined(ENCORE) || defined(OVATION)
  24. #include "bmaster.h"
  25. #elif defined(EZDVD)
  26. #include "Hostcfg.h"
  27. #include "dataxfer.h"
  28. #include "mvis.h"
  29. #endif
  30. #if defined(ENCORE)
  31. #include "mvstub.h"
  32. #endif
  33. #if defined (LOAD_UCODE_FROM_FILE)
  34. #include "RegistryApi.h"
  35. unsigned char UcodeBuff[150 * 1024]; // Ucode for for loading from file. // test
  36. #else
  37. #if defined(DECODER_DVDPC)
  38. #include "cobra_ux.h"
  39. #else//if defined(ENCORE) || defined(OVATION)
  40. #include "dvd1_ux.h"
  41. //#elif defined(EZDVD)
  42. //#include "ezdvd_ux.h"
  43. #endif
  44. #endif //LOAD_UCODE_FROM_FILE
  45. //*******************************************************************
  46. // Local Types Declaration
  47. //*******************************************************************
  48. typedef enum _PLAY_STATE_COMMAND {
  49. CMD_PLAY = 0,
  50. CMD_PAUSE,
  51. CMD_STOP,
  52. CMD_SCAN,
  53. CMD_STEP,
  54. CMD_SLOWMOTION,
  55. CMD_NONE
  56. } PLAY_STATE_COMMAND;
  57. //*******************************************************************
  58. // Global Variables Declaration
  59. //*******************************************************************
  60. PLAY_STATE_COMMAND gLastCommand = CMD_STOP;
  61. BOOL bPlaybackJustStarted = FALSE;
  62. #if defined (LOAD_UCODE_FROM_FILE)
  63. BOOL
  64. ZivaHW_LoadUCodeFromFile( // Load the microcode based on the microcode Id specified.
  65. PHW_DEVICE_EXTENSION pHwDevExt); // is pHwDevExt
  66. #endif
  67. //
  68. // ZivaHW_Initialize
  69. //
  70. ///////////////////////////////////////////////////////////////////////////////
  71. BOOL _stdcall ZivaHw_Initialize( PHW_DEVICE_EXTENSION pHwDevExt )
  72. {
  73. #if defined(DECODER_DVDPC)
  74. DWORD dwDVDAMCCBaseAddress,dwDVDIrq;
  75. #endif
  76. MonoOutInit();
  77. #if defined(DECODER_DVDPC)
  78. if (!InitLukeCfg(&dwDVDAMCCBaseAddress, &dwDVDIrq))
  79. return FALSE;
  80. InitMvis(pHwDevExt -> dwDVDAMCCBaseAddress);
  81. TV_SetEncoderType(1);
  82. if (!DataTransfer_Init( pHwDevExt -> dwDVDAMCCBaseAddress,dwDVDIrq))
  83. {
  84. MonoOutStr( " Cannot Initialize the AMCC for Bus Mastering " );
  85. return FALSE;
  86. }
  87. #elif defined(ENCORE)
  88. // Initialize Bus Master first
  89. if ( !BMA_Init( pHwDevExt -> dwDVDAMCCBaseAddress, pHwDevExt->bIsVxp524 ) )
  90. {
  91. MonoOutStr( " Cannot Initialize the AMCC for Bus Mastering " );
  92. return FALSE;
  93. }
  94. if ( !FPGA_Init( pHwDevExt -> dwDVDFPGABaseAddress ) )
  95. {
  96. MonoOutStr( " Cannot Initialize the FPGA " );
  97. return FALSE;
  98. }
  99. #elif defined(OVATION)
  100. // Initialize FPGA
  101. if ( !FPGA_Init( pHwDevExt -> dwDVDFPGABaseAddress ) )
  102. {
  103. MonoOutStr( " Cannot Initialize the FPGA " );
  104. return FALSE;
  105. }
  106. // Initialize Bus Master
  107. if ( !BMA_Init( pHwDevExt -> dwDVDAMCCBaseAddress ) )
  108. {
  109. MonoOutStr( " Cannot Initialize the AMCC for Bus Mastering " );
  110. return FALSE;
  111. }
  112. #elif defined(EZDVD)
  113. if (!InitHost(&(pHwDevExt -> dwDVDFPGABaseAddress), NULL))
  114. return FALSE;
  115. BRD_Init(pHwDevExt -> dwDVDAMCCBaseAddress, 0);
  116. InitMvis(0);//parameter ignored
  117. #endif
  118. // Initialize DVD1 chip
  119. if ( !DVD_Initialize( pHwDevExt -> dwDVDHostBaseAddress, pHwDevExt -> dwDVDCFifoBaseAddress ) )
  120. {
  121. MonoOutStr( " Cannot Initialize the DVD1 chip (Board not found at specified address: " );
  122. MonoOutULongHex( pHwDevExt -> dwDVDHostBaseAddress );
  123. MonoOutStr( ") " );
  124. return FALSE;
  125. }
  126. if ( ( DVD_GetHWVersion() == DVD_HW_VERSION_1_0 ) )
  127. {
  128. #ifdef OVATION
  129. if ( !TC6807AF_Initialize( pHwDevExt -> dwDVD6807BaseAddress ) )
  130. {
  131. MonoOutStr( " Cannot Initialize the TC6807AF chip at specified address: " );
  132. MonoOutULongHex( pHwDevExt -> dwDVD6807BaseAddress );
  133. MonoOutStr( ") " );
  134. return FALSE;
  135. }
  136. #endif
  137. }
  138. //
  139. // Disable ZiVA's host interrupt
  140. //
  141. BRD_CloseDecoderInterruptPass();
  142. //
  143. // Load Decoder's firmware
  144. //
  145. #if defined (LOAD_UCODE_FROM_FILE)
  146. if ( !ZivaHW_LoadUCodeFromFile(pHwDevExt) )
  147. {
  148. MonoOutStr(" !!! Ucode Load from file failed. !!!");
  149. return FALSE;
  150. }
  151. #else
  152. if ( !ZivaHW_LoadUCode( ) )
  153. return FALSE;
  154. #endif
  155. #if defined( OVATION )
  156. ADAC_Init( pHwDevExt -> dwDVDFPGABaseAddress );
  157. #elif (DECODER_DVDPC)
  158. ADAC_Init( pHwDevExt -> dwDVDAMCCBaseAddress );
  159. #else
  160. ADAC_Init( (pHwDevExt -> dwDVD6807BaseAddress) - 2 );
  161. #endif // OVATION
  162. // Set default sampling frequency to 48 KHz (AC-3 audio)
  163. ADAC_SetSamplingFrequency( ADAC_SAMPLING_FREQ_48 );
  164. #if 0
  165. // Set interrupt mask for events that we are going to use
  166. if ( !DVD_IntEnable( CL6100_INT_MASK_UND|CL6100_INT_MASK_ERR ) )
  167. return FALSE;
  168. #endif
  169. #if 0
  170. DebugPrint((DebugLevelVerbose,"\nCF_intrpt: %lX", DVD_ReadReg( 0x1c ) ));
  171. DebugPrint((DebugLevelVerbose," CF_count: %lX", DVD_ReadReg( 0x1d ) ));
  172. DebugPrint((DebugLevelVerbose," CF_command: %lX", DVD_ReadReg( 0x1f ) ));
  173. DebugPrint((DebugLevelVerbose," Host_contrl: %lX", DVD_ReadReg( 0 ) ));
  174. DebugPrint((DebugLevelVerbose,"\nDRAM_SUBP_FIFO_ST: %lX", DVD_ReadDRAM( 0x1722*4 ) ));
  175. DebugPrint((DebugLevelVerbose," RD_PTR: %lX", DVD_ReadDRAM( 0x1721*4 ) ));
  176. DebugPrint((DebugLevelVerbose," WR_PTR: %lX", DVD_ReadDRAM( 0x1720*4 ) ));
  177. #endif
  178. return TRUE;
  179. }
  180. //
  181. // CL6100SD_LoadUCode
  182. //
  183. ///////////////////////////////////////////////////////////////////////////////
  184. #if defined (LOAD_UCODE_FROM_FILE)
  185. BOOL LoadUcode(BYTE * pbtUcode)
  186. {
  187. // White sub picture palettes.
  188. DWORD dwPalletes[16] = { 0x00b08080,
  189. 0x00b08080,
  190. 0x00b08080,
  191. 0x00b08080,
  192. 0x00b08080,
  193. 0x00b08080,
  194. 0x00b08080,
  195. 0x00b08080,
  196. 0x00b08080,
  197. 0x00b08080,
  198. 0x00b08080,
  199. 0x00b08080,
  200. 0x00b08080,
  201. 0x00b08080,
  202. 0x00b08080,
  203. 0x00b08080 };
  204. #if defined(DECODER_DVDPC) || defined(EZDVD)
  205. DataTransfer_Reset();
  206. #else
  207. BMA_Reset();
  208. FPGA_Clear( FPGA_SECTOR_START );
  209. #endif
  210. if ( !DVD_LoadUCode( pbtUcode) )
  211. return FALSE;
  212. // Initialize sub picture palettes to white
  213. DVD_SetPalette( dwPalletes );
  214. return TRUE;
  215. }
  216. #else
  217. BOOL _stdcall ZivaHW_LoadUCode( )
  218. {
  219. // White sub picture palettes.
  220. DWORD dwPalletes[16] = { 0x00b08080,
  221. 0x00b08080,
  222. 0x00b08080,
  223. 0x00b08080,
  224. 0x00b08080,
  225. 0x00b08080,
  226. 0x00b08080,
  227. 0x00b08080,
  228. 0x00b08080,
  229. 0x00b08080,
  230. 0x00b08080,
  231. 0x00b08080,
  232. 0x00b08080,
  233. 0x00b08080,
  234. 0x00b08080,
  235. 0x00b08080 };
  236. #if defined(DECODER_DVDPC) || defined(EZDVD)
  237. DataTransfer_Reset();
  238. #else
  239. BMA_Reset();
  240. FPGA_Clear( FPGA_SECTOR_START );
  241. #endif
  242. if ( !DVD_LoadUCode( (BYTE *)(Microcode_Ptr_List[0].Microcode_Seg_Add) ) )
  243. return FALSE;
  244. // Initialize sub picture palettes to white
  245. DVD_SetPalette( dwPalletes );
  246. return TRUE;
  247. }
  248. #endif
  249. //
  250. // ZivaHw_Play
  251. //
  252. ///////////////////////////////////////////////////////////////////////////////
  253. BOOL _stdcall ZivaHw_Play( )
  254. {
  255. BOOL bStatus = FALSE;
  256. // Set interrupt mask for events that we are going to use
  257. //#ifndef EZDVD
  258. #ifdef DEBUG
  259. DVD_IntEnable( CL6100_INT_MASK_VSYNC|CL6100_INT_MASK_UND|CL6100_INT_MASK_ERR
  260. |CL6100_INT_MASK_USR ); //sri
  261. #else
  262. DVD_IntEnable( CL6100_INT_MASK_VSYNC|CL6100_INT_MASK_USR );
  263. #endif
  264. //#endif
  265. if (gLastCommand == CMD_PAUSE ||
  266. gLastCommand == CMD_SCAN ||
  267. gLastCommand == CMD_SLOWMOTION )
  268. {
  269. gLastCommand = CMD_PLAY;
  270. bStatus = DVD_Resume( );
  271. // bStatus = DVD_Play( );
  272. }
  273. else if ( gLastCommand != CMD_PLAY )
  274. {
  275. bPlaybackJustStarted = TRUE;
  276. gLastCommand = CMD_PLAY;
  277. bStatus = DVD_Play( );
  278. }
  279. else
  280. bStatus = TRUE;
  281. return bStatus;
  282. }
  283. //
  284. // ZivaHw_Scan
  285. //
  286. ///////////////////////////////////////////////////////////////////////////////
  287. BOOL _stdcall ZivaHw_Scan( )
  288. {
  289. BOOL bStatus = FALSE;
  290. if ( gLastCommand != CMD_SCAN )
  291. {
  292. if ( gLastCommand != CMD_STOP )
  293. ZivaHw_Abort( );
  294. gLastCommand = CMD_SCAN;
  295. bStatus = DVD_Scan( 0, 0 );
  296. }
  297. else
  298. bStatus = TRUE;
  299. return bStatus;
  300. }
  301. //
  302. // ZivaHw_SLowMotion
  303. //
  304. ///////////////////////////////////////////////////////////////////////////////
  305. BOOL _stdcall ZivaHw_SlowMotion( WORD wRatio )
  306. {
  307. BOOL bStatus = FALSE;
  308. if ( gLastCommand != CMD_SLOWMOTION )
  309. {
  310. gLastCommand = CMD_SLOWMOTION;
  311. bStatus = DVD_SlowMotion( wRatio );
  312. }
  313. else
  314. bStatus = TRUE;
  315. return bStatus;
  316. }
  317. //
  318. // ZivaHw_Pause
  319. //
  320. ///////////////////////////////////////////////////////////////////////////////
  321. BOOL _stdcall ZivaHw_Pause( )
  322. {
  323. if (gLastCommand == CMD_PLAY ||
  324. gLastCommand == CMD_SCAN ||
  325. gLastCommand == CMD_SLOWMOTION )
  326. {
  327. gLastCommand = CMD_PAUSE;
  328. return DVD_Pause( );
  329. }
  330. return TRUE;
  331. }
  332. //
  333. // ZivaHw_Reset
  334. //
  335. ///////////////////////////////////////////////////////////////////////////////
  336. BOOL ZivaHw_Reset( )
  337. {
  338. //#ifndef EZDVD
  339. #ifdef DEBUG
  340. DVD_IntDisable( CL6100_INT_MASK_VSYNC|CL6100_INT_MASK_UND|CL6100_INT_MASK_ERR
  341. |CL6100_INT_MASK_USR ); //sri
  342. #else
  343. DVD_IntDisable( CL6100_INT_MASK_VSYNC|CL6100_INT_MASK_USR ); //sri
  344. #endif
  345. //#endif
  346. DVD_Reset( );
  347. #if defined(DECODER_DVDPC) || defined(EZDVD)
  348. DataTransfer_Reset();
  349. #else
  350. BMA_Reset();
  351. FPGA_Clear( FPGA_SECTOR_START );
  352. #endif
  353. gLastCommand = CMD_STOP;
  354. return TRUE;
  355. }
  356. //
  357. // ZivaHw_Abort
  358. //
  359. ///////////////////////////////////////////////////////////////////////////////
  360. BOOL ZivaHw_Abort( )
  361. {
  362. BOOL bStatus = FALSE;
  363. //INT_STATUS_INFO Info;
  364. //DWORD dwTimeout = 100000;
  365. // Set interrupt mask for events that we are going to use
  366. //#ifndef EZDVD
  367. #ifdef DEBUG
  368. DVD_IntDisable( CL6100_INT_MASK_VSYNC|CL6100_INT_MASK_UND|CL6100_INT_MASK_ERR
  369. |CL6100_INT_MASK_USR ); //sri
  370. #else
  371. DVD_IntDisable( CL6100_INT_MASK_VSYNC|CL6100_INT_MASK_USR ); //sri
  372. #endif
  373. //#endif
  374. if ( gLastCommand != CMD_STOP )
  375. {
  376. gLastCommand = CMD_STOP;
  377. #if defined(DECODER_DVDPC) || defined(EZDVD)
  378. DataTransfer_Reset();
  379. #else
  380. BMA_Reset();
  381. FPGA_Clear( FPGA_SECTOR_START );
  382. #endif
  383. bStatus = DVD_Abort( );
  384. }
  385. else
  386. bStatus = TRUE;
  387. return bStatus;
  388. }
  389. //
  390. // ZivaHw_FlushBuffers
  391. //
  392. ///////////////////////////////////////////////////////////////////////////////
  393. BOOL ZivaHw_FlushBuffers( )
  394. {
  395. gLastCommand = CMD_NONE; // Allow any next command
  396. DVD_Abort( );
  397. #if defined(DECODER_DVDPC) || defined(EZDVD)
  398. DataTransfer_Reset();
  399. #else
  400. BMA_Reset();
  401. FPGA_Clear( FPGA_SECTOR_START );
  402. #endif
  403. return TRUE;
  404. }
  405. //
  406. // ZivaHw_GetState
  407. //
  408. ///////////////////////////////////////////////////////////////////////////////
  409. ZIVA_STATE ZivaHw_GetState( )
  410. {
  411. ZIVA_STATE zState;
  412. if ( gLastCommand == CMD_PLAY )
  413. zState = ZIVA_STATE_PLAY;
  414. else if ( gLastCommand == CMD_PAUSE )
  415. zState = ZIVA_STATE_PAUSE;
  416. else if ( gLastCommand == CMD_STOP )
  417. zState = ZIVA_STATE_STOP;
  418. else if ( gLastCommand == CMD_SCAN )
  419. zState = ZIVA_STATE_SCAN;
  420. else if ( gLastCommand == CMD_STEP )
  421. zState = ZIVA_STATE_STEP;
  422. else if ( gLastCommand == CMD_SLOWMOTION )
  423. zState = ZIVA_STATE_SLOWMOTION;
  424. return zState;
  425. }
  426. //
  427. // ZivaHW_GetNotificationDirect
  428. //
  429. /////////////////////////////////////////////////////////////////////
  430. BOOL ZivaHW_GetNotificationDirect( PINT_STATUS_INFO pInfo )
  431. {
  432. INTSOURCES IntSrc;
  433. //MonoOutStr("[Get notification direct ");
  434. pInfo -> dwStatus = DVD_Isr( &IntSrc );
  435. pInfo -> dwButton = IntSrc.DVDIntHLI;
  436. pInfo -> dwError = IntSrc.DVDIntERR;
  437. pInfo -> dwBuffer = IntSrc.DVDIntBUFF;
  438. pInfo -> dwUnderflow = IntSrc.DVDIntUND;
  439. pInfo -> dwAOR = IntSrc.DVDIntAOR;
  440. pInfo -> dwAEE = IntSrc.DVDIntAEE;
  441. //MonoOutStr("]");
  442. return TRUE;
  443. }
  444. void ZivaHW_ForceCodedAspectRatio(WORD wRatio)
  445. {
  446. DVD_ForceCodedAspectRatio(wRatio);
  447. }
  448. void ZivaHw_SetDisplayMode( WORD wDisplay, WORD wMode )
  449. {
  450. DVD_SetDisplayMode(wDisplay,wMode );
  451. }
  452. void ZivaHw_SetVideoMode(PHW_DEVICE_EXTENSION pHwDevExt)
  453. {
  454. #if defined (DECODER_DVDPC) || defined(EZDVD)
  455. // TV_SetEncoderType(1);
  456. SetTVSystem(pHwDevExt->VidSystem);
  457. DVD_NewPlayMode( ZIVA_STREAM_TYPE_MPEG_PROGRAM, pHwDevExt->VidSystem );
  458. #else if(ENCORE)
  459. BOOL bSystem = pHwDevExt->VidSystem == PAL ? FALSE:TRUE;
  460. SetMacroVisionLevel( bSystem, pHwDevExt->ulLevel );
  461. DVD_NewPlayMode( ZIVA_STREAM_TYPE_MPEG_PROGRAM, pHwDevExt->VidSystem );
  462. #endif
  463. }
  464. #if defined (LOAD_UCODE_FROM_FILE)
  465. #define ENTRY_UCODE_FILE L"Microcode"
  466. #define ENTRY_DEFAULT_UCODE_FILE L"Dvd1.Ux"
  467. BOOL
  468. ZivaHW_LoadUCodeFromFile( // Load the microcode based on the microcode Id specified.
  469. PHW_DEVICE_EXTENSION pHwDevExt) // is pHwDevExt
  470. {
  471. NTSTATUS status;
  472. HANDLE hKeyPdo;
  473. OBJECT_ATTRIBUTES ObjectAttributes;
  474. UNICODE_STRING uniFileName;
  475. HANDLE hFile;
  476. IO_STATUS_BLOCK iosb;
  477. FILE_STANDARD_INFORMATION FileInfo;
  478. PUCHAR pFileDataPtr, pSaveFileDataPtr;
  479. WCHAR pSection[] = L"FileNames";
  480. WCHAR pwchUXFileName[255];
  481. BOOL fResult = FALSE;
  482. /*
  483. WCHAR pwchEncUXFileName[255];// = L"\\SystemRoot\\system32\\drivers\\c3m2_enc.ux";
  484. WCHAR pwchDecUXFileName[255];// = L"\\SystemRoot\\system32\\drivers\\c3m2_dec.ux";
  485. short sLength;
  486. WCHAR pSection[] = L"FileNames";
  487. */
  488. MonoOutStr("Loading Ucode from File ");
  489. status = IoOpenDeviceRegistryKey( pHwDevExt->pPhysicalDeviceObj, // my real PDO
  490. PLUGPLAY_REGKEY_DRIVER, // pertinent to my device
  491. KEY_ALL_ACCESS, // all acess
  492. &hKeyPdo); // handle returned
  493. if ( !NT_SUCCESS( status ))
  494. {
  495. MonoOutStr("Failed to obtain Key handle ");
  496. return FALSE;
  497. }
  498. if (!REG_GetPrivateProfileString(
  499. pSection,
  500. ENTRY_UCODE_FILE,
  501. ENTRY_DEFAULT_UCODE_FILE,
  502. pwchUXFileName,
  503. sizeof(pwchUXFileName),
  504. hKeyPdo))
  505. {
  506. MonoOutStr("Failed to obtain Ucode file name form registry ");
  507. return FALSE;
  508. }
  509. pSaveFileDataPtr = pFileDataPtr = NULL;
  510. uniFileName.Length = wcslen(pwchUXFileName) * sizeof(WCHAR);
  511. uniFileName.MaximumLength = wcslen(pwchUXFileName) * sizeof(WCHAR);
  512. uniFileName.Buffer = pwchUXFileName;
  513. //
  514. // Read the Microcode file and load it.
  515. //
  516. // Open the file.
  517. InitializeObjectAttributes(
  518. &ObjectAttributes,
  519. &uniFileName,
  520. OBJ_CASE_INSENSITIVE,
  521. NULL,
  522. NULL);
  523. status = ZwCreateFile(
  524. &hFile,
  525. GENERIC_READ, // || SYNCHRONIZE,
  526. &ObjectAttributes,
  527. &iosb,
  528. NULL, // allocate size
  529. FILE_ATTRIBUTE_NORMAL,
  530. FILE_SHARE_READ,
  531. FILE_OPEN,
  532. FILE_SYNCHRONOUS_IO_NONALERT, //FILE_SEQUENTIAL_ONLY, use sync no alert
  533. NULL, // eabuffer
  534. 0); // ealength
  535. if ( !NT_SUCCESS( status ))
  536. {
  537. MonoOutStr("Can not create ucode file\n");
  538. hFile = NULL;
  539. return fResult;
  540. }
  541. // Get file lengh and allocate memory to read complete file.
  542. status = ZwQueryInformationFile(hFile, &iosb, &FileInfo, sizeof(FileInfo), FileStandardInformation);
  543. if ( !NT_SUCCESS( status ))
  544. {
  545. MonoOutStr(" Can not get ucode file length ");
  546. ZwClose( hFile );
  547. hFile = NULL;
  548. return fResult;
  549. }
  550. #if 0
  551. pFileDataPtr = ExAllocatePool(PagedPool , FileInfo.EndOfFile.LowPart);
  552. if (pFileDataPtr == NULL)
  553. {
  554. MonoOutStr(" Can not allocate pFileDataPtr ");
  555. ZwClose( hFile );
  556. hFile = NULL;
  557. return fResult;
  558. }
  559. #endif
  560. pFileDataPtr = UcodeBuff;
  561. pSaveFileDataPtr = pFileDataPtr;
  562. // Read all the data from the file into buffer allocated.
  563. status = ZwReadFile(
  564. hFile,
  565. NULL, // event
  566. NULL, // apcroutine
  567. NULL, // apc context
  568. &iosb,
  569. pFileDataPtr,
  570. FileInfo.EndOfFile.LowPart,
  571. NULL, //FILE_USE_FILE_POINTER_POSITION
  572. NULL); // key
  573. if ( !NT_SUCCESS( status ) || iosb.Information <= 0 )
  574. {
  575. MonoOutStr(" Can not read ucode file ");
  576. ZwClose( hFile );
  577. hFile = NULL;
  578. ExFreePool(pSaveFileDataPtr);
  579. pFileDataPtr = NULL;
  580. return fResult;
  581. }
  582. if (LoadUcode(pFileDataPtr))
  583. fResult = TRUE;
  584. // Close the file and release the allocated buffer.
  585. ZwClose( hFile );
  586. hFile = NULL;
  587. #if 0
  588. ExFreePool(pSaveFileDataPtr);
  589. pFileDataPtr = NULL;
  590. #endif
  591. return fResult;
  592. }
  593. #endif
  594. DWORD SwapDWORD(DWORD dwData)
  595. {
  596. dwData = (((dwData & 0x000000FF) << 24) | ((dwData & 0x0000FF00) << 8)
  597. |((dwData & 0x00FF0000) >> 8)|((dwData & 0xFF000000) >> 24));
  598. return dwData;
  599. }
  600. BOOL ZivaHw_GetUserData(PHW_DEVICE_EXTENSION pHwDevExt)
  601. {
  602. DWORD dwUserReadPtr;
  603. DWORD dwUserWritePtr;
  604. DWORD UserDataBufferStart;
  605. DWORD UserDataBufferEnd;
  606. int i =0;
  607. BOOL fCCData = FALSE;
  608. DWORD dwData=0;
  609. DWORD dwUserDataBufferSize=0;
  610. dwUserReadPtr = DVD_ReadDRAM( USER_DATA_READ );
  611. dwUserWritePtr = DVD_ReadDRAM( USER_DATA_WRITE );
  612. UserDataBufferStart = DVD_ReadDRAM( USER_DATA_BUFFER_START );
  613. UserDataBufferEnd = DVD_ReadDRAM( USER_DATA_BUFFER_END );
  614. // Check for DRAM Buffer Overflow
  615. if ( dwUserReadPtr == 0xFFFFFFFF )
  616. {
  617. // Set Read Ptr
  618. DVD_WriteDRAM( USER_DATA_READ, dwUserWritePtr );
  619. MonoOutStr(" UsrBufferOverFlow ");
  620. pHwDevExt->fReSync = TRUE;
  621. return fCCData;
  622. }
  623. else
  624. {
  625. if(pHwDevExt->fReSync)
  626. {
  627. dwData = DVD_ReadDRAM( dwUserReadPtr );
  628. if( (dwData & 0xFFFF0000 ) == 0xFEED0000)
  629. {
  630. MonoOutStr(" ReSync After Overflow ");
  631. pHwDevExt->fReSync = FALSE;
  632. }
  633. else
  634. return fCCData;
  635. }
  636. pHwDevExt->dwUserDataBuffer[i++] = 0xB2010000;
  637. while( dwUserReadPtr != dwUserWritePtr )
  638. {
  639. dwData = DVD_ReadDRAM( dwUserReadPtr );
  640. if(dwData == 0x434301F8)
  641. {
  642. MonoOutStr(" CCID ");
  643. fCCData = TRUE;
  644. }
  645. if( (dwData & 0xFFFF0000 ) == 0xFEED0000)
  646. {
  647. MonoOutStr(" Feed ");
  648. pHwDevExt->dwUserDataSize = dwData & 0x00000FFF;
  649. MonoOutStr(" SizeSpecifiedByFirst3Bytes ");
  650. MonoOutULong(pHwDevExt->dwUserDataSize);
  651. }
  652. else
  653. {
  654. pHwDevExt->dwUserDataBuffer[ i] = SwapDWORD(dwData);
  655. i++;
  656. }
  657. // Adjust Data Pointer
  658. dwUserReadPtr += 4L;
  659. if ( dwUserReadPtr >= UserDataBufferEnd)
  660. dwUserReadPtr = UserDataBufferStart;
  661. }
  662. }
  663. DVD_WriteDRAM( USER_DATA_READ, dwUserReadPtr );
  664. dwUserDataBufferSize = i*4 ;
  665. MonoOutStr(" DataReadFromUserBuffer ");
  666. MonoOutULong(dwUserDataBufferSize);
  667. return (fCCData);
  668. }